diff --git a/perl-xCAT/xCAT/KVMUtils.pm b/perl-xCAT/xCAT/KVMUtils.pm index e1befd7493..12835999c6 100644 --- a/perl-xCAT/xCAT/KVMUtils.pm +++ b/perl-xCAT/xCAT/KVMUtils.pm @@ -515,6 +515,36 @@ sub guest_os { #------------------------------------------------------- +=head3 guest_uuid + + Descriptions: + Converts between the UUID of a libvirt domain and the UUID that its guest reports. + vpd.uuid holds the UUID that the guest reports. + + QEMU stores the domain UUID as SMBIOS 2.6 specifies, so the guest reports it + unchanged. Machine type pc-i440fx-2.1 and its RHEL counterpart pc-i440fx-rhel7.1.0 + are the exception: they store the UUID bytes in text order behind an SMBIOS 2.8 entry + point, so the guest reports the first three fields swapped. Older machine types store + the same bytes in SMBIOS 2.4 tables, which the guest reads unswapped. The swap is its + own inverse, so one sub converts both ways. + Arguments: + $uuid - a domain UUID or a guest UUID, or undef + $machine - the machine type of the domain, or undef for the libvirt default + Returns: + the UUID on the other side + +=cut + +#------------------------------------------------------- +sub guest_uuid { + my ($uuid, $machine) = @_; + return $uuid unless defined($uuid) and defined($machine) and $machine =~ /\Apc-i440fx-(?:2\.1|rhel7\.1\.0)\z/; + $uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/; + return $uuid; +} + +#------------------------------------------------------- + =head3 clock_offset Descriptions: diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 73cefeaefe..b86f4afe19 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -510,12 +510,9 @@ sub build_diskstruct { } sub getNodeUUID { - my $node = shift; - my $uuid; + my ($node, $machine) = @_; if ($confdata->{vpd}->{$node}->[0] and $confdata->{vpd}->{$node}->[0]->{uuid}) { - $uuid = $confdata->{vpd}->{$node}->[0]->{uuid}; - $uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/; - return $uuid; + return xCAT::KVMUtils::guest_uuid($confdata->{vpd}->{$node}->[0]->{uuid}, $machine); } if ($confdata->{mac}->{$node}->[0]->{mac}) { #a uuidv1 is possible, generate that for absolute uniqueness guarantee my $mac = $confdata->{mac}->{$node}->[0]->{mac}; @@ -525,9 +522,7 @@ sub getNodeUUID { } else { $updatetable->{vpd}->{$node} = { uuid => xCAT::Utils::genUUID() }; } - $uuid = $updatetable->{vpd}->{$node}->{uuid}; - $uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/; - return $uuid; + return xCAT::KVMUtils::guest_uuid($updatetable->{vpd}->{$node}->{uuid}, $machine); } @@ -613,7 +608,6 @@ sub build_xmldesc { $xtree{type} = $profile->{domtype}; $xtree{name}->{content} = $node; - $xtree{uuid}->{content} = getNodeUUID($node); if ($args{memory}) { $xtree{memory}->{content} = getUnits($args{memory}, "M", 1024); if ($confdata->{vm}->{$node}->[0]->{memory}) { @@ -679,6 +673,7 @@ sub build_xmldesc { hyp_cpumodel => $hypcpumodel, bootorder => $confdata->{vm}->{$node}->[0]->{bootorder}, machine => $machine_type); + $xtree{uuid}->{content} = getNodeUUID($node, $xtree{os}->{type}->{machine}); #prepare the xml hash for memory binding if (defined $memnumanodes) { @@ -1558,8 +1553,9 @@ sub rinv { return; } my $domain = $parser->parse_string($currxml); - my $uuid = $domain->findnodes('/domain/uuid')->[0]->to_literal; - $uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/; + my ($ostype) = $domain->findnodes('/domain/os/type'); + my $uuid = xCAT::KVMUtils::guest_uuid($domain->findnodes('/domain/uuid')->[0]->to_literal, + $ostype ? $ostype->getAttribute('machine') : undef); xCAT::SvrUtils::sendmsg("UUID/GUID: $uuid", $callback, $node); my $cpus = $domain->findnodes('/domain/vcpu')->[0]->to_literal; xCAT::SvrUtils::sendmsg("CPUs: $cpus", $callback, $node); @@ -2870,7 +2866,8 @@ sub clone_vm_from_master { } my $newnodexml = $parser->parse_string($kvmmasteref->{xml}); $newnodexml->findnodes("/domain/name/text()")->[0]->setData($node); #set name correctly - my $uuid = getNodeUUID($node); + my ($clonetype) = $newnodexml->findnodes('/domain/os/type'); + my $uuid = getNodeUUID($node, $clonetype ? $clonetype->getAttribute('machine') : undef); $newnodexml->findnodes("/domain/uuid/text()")->[0]->setData($uuid); #put in correct uuid #set up mac addresses and such right... fixup_clone_network(mastername => $mastername, mastertableentry => $masteref, kvmmastertableentry => $kvmmasteref, xmlinprogress => $newnodexml); @@ -3264,8 +3261,8 @@ sub rscan { my ($uuid, $node, $vmcpus, $vmmemory, $vmnics, $vmstorage, $arch, $mac, $vmnicnicmodel); my @uuidobj = $domain->findnodes("/domain/uuid"); if (@uuidobj) { - $uuid = $uuidobj[0]->to_literal; - $uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/; + my ($ostype) = $domain->findnodes('/domain/os/type'); + $uuid = xCAT::KVMUtils::guest_uuid($uuidobj[0]->to_literal, $ostype ? $ostype->getAttribute('machine') : undef); } my $type = $domain->findnodes("/domain")->[0]->getAttribute("type"); if (length($type) > $maxlength[0]) {