2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-24 19:32:17 +00:00

fix(xcat-core): esx.pm writes vpd.uuid with two opposite conventions

vpd.uuid holds the UUID that the guest operating system reports, and makedhcp derives the
DHCPv6 DUID of a node from it. esx.pm uses two opposite conventions for the same column. The
clone callback stores config.uuid unchanged, while mkvm and rinv swap the first three fields.
One of the two is always wrong, so a VMware guest gets a dynamicrange address with no
bootfile-url and does not boot over IPv6, and rinv prints a UUID the guest does not report.

Neither convention is right on its own. VMware writes uuid.bios into the SMBIOS type 1
structure unencoded and only the version of the entry point changes. Measured on ESXi 7.0.3,
8.0.3 and 9.1.0: EFI firmware gives SMBIOS 2.7 at every hardware version, and BIOS firmware
gives 2.4 up to hardware version 11 and 2.7 from hardware version 12. A 2.7 guest reports the
first three fields swapped, and a 2.4 guest reports them unchanged.

xCAT::VMCommon::esx_guest_uuid takes the UUID, config.firmware and config.version and returns
the UUID on the other side. inv and clone_task_callback read both properties from the VM view.
build_cfgspec learns them from the firmware and virtualHW.version keys of vm.othersettings,
which xCAT::VMCommon::esx_vmx_settings now passes to vSphere as fields of the
VirtualMachineConfigSpec, because extraConfig does not apply them.

xCAT-test/unit/esx_vm_uuid.t pins every row of the measurement with literal UUID strings, and
the DUID that kea_duid_from_uuid then derives for a UEFI guest against the DUID that its
firmware sent. A mutation that drops the SMBIOS 2.4 branch fails the 6 assertions that name a
BIOS guest at hardware version 8 or 11 and leaves the other 56 passing. A mutation that stops
converting an EFI guest fails the 24 assertions that name one and leaves 38 passing.

No ESXi host exists in the lab, so the change is not validated end to end.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-26 17:40:41 -03:00
parent 8924cb43de
commit 40178d4f08
5 changed files with 237 additions and 15 deletions
@@ -204,6 +204,11 @@ vm Attributes:
PCI devices can be assigned to a virtual machine for exclusive usage, e.g., 'devpassthrough:pci_0001_01_00_0,pci_0000_03_00_0'. A PCI device can also be expressed as 'devpassthrough:0001:01:00.1'. The devices are put in a comma-delimited list. The PCI device names can be obtained by running \ **virsh nodedev-list**\ on the host.
VM machine type:
Specify a machine type for VM creation on the host, e.g., 'machine:pc'. Typical machine types are pc, q35, and pseries.
VMware firmware and hardware version:
Specify the firmware and the hardware version of a VMware guest, e.g.,
'firmware=efi;virtualHW.version=17'. mkvm passes both to vSphere as fields of the
VirtualMachineConfigSpec, not as extraConfig, because extraConfig does not apply them.
They also decide the byte order of config.uuid, so that the guest reports vpd.uuid.
+6 -1
View File
@@ -238,7 +238,12 @@ qq{ link,ro - The file is readonly, and will be placed in tmpfs on the booted no
PCI passthrough:
PCI devices can be assigned to a virtual machine for exclusive usage, e.g., 'devpassthrough:pci_0001_01_00_0,pci_0000_03_00_0'. A PCI device can also be expressed as 'devpassthrough:0001:01:00.1'. The devices are put in a comma-delimited list. The PCI device names can be obtained by running B<virsh nodedev-list> on the host.
VM machine type:
Specify a machine type for VM creation on the host, e.g., 'machine:pc'. Typical machine types are pc, q35, and pseries.",
Specify a machine type for VM creation on the host, e.g., 'machine:pc'. Typical machine types are pc, q35, and pseries.
VMware firmware and hardware version:
Specify the firmware and the hardware version of a VMware guest, e.g.,
'firmware=efi;virtualHW.version=17'. mkvm passes both to vSphere as fields of the
VirtualMachineConfigSpec, not as extraConfig, because extraConfig does not apply them.
They also decide the byte order of config.uuid, so that the guest reports vpd.uuid.",
'guestostype' => "This allows administrator to specify an identifier for OS to pass through to virtualization stack. Normally this should be ignored as xCAT will translate from nodetype.os rather than requiring this field be used\n",
'beacon' => "This flag is used by xCAT to track the state of the identify LED with respect to the VM.",
'datacenter' => "Optionally specify a datacenter for the VM to exist in (only applicable to VMWare)",
+81
View File
@@ -281,4 +281,85 @@ sub genMac { #Generates a mac address for a node, does NOT assure uniqueness, ca
return $mac;
}
#-------------------------------------------------------
=head3 esx_guest_uuid
Descriptions:
Converts between config.uuid of a VMware VM and the UUID that its guest reports.
vpd.uuid holds the UUID that the guest reports.
VMware writes uuid.bios into the SMBIOS type 1 structure unencoded. Only the version
of the SMBIOS entry point changes, and the guest decodes the bytes according to it. A
guest behind a 2.7 entry point reads the first three fields little-endian and reports
them swapped. A guest behind a 2.4 entry point reports the same bytes unswapped.
Measured on ESXi 7.0.3, 8.0.3 and 9.1.0: EFI firmware gives SMBIOS 2.7 at every
hardware version, and BIOS firmware gives 2.4 up to hardware version 11 and 2.7 from
hardware version 12. The host default firmware and hardware version are both newer
than that, so an unknown value reads 2.7. The swap is its own inverse, so one sub
converts both ways.
VMware documents acpi.smbiosVersion2.7 = FALSE, which puts a 2.7 guest back on 2.4.
That override is not measured and this sub does not read it.
Arguments:
$uuid - config.uuid, or the UUID that the guest reports, or undef
$firmware - config.firmware, bios or efi, or undef for the host default
$hwversion - config.version, such as vmx-13, or undef for the host default
Returns:
the UUID on the other side
=cut
#-------------------------------------------------------
sub esx_guest_uuid {
my ($uuid, $firmware, $hwversion) = @_;
return $uuid unless defined($uuid);
my ($number) = (defined($hwversion) ? $hwversion : '') =~ /(\d+)/;
return $uuid if defined($firmware) and lc($firmware) eq 'bios' and defined($number) and $number < 12;
$uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/;
return $uuid;
}
#-------------------------------------------------------
=head3 esx_vmx_settings
Descriptions:
Splits vm.othersettings of a VMware guest into the fields of a
VirtualMachineConfigSpec and the extraConfig options.
firmware and virtualHW.version are vmx keys that the VirtualMachineConfigSpec carries
as the firmware and version fields. extraConfig does not apply them, so mkvm passes
them as fields, and esx_guest_uuid needs both to convert the UUID of a guest that
mkvm creates.
Arguments:
$othersettings - vm.othersettings, a list of key=value separated by ;, or undef
Returns:
a hash reference with the firmware and version keys that are present, and an array
reference of [key, value] pairs for extraConfig
=cut
#-------------------------------------------------------
sub esx_vmx_settings {
my ($othersettings) = @_;
my %spec;
my @extraconfig;
foreach my $setting (split /;/, (defined($othersettings) ? $othersettings : '')) {
my ($key, $value) = split /=/, $setting, 2;
next unless defined($key) and length($key);
my $name = lc($key);
if ($name eq 'firmware' and defined($value) and length($value)) {
$spec{firmware} = lc($value);
} elsif ($name eq 'virtualhw.version' and defined($value) and $value =~ /(\d+)/) {
$spec{version} = "vmx-$1";
} else {
push @extraconfig, [ $key, $value ];
}
}
return (\%spec, \@extraconfig);
}
1;
+19 -14
View File
@@ -757,8 +757,8 @@ sub inv {
my $vmview = $args{vmview};
my $moref = $vmview->{mo_ref}->value;
xCAT::SvrUtils::sendmsg("Managed Object Reference: $moref", $output_handler, $node);
my $uuid = $vmview->config->uuid;
$uuid =~ s/(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/;
# vpd.uuid holds the UUID that the guest reports, which is what rinv prints.
my $uuid = xCAT::VMCommon::esx_guest_uuid($vmview->config->uuid, $vmview->config->{firmware}, $vmview->config->{version});
xCAT::SvrUtils::sendmsg("UUID/GUID: $uuid", $output_handler, $node);
my $cpuCount = $vmview->config->hardware->numCPU;
xCAT::SvrUtils::sendmsg("CPUs: $cpuCount", $output_handler, $node);
@@ -2692,7 +2692,9 @@ sub clone_task_callback {
my $nodeviews = $conn->find_entity_views(view_type => 'VirtualMachine', filter => { 'config.name' => $regex });
unless (scalar @$nodeviews == 1) { die "this should be impossible"; }
my $vpdtab = xCAT::Table->new('vpd', -create => 1);
$vpdtab->setAttribs({ node => $node }, { uuid => $nodeviews->[0]->config->uuid });
my $clonedconfig = $nodeviews->[0]->config;
$vpdtab->setAttribs({ node => $node },
{ uuid => xCAT::VMCommon::esx_guest_uuid($clonedconfig->uuid, $clonedconfig->{firmware}, $clonedconfig->{version}) });
my $ndev;
my @devstochange;
foreach $ndev (@{ $nodeviews->[0]->config->hardware->device }) {
@@ -3207,18 +3209,18 @@ sub build_cfgspec {
my $vpdtab = xCAT::Table->new('vpd');
$vpdtab->setNodeAttribs($node, { uuid => $uuid });
}
$uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)/$4$3$2$1-$6$5-$8$7/;
my ($vmxspec, $extraconfig) = xCAT::VMCommon::esx_vmx_settings($tablecfg{vm}->{$node}->[0]->{othersettings});
# config.uuid must hold the UUID that the guest reports as vpd.uuid, and the firmware and
# the hardware version of the new VM decide which byte order that is.
$uuid = xCAT::VMCommon::esx_guest_uuid($uuid, $vmxspec->{firmware}, $vmxspec->{version});
my @optionvals;
if ($tablecfg{vm}->{$node}->[0]->{othersettings}) {
my $key;
my $value;
foreach (split /;/, $tablecfg{vm}->{$node}->[0]->{othersettings}) {
($key, $value) = split /=/;
if ($value) {
push @optionvals, OptionValue->new(key => $key, value => $value);
} else {
push @optionvals, OptionValue->new(key => $key);
}
foreach my $option (@$extraconfig) {
my ($key, $value) = @$option;
if ($value) {
push @optionvals, OptionValue->new(key => $key, value => $value);
} else {
push @optionvals, OptionValue->new(key => $key);
}
}
my %specargs = (
@@ -3230,6 +3232,9 @@ sub build_cfgspec {
deviceChange => \@devices,
uuid => $uuid,
);
foreach my $field (keys %$vmxspec) {
$specargs{$field} = $vmxspec->{$field};
}
if (@optionvals) {
$specargs{extraConfig} = \@optionvals;
}
+126
View File
@@ -0,0 +1,126 @@
#!/usr/bin/env perl
# vpd.uuid holds the system UUID that the guest reports, and makedhcp derives the DHCPv6 DUID of a
# node from it. VMware writes uuid.bios into the SMBIOS type 1 structure unencoded, so the UUID that
# an ESX guest reports depends on the version of the SMBIOS entry point its firmware builds: a guest
# behind a 2.7 entry point reports the first three fields swapped, and a guest behind a 2.4 entry
# point reports them unchanged. The esx plugin must therefore convert config.uuid per VM.
#
# The expected values come from the measurement in VersatusHPC/xcat-internal issue 349, on ESXi
# 9.1.0 (build 25370933), 8.0.3 (build 25429389) and 7.0.3 (build 24784741). Every guest had
# uuid.bios = "12 34 56 78 12 34 4b cd-98 76 12 34 56 78 90 ab", a guest ISO printed product_uuid
# and the SMBIOS entry point, and a UEFI guest booted over PXEv6 while the host captured its DUID.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../xCAT-server/lib";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../perl-xCAT";
use File::Temp qw(tempdir);
use Test::More;
use XCAT::Test::File qw(repo_path);
BEGIN {
$ENV{XCATROOT} = repo_path('xCAT-server');
$ENV{XCATCFG} = 'SQLite:' . tempdir( CLEANUP => 1 );
}
use xCAT::VMCommon;
require( repo_path('xCAT-server/lib/xcat/plugins/dhcp.pm') );
# uuid.bios of every measured VM, which is config.uuid.
my $config = '12345678-1234-4bcd-9876-1234567890ab';
# What a guest behind an SMBIOS 2.7 entry point reports, from product_uuid in the guest.
my $reported_27 = '78563412-3412-cd4b-9876-1234567890ab';
# The DUID that the UEFI guest sent over PXEv6: 00:04 and the raw SMBIOS bytes.
my $pxev6_duid = '00:04:12:34:56:78:12:34:4b:cd:98:76:12:34:56:78:90:ab';
# EFI firmware builds an SMBIOS 2.7 entry point at every measured hardware version. 8 to 22 on
# ESXi 9.1, and 11, 13, 17, 19, 20 and 21 on 8.0 and 7.0.
my @efi_27 = ( 8, 9, 10, 11, 12, 13, 17, 19, 20, 21, 22 );
# BIOS firmware builds an SMBIOS 2.7 entry point from hardware version 12. Measured at 12 and 13 on
# ESXi 8.0 and 7.0, and at 13, 17 and 22 on 9.1.
my @bios_27 = ( 12, 13, 17, 22 );
# BIOS firmware builds an SMBIOS 2.4 entry point up to hardware version 11. Measured at 8 and 11 on
# ESXi 9.1 and at 11 on 8.0 and 7.0.
my @bios_24 = ( 8, 11 );
foreach my $version (@efi_27) {
is( xCAT::VMCommon::esx_guest_uuid( $config, 'efi', "vmx-$version" ), $reported_27,
"an efi vmx-$version guest reports config.uuid swapped" );
is( xCAT::VMCommon::esx_guest_uuid( $reported_27, 'efi', "vmx-$version" ), $config,
"and mkvm gives an efi vmx-$version guest config.uuid swapped back from vpd.uuid" );
is( xCAT_plugin::dhcp::kea_duid_from_uuid( $reported_27, 'firmware' ), $pxev6_duid,
"the default reservation of an efi vmx-$version guest is the DUID its firmware sends" );
}
foreach my $version (@bios_27) {
is( xCAT::VMCommon::esx_guest_uuid( $config, 'bios', "vmx-$version" ), $reported_27,
"a bios vmx-$version guest reports config.uuid swapped" );
is( xCAT::VMCommon::esx_guest_uuid( $reported_27, 'bios', "vmx-$version" ), $config,
"and mkvm gives a bios vmx-$version guest config.uuid swapped back from vpd.uuid" );
}
# BIOS network boot is IPv4 only, so these guests reserve no DHCPv6 address. The UUID they report
# is still what vpd.uuid and rinv must carry.
foreach my $version (@bios_24) {
is( xCAT::VMCommon::esx_guest_uuid( $config, 'bios', "vmx-$version" ), $config,
"a bios vmx-$version guest reports config.uuid unchanged" );
is( xCAT::VMCommon::esx_guest_uuid( $config, 'bios', $version ), $config,
"and a bare hardware version $version reads the same as vmx-$version" );
}
# The host default firmware and hardware version are both newer than hardware version 11, so a VM
# that names neither reads the SMBIOS 2.7 tables.
is( xCAT::VMCommon::esx_guest_uuid( $config, undef, undef ), $reported_27,
'a guest of unknown firmware and hardware version reports config.uuid swapped' );
is( xCAT::VMCommon::esx_guest_uuid( $config, 'bios', undef ), $reported_27,
'a bios guest of unknown hardware version reports config.uuid swapped' );
is( xCAT::VMCommon::esx_guest_uuid( $config, 'efi', undef ), $reported_27,
'an efi guest of unknown hardware version reports config.uuid swapped' );
is( xCAT::VMCommon::esx_guest_uuid( $config, 'BIOS', 'vmx-11' ), $config,
'the firmware name is matched without regard to case' );
is( xCAT::VMCommon::esx_guest_uuid( undef, 'efi', 'vmx-17' ), undef, 'a guest with no UUID converts to no UUID' );
# mkvm learns the firmware and the hardware version from vm.othersettings, because a
# VirtualMachineConfigSpec carries both as fields and extraConfig does not apply them.
my ( $spec, $extra ) = xCAT::VMCommon::esx_vmx_settings('firmware=efi');
is_deeply( $spec, { firmware => 'efi' }, 'othersettings firmware=efi selects efi firmware' );
is_deeply( $extra, [], 'and leaves no extraConfig option' );
( $spec, $extra ) = xCAT::VMCommon::esx_vmx_settings('virtualHW.version=11');
is_deeply( $spec, { version => 'vmx-11' }, 'othersettings virtualHW.version=11 selects hardware version 11' );
( $spec, $extra ) = xCAT::VMCommon::esx_vmx_settings('virtualHW.version=vmx-13');
is_deeply( $spec, { version => 'vmx-13' }, 'othersettings virtualHW.version=vmx-13 selects hardware version 13' );
( $spec, $extra ) = xCAT::VMCommon::esx_vmx_settings('firmware=BIOS;virtualHW.version=11;isolation.tools.copy.disable=TRUE;sched.mem.pin');
is_deeply( $spec, { firmware => 'bios', version => 'vmx-11' }, 'othersettings names both fields in any case' );
is_deeply( $extra, [ [ 'isolation.tools.copy.disable', 'TRUE' ], [ 'sched.mem.pin', undef ] ],
'and every other setting stays an extraConfig option' );
( $spec, $extra ) = xCAT::VMCommon::esx_vmx_settings(undef);
is_deeply( $spec, {}, 'an empty vm.othersettings names no field' );
is_deeply( $extra, [], 'and no extraConfig option' );
# The chain that mkvm follows: vpd.uuid and vm.othersettings give config.uuid of the new VM.
foreach my $case (
[ 'firmware=bios;virtualHW.version=11', $config, 'a bios vmx-11 guest' ],
[ 'firmware=bios;virtualHW.version=13', $reported_27, 'a bios vmx-13 guest' ],
[ 'firmware=efi;virtualHW.version=11', $reported_27, 'an efi vmx-11 guest' ],
[ undef, $reported_27, 'a guest that names neither' ],
)
{
my ( $othersettings, $expected, $label ) = @$case;
my ($fields) = xCAT::VMCommon::esx_vmx_settings($othersettings);
is( xCAT::VMCommon::esx_guest_uuid( $config, $fields->{firmware}, $fields->{version} ), $expected,
"mkvm gives $label a config.uuid that its guest reports as vpd.uuid" );
}
done_testing();