From 1e830adaa9a5a9bf3adfe23cfdae4b2bfca204ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sat, 24 Oct 2026 04:00:49 -0300 Subject: [PATCH] fix(kvm): resolve the default machine type before converting a UUID The UUID conversion of mkvm, clonevm, rinv and rscan used the machine type that the domain XML names. A domain that names none, or names an alias such as pc, gets the default machine type of the hypervisor: pc-i440fx-2.1 on QEMU 2.1 and pc-i440fx-rhel7.1.0 on the qemu-kvm of RHEL 7.1. Its guest then reported a swapped UUID that the plugin did not expect. The plugin now asks libvirt for the machine type through the domain capabilities of the hypervisor, as it already does for the video model, and converts the UUID for that machine type. The domain XML keeps the machine type it names. When libvirt cannot answer, the plugin uses the machine type of the XML, as before. (cherry picked from commit f3b47fcca98ca75c123615433df38d3642d2c5d4) --- xCAT-server/lib/xcat/plugins/kvm.pm | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index f01ff91f7d..2454849260 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -526,6 +526,18 @@ sub getNodeUUID { } +# The machine type that libvirt gives a domain whose XML names none, or names an alias such as pc. +sub domain_machine_type { + my ($machine, $arch, $domtype) = @_; + return $machine unless $hypconn and $parser; + my $resolved = eval { + my $capsxml = $hypconn->get_domain_capabilities(undef, $arch, $machine, $domtype); + my ($element) = $parser->parse_string($capsxml)->findnodes('/domainCapabilities/machine'); + $element ? $element->textContent : undef; + }; + return (defined($resolved) and length($resolved)) ? $resolved : $machine; +} + sub build_nicstruct { my $rethash; my $node = shift; @@ -673,7 +685,8 @@ sub build_xmldesc { hyp_cpumodel => $hypcpumodel, bootorder => $confdata->{vm}->{$node}->[0]->{bootorder}, machine => $machine_type); - $xtree{uuid}->{content} = getNodeUUID($node, $xtree{os}->{type}->{machine}); + $xtree{uuid}->{content} = getNodeUUID($node, + domain_machine_type($xtree{os}->{type}->{machine}, $profile->{arch}, $profile->{domtype})); #prepare the xml hash for memory binding if (defined $memnumanodes) { @@ -1555,7 +1568,8 @@ sub rinv { my $domain = $parser->parse_string($currxml); 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); + domain_machine_type($ostype ? $ostype->getAttribute('machine') : undef, + $ostype ? $ostype->getAttribute('arch') : undef, $domain->findnodes('/domain')->[0]->getAttribute('type'))); xCAT::SvrUtils::sendmsg("UUID/GUID: $uuid", $callback, $node); my $cpus = $domain->findnodes('/domain/vcpu')->[0]->to_literal; xCAT::SvrUtils::sendmsg("CPUs: $cpus", $callback, $node); @@ -2867,7 +2881,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 ($clonetype) = $newnodexml->findnodes('/domain/os/type'); - my $uuid = getNodeUUID($node, $clonetype ? $clonetype->getAttribute('machine') : undef); + my $uuid = getNodeUUID($node, domain_machine_type($clonetype ? $clonetype->getAttribute('machine') : undef, + $clonetype ? $clonetype->getAttribute('arch') : undef, $newnodexml->findnodes('/domain')->[0]->getAttribute('type'))); $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); @@ -3262,7 +3277,9 @@ sub rscan { my @uuidobj = $domain->findnodes("/domain/uuid"); if (@uuidobj) { my ($ostype) = $domain->findnodes('/domain/os/type'); - $uuid = xCAT::KVMUtils::guest_uuid($uuidobj[0]->to_literal, $ostype ? $ostype->getAttribute('machine') : undef); + $uuid = xCAT::KVMUtils::guest_uuid($uuidobj[0]->to_literal, + domain_machine_type($ostype ? $ostype->getAttribute('machine') : undef, + $ostype ? $ostype->getAttribute('arch') : undef, $domain->findnodes('/domain')->[0]->getAttribute('type'))); } my $type = $domain->findnodes("/domain")->[0]->getAttribute("type"); if (length($type) > $maxlength[0]) {