mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-19 17:02:15 +00:00
fix(kvm): give a KVM guest the UUID that vpd.uuid holds
mkvm and clonevm wrote the libvirt domain UUID with the first three fields of vpd.uuid swapped, rscan swapped them back when it stored a domain UUID in vpd.uuid, and rinv printed the swapped value. QEMU stores the domain UUID as SMBIOS 2.6 specifies, so the guest reported the swapped UUID, not vpd.uuid, and its UEFI firmware sent a DUID that the reservation makedhcp derives from vpd.uuid did not match. The plugin now converts through xCAT::KVMUtils::guest_uuid, which keeps the UUID unchanged for every machine type except pc-i440fx-2.1 and its RHEL counterpart pc-i440fx-rhel7.1.0. Those machine types, which QEMU before 9.1 and the qemu-kvm of EL8 still offer, store the UUID bytes unencoded behind an SMBIOS 2.8 entry point, so their guest reports the first three fields swapped and the swap stays. mkvm and clonevm take the machine type of the domain they build, and rscan and rinv the machine type of the domain they read. A guest that mkvm defined before keeps its UUID, because mkvm reuses the domain XML in kvm_nodedata. Its vpd.uuid keeps the swapped order until it is corrected. (cherry picked from commit 4d8007091c9a8ba2e246749a7278c0f5e04da374)
This commit is contained in:
committed by
Daniel Hilst
parent
bff1e7ea93
commit
76f2008779
@@ -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:
|
||||
|
||||
@@ -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]) {
|
||||
|
||||
Reference in New Issue
Block a user