From f08b71f3ab5f9cd53da82c69552c04f94afb6d52 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 23 Feb 2022 16:14:34 +0000 Subject: [PATCH] libvirt: Remove unnecessary TODO The 'guest.os_mach_type' property is set to the value returned by 'libvirt.utils.get_machine_type'. This will attempt to pull a machine type from image metadata and fallback to a sensible default. As such, we never need to worry about 'guest.os_mach_type' being unset on x86 hosts. Change-Id: Ibc6d3dcaaa704599b7963bf97bdd901788f5af45 Signed-off-by: Stephen Finucane --- nova/virt/libvirt/driver.py | 40 ++++++++++++++----------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index f4a07afcea5b..4a15b988a02d 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -6811,38 +6811,28 @@ class LibvirtDriver(driver.ComputeDriver): """ caps = self._host.get_capabilities() - # TODO(kchamart) In the third 'if' conditional below, for 'x86' - # arch, we're assuming: when 'os_mach_type' is 'None', you'll - # have "pc" machine type. That assumption, although it is - # correct for the "forseeable future", it will be invalid when - # libvirt / QEMU changes the default machine types. - # - # From libvirt 4.7.0 onwards (September 2018), it will ensure - # that *if* 'pc' is available, it will be used as the default -- - # to not break existing applications. (Refer: - # https://libvirt.org/git/?p=libvirt.git;a=commit;h=26cfb1a3 - # --"qemu: ensure default machine types don't change if QEMU - # changes"). - # - # But even if libvirt (>=v4.7.0) handled the default case, - # relying on such assumptions is not robust. Instead we should - # get the default machine type for a given architecture reliably - # -- by Nova setting it explicitly (we already do it for Arm / - # AArch64 & s390x). A part of this bug is being tracked here: - # https://bugs.launchpad.net/nova/+bug/1780138). - # Add PCIe root port controllers for PCI Express machines # but only if their amount is configured if not CONF.libvirt.num_pcie_ports: return False - if (caps.host.cpu.arch == fields.Architecture.AARCH64 and - guest.os_mach_type.startswith('virt')): + + # Only certain architectures and machine types can handle PCIe ports; + # the latter will be handled by libvirt.utils.get_machine_type + + if ( + caps.host.cpu.arch == fields.Architecture.AARCH64 and + guest.os_mach_type.startswith('virt') + ): return True - if (caps.host.cpu.arch == fields.Architecture.X86_64 and - guest.os_mach_type is not None and - 'q35' in guest.os_mach_type): + + if ( + caps.host.cpu.arch == fields.Architecture.X86_64 and + guest.os_mach_type is not None and + 'q35' in guest.os_mach_type + ): return True + return False def _get_guest_config(self, instance, network_info, image_meta,