From 4807663ce6648fc3b64e416d1763d55529711b1f Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 30 Jan 2013 16:02:09 +0000 Subject: [PATCH] Have KVM support LVM volumes git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@15018 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/kvm.pm | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 34044ebc0..84e4b1faf 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -117,11 +117,29 @@ sub build_pool_xml { my $name=$url; $name=~ s!nfs://!nfs_!; $name=~ s!dir://!dir_!; + $name=~ s!lvm://!lvm_!; $name =~ s/\//_/g; #though libvirt considers / kosher, sometimes it wants to create a local xml file using name for filename... if ($url =~ /^dir:/) { #directory style.. my $path=$url; $path =~ s/dir:\/\///g; return "$name$path"; + } elsif ($url =~ /^lvm:\/\//) { #lvm specified + my $path = $url; + $path =~ s/^lvm:\/\///; + $path =~ s/:(.*)\z//; + my $volumes = $1; + my $mount = "/dev/$path"; + my $xml = ''.$path.''.$mount.''; + if ($volumes) { + $xml .= ""; + my @vols = split /,/,$volumes; + foreach (@vols) { + $xml .= ''; + } + $xml .= ""; + } + $xml .= ""; + return $xml; } my $mounthost = shift; unless ($mounthost) { $mounthost = $hyp; } @@ -183,6 +201,12 @@ sub get_storage_pool_by_url { if ($checkpath eq $path) { last; } + } elsif ($url =~ /^lvm:\/\/([^:]*)/) { #lvm volume group.... + my $vgname = $1; + my $checkname = $pool->findnodes("/pool/name/text()")->[0]->data; + if ($checkname eq $vgname) { + last; + } } elsif ($pool->findnodes('/pool/name/text()')->[0]->data eq $url) { #$pool->{name} eq $url) { last; } @@ -476,7 +500,7 @@ sub build_diskstruct { if (substr($disk_parts[0], 0, 4) eq 'phy:') { $diskhash->{type}='block'; $diskhash->{source}->{dev} = substr($disk_parts[0], 4); - } elsif ($disk_parts[0] =~ m/^nfs:\/\/(.*)$/ or $disk_parts[0] =~ m/^dir:\/\/(.*)$/) { + } elsif ($disk_parts[0] =~ m/^nfs:\/\/(.*)$/ or $disk_parts[0] =~ m/^dir:\/\/(.*)$/ or $disk_parts[0] =~ m/^lvm:\/\/(.*)$/) { my %disks = %{get_multiple_paths_by_url(url=>$disk_parts[0],node=>$node)}; unless (keys %disks) { die "Unable to find any persistent disks at ".$disk_parts[0]; @@ -1080,7 +1104,7 @@ sub makedom { my $dom; if (not $xml and $confdata->{kvmnodedata}->{$node} and $confdata->{kvmnodedata}->{$node}->[0] and $confdata->{kvmnodedata}->{$node}->[0]->{xml}) { #we do this to trigger storage prereq fixup - if (defined $confdata->{vm}->{$node}->[0]->{storage} and ($confdata->{vm}->{$node}->[0]->{storage} =~ /^nfs:/ or $confdata->{vm}->{$node}->[0]->{storage} =~ /^dir:/)) { + if (defined $confdata->{vm}->{$node}->[0]->{storage} and ($confdata->{vm}->{$node}->[0]->{storage} =~ /^nfs:/ or $confdata->{vm}->{$node}->[0]->{storage} =~ /^dir:/ or $confdata->{vm}->{$node}->[0]->{storage} =~ /^lvm:/)) { if ($confdata->{vm}->{$node}->[0]->{master}) { my $vmmastertab=xCAT::Table->new('vmmaster',-create=>0); my $masterent; @@ -1171,7 +1195,7 @@ sub createstorage { $prefix='vd'; } my @suffixes=('a','b','d'..'zzz'); - if ($filename =~ /^nfs:/ or $filename =~ /^dir:/) { #libvirt storage pool to be used for this + if ($filename =~ /^nfs:/ or $filename =~ /^dir:/ or $filename =~ /^lvm:/) { #libvirt storage pool to be used for this my @sizes = split /,/,$size; foreach (@sizes) { get_filepath_by_url(url=>$filename,dev=>$prefix.shift(@suffixes),create=>$_, force=>$force); @@ -1520,7 +1544,7 @@ sub chvm { foreach $store (split /\|/, $confdata->{vm}->{$node}->[0]->{storage}) { $store =~ s/,.*//; $store =~ s/=.*//; - if (($store =~ /^nfs:\/\//) || ($store =~ /^dir:\/\//)) { + if (($store =~ /^nfs:\/\//) || ($store =~ /^dir:\/\//) || ($store =~ /^lvm:/)) { my %disks = %{get_multiple_paths_by_url(url=>$store,node=>$node)}; foreach (keys %disks) { $useddisks{$disks{$_}->{device}}=1;