Remove logic for unsupported old libvirt/qemu

After recent bump by f7d99623ed , nova
requires QEMU >= 6.2.0 and libvirt > 8.0.0 .

Drop all logic added to support QEMU or libvirt older than these lower
boundaries.

Change-Id: Ie27e781f4b2a5696cde4988d9332d2d7e86eeda4
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-06-11 14:55:24 +09:00
parent 04a65154a9
commit bda78b5cf2
5 changed files with 26 additions and 185 deletions
-13
View File
@@ -24,7 +24,6 @@ import stat
from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_utils import units
from oslo_utils import uuidutils
import nova.privsep
@@ -191,18 +190,6 @@ def readpty(path):
return ''
@nova.privsep.sys_admin_pctxt.entrypoint
def create_mdev(physical_device, mdev_type, uuid=None):
"""Instantiate a mediated device."""
if uuid is None:
uuid = uuidutils.generate_uuid()
fpath = '/sys/class/mdev_bus/{0}/mdev_supported_types/{1}/create'
fpath = fpath.format(physical_device, mdev_type)
with open(fpath, 'w') as f:
f.write(uuid)
return uuid
@nova.privsep.sys_admin_pctxt.entrypoint
def systemd_run_qb_mount(qb_vol, mnt_base, cfg_file=None):
"""Mount QB volume in separate CGROUP"""
+4 -29
View File
@@ -19,7 +19,6 @@ import os_resource_classes as orc
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova.compute import instance_actions
import nova.conf
@@ -56,16 +55,10 @@ class VGPUTestBase(base.ServersTestBase):
'used': 44,
'free': 84,
}
# Persistent mdevs in libvirt >= 7.3.0
if self.FAKE_LIBVIRT_VERSION < versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_PERSISTENT_MDEV):
create_mdev_str = 'nova.privsep.libvirt.create_mdev'
else:
create_mdev_str = (
'nova.virt.libvirt.driver.LibvirtDriver._create_mdev')
self._create_mdev = self._create_mdev_7_3
self.useFixture(
fixtures.MockPatch(create_mdev_str, side_effect=self._create_mdev))
fixtures.MockPatch(
'nova.virt.libvirt.driver.LibvirtDriver._create_mdev',
side_effect=self._create_mdev))
# for the sake of resizing, we need to patch the two methods below
self.useFixture(fixtures.MockPatch(
@@ -104,25 +97,7 @@ class VGPUTestBase(base.ServersTestBase):
def libvirt2pci_address(self, dev_name):
return "{}:{}:{}.{}".format(*dev_name[4:].split('_'))
def _create_mdev(self, physical_device, mdev_type, uuid=None):
# We need to fake the newly created sysfs object by adding a new
# FakeMdevDevice in the existing persisted Connection object so
# when asking to get the existing mdevs, we would see it.
if not uuid:
uuid = uuidutils.generate_uuid()
mdev_name = libvirt_utils.mdev_uuid2name(uuid)
libvirt_parent = self.pci2libvirt_address(physical_device)
# Here, we get the right compute thanks by the self.current_host that
# was modified just before
connection = self.computes[
self._current_host].driver._host.get_connection()
connection.mdev_info.devices.update(
{mdev_name: fakelibvirt.FakeMdevDevice(dev_name=mdev_name,
type_id=mdev_type,
parent=libvirt_parent)})
return uuid
def _create_mdev_7_3(self, dev_name, mdev_type, uuid=None):
def _create_mdev(self, dev_name, mdev_type, uuid=None):
# We need to fake the newly created sysfs object by adding a new
# FakeMdevDevice in the existing persisted Connection object so
# when asking to get the existing mdevs, we would see it.
-12
View File
@@ -148,18 +148,6 @@ class LibvirtTestCase(test.NoDBTestCase):
mock_fcntl.F_SETFL, 32769 | os.O_NONBLOCK)])
self.assertIn(mock.call('/fake/path', 'r'), mock_open.mock_calls)
def test_create_nmdev(self):
mock_open = mock.mock_open()
with mock.patch('builtins.open', new=mock_open) as mock_open:
nova.privsep.libvirt.create_mdev('phys', 'mdevtype',
uuid='fakeuuid')
handle = mock_open()
self.assertTrue(mock.call('/sys/class/mdev_bus/phys/'
'mdev_supported_types/mdevtype/create',
'w') in mock_open.mock_calls)
handle.write.assert_called_with('fakeuuid')
@mock.patch('oslo_concurrency.processutils.execute')
def test_umount(self, mock_execute):
nova.privsep.libvirt.umount('/fake/path')
+5 -39
View File
@@ -22702,13 +22702,10 @@ class LibvirtConnTestCase(test.NoDBTestCase,
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_MAXPHYSADDR))
@mock.patch.object(fakelibvirt.Connection, 'getVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_MAXPHYSADDR))
@mock.patch.object(fakelibvirt.Connection, 'getType',
return_value=host.HV_DRIVER_QEMU)
def test_update_host_specific_capabilities_with_maxphysaddr(
self, mock_get_lib_version, mock_get_version, mock_type):
self, mock_get_lib_version, mock_type):
driver = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI())
driver._update_host_specific_capabilities()
self.assertTrue(
@@ -22738,14 +22735,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_MAXPHYSADDR))
@mock.patch.object(fakelibvirt.Connection, 'getVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_MAXPHYSADDR) - 1)
libvirt_driver.MIN_LIBVIRT_MAXPHYSADDR) - 1)
@mock.patch.object(fakelibvirt.Connection, 'getType',
return_value=host.HV_DRIVER_QEMU)
def test_update_host_specific_capabilities_without_maxphysaddr(
self, mock_get_lib_version, mock_get_version, mock_type):
self, mock_get_lib_version, mock_type):
driver = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI())
driver._update_host_specific_capabilities()
self.assertFalse(
@@ -22753,33 +22747,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
self.assertFalse(
driver.capabilities.get('supports_address_space_emulated'))
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_TB_CACHE_SIZE) - 1)
def test_supports_tb_cache_size_fail(self, mock_getversion):
self.flags(virt_type='qemu', group='libvirt')
self.flags(tb_cache_size=10, group='libvirt')
driver = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
self.assertRaises(exception.InvalidConfiguration,
driver.init_host, 'dummyhost')
@mock.patch.object(libvirt_driver.LibvirtDriver,
'_register_all_undefined_instance_details',
new=mock.Mock())
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_TB_CACHE_SIZE))
def test_supports_tb_cache_size_ok(self, mock_getversion):
self.flags(virt_type='qemu', group='libvirt')
self.flags(tb_cache_size=10, group='libvirt')
driver = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
driver.init_host('dummyhost')
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_TB_CACHE_SIZE))
def test_get_guest_config_feature_tcg(self, mock_getversion):
def test_get_guest_config_feature_tcg(self):
self.flags(virt_type='qemu', group='libvirt')
self.flags(tb_cache_size=10, group='libvirt')
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
@@ -28358,7 +28326,6 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
get_unassigned_mdevs.assert_called_once_with('pci_0000_06_00_0',
['nvidia-11'])
@mock.patch.object(nova.privsep.libvirt, 'create_mdev')
@mock.patch.object(libvirt_driver.LibvirtDriver,
'_get_mdev_capable_devices')
@mock.patch.object(libvirt_driver.LibvirtDriver,
@@ -28368,8 +28335,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
def test_allocate_mdevs_with_no_gpu_capacity(self,
get_supported_mdev_rcs,
unallocated_mdevs,
get_mdev_capable_devs,
privsep_create_mdev):
get_mdev_capable_devs):
self.flags(enabled_mdev_types=['nvidia-11'], group='devices')
allocations = {
uuids.rp1: {
+17 -92
View File
@@ -225,8 +225,6 @@ NEXT_MIN_QEMU_VERSION = (8, 2, 2)
# vIOMMU model value `virtio` minimal support version
MIN_LIBVIRT_VIOMMU_VIRTIO_MODEL = (8, 3, 0)
MIN_LIBVIRT_TB_CACHE_SIZE = (8, 0, 0)
# Virtuozzo driver support
MIN_VIRTUOZZO_VERSION = (7, 0, 0)
@@ -244,19 +242,10 @@ VGPU_RESOURCE_SEMAPHORE = 'vgpu_resources'
MIN_MDEV_LIVEMIG_LIBVIRT_VERSION = (8, 6, 0)
MIN_MDEV_LIVEMIG_QEMU_VERSION = (8, 1, 0)
# Minimum version supporting persistent mdevs.
# https://libvirt.org/drvnodedev.html#mediated-devices-mdevs
MIN_LIBVIRT_PERSISTENT_MDEV = (7, 3, 0)
# Autostart appears to be available starting in 7.8.0
# https://github.com/libvirt/libvirt/commit/c6607a25b93bd6b0188405785d6608fdf71c8e0a
MIN_LIBVIRT_NODEDEV_AUTOSTART = (7, 8, 0)
LIBVIRT_PERF_EVENT_PREFIX = 'VIR_PERF_PARAM_'
# Maxphysaddr minimal support version.
MIN_LIBVIRT_MAXPHYSADDR = (8, 7, 0)
MIN_QEMU_MAXPHYSADDR = (2, 7, 0)
# stateless firmware support
MIN_LIBVIRT_STATELESS_FIRMWARE = (8, 6, 0)
@@ -801,9 +790,6 @@ class LibvirtDriver(driver.ComputeDriver):
self._check_my_ip()
# TODO(ykarel) This can be dropped when MIN_LIBVIRT_VERSION>=8.0.0
self._supports_tb_cache_size()
if (CONF.libvirt.virt_type == 'lxc' and
not (CONF.libvirt.uid_maps and CONF.libvirt.gid_maps)):
LOG.warning("Running libvirt-lxc without user namespaces is "
@@ -891,18 +877,10 @@ class LibvirtDriver(driver.ComputeDriver):
# wrongly modified.
self.cpu_api.power_down_all_dedicated_cpus()
if not self._host.has_min_version(MIN_LIBVIRT_PERSISTENT_MDEV):
# TODO(sbauza): Remove this code once mediated devices are
# persisted across reboots.
# TODO(Uggla): Remove in bump cleanup patch
self._recreate_assigned_mediated_devices()
else:
# NOTE(melwitt): We shouldn't need to do this with libvirt 7.8.0
# and newer because we're setting autostart=True on the devices --
# but if that fails for whatever reason and any devices become
# inactive, we can start them here. With libvirt version < 7.8.0,
# this is needed because autostart is not available.
self._start_inactive_mediated_devices()
# NOTE(melwitt): We shouldn't need to do this because we're setting
# autostart=True on the devices -- but if that fails for whatever
# reason and any devices become inactive, we can start them here.
self._start_inactive_mediated_devices()
self._check_cpu_compatibility()
@@ -953,7 +931,6 @@ class LibvirtDriver(driver.ComputeDriver):
supports_maxphysaddr = self._host.has_min_version(
lv_ver=MIN_LIBVIRT_MAXPHYSADDR,
hv_ver=MIN_QEMU_MAXPHYSADDR,
hv_type=host.HV_DRIVER_QEMU,
)
@@ -1244,35 +1221,6 @@ class LibvirtDriver(driver.ComputeDriver):
# See https://bugzilla.redhat.com/show_bug.cgi?id=1376907 for ref.
return os.path.exists('/sys/bus/mdev/devices/{0}'.format(uuid))
def _recreate_assigned_mediated_devices(self):
"""Recreate assigned mdevs that could have disappeared if we reboot
the host.
"""
# NOTE(sbauza): This method just calls sysfs to recreate mediated
# devices by looking up existing guest XMLs and doesn't use
# the Placement API so it works with or without a vGPU reshape.
mdevs = self._get_all_assigned_mediated_devices()
for (mdev_uuid, instance_uuid) in mdevs.items():
if not self._is_existing_mdev(mdev_uuid):
dev_name = libvirt_utils.mdev_uuid2name(mdev_uuid)
dev_info = self._get_mediated_device_information(dev_name)
parent = dev_info['parent']
parent_type = self._get_vgpu_type_per_pgpu(parent)
if dev_info['type'] != parent_type:
# NOTE(sbauza): The mdev was created by using a different
# vGPU type. We can't recreate the mdev until the operator
# modifies the configuration.
parent = "{}:{}:{}.{}".format(*parent[4:].split('_'))
msg = ("The instance UUID %(inst)s uses a mediated device "
"type %(type)s that is no longer supported by the "
"parent PCI device, %(parent)s. Please correct "
"the configuration accordingly." %
{'inst': instance_uuid,
'parent': parent,
'type': dev_info['type']})
raise exception.InvalidLibvirtMdevConfig(reason=msg)
self._create_new_mediated_device(parent, uuid=mdev_uuid)
def _check_my_ip(self):
ips = compute_utils.get_machine_ips()
if CONF.my_ip not in ips:
@@ -1344,19 +1292,6 @@ class LibvirtDriver(driver.ComputeDriver):
"cpu_shared_set' and '[compute] cpu_dedicated_set', "
"respectively, and undefine 'vcpu_pin_set'.")
def _supports_tb_cache_size(self):
if (
CONF.libvirt.virt_type == 'qemu' and
CONF.libvirt.tb_cache_size and
CONF.libvirt.tb_cache_size > 0
):
if not self._host.has_min_version(MIN_LIBVIRT_TB_CACHE_SIZE):
raise exception.InvalidConfiguration(
_("Nova requires libvirt version %s or greater "
"with '[libvirt] tb_cache_size' "
"configured.") %
libvirt_utils.version_to_string(MIN_LIBVIRT_TB_CACHE_SIZE))
def _prepare_migration_flags(self):
migration_flags = 0
@@ -9042,23 +8977,17 @@ class LibvirtDriver(driver.ComputeDriver):
self._host.device_create(conf)
# Define it to make it persistent.
mdev_dev = self._host.device_define(conf)
# TODO(Uggla): Remove this in the libvirt bump cleanup patch
# As we are not setting autostart anymore, because we are not
# passing in following code.
# It makes test_allocate_mdevs_with_no_mdevs_but_capacity test to fail.
# So removing the tests.
if self._host.has_min_version(MIN_LIBVIRT_NODEDEV_AUTOSTART):
# Set it to automatically start when the compute host boots or the
# parent device becomes available.
# NOTE(melwitt): Make this not fatal because we can try to manually
# start mdevs in init_host() if they didn't start automatically
# after a host reboot.
try:
self._host.device_set_autostart(mdev_dev, autostart=True)
except Exception as e:
LOG.info(
'Failed to set autostart to True for mdev '
f'{mdev_dev.name()} with UUID {uuid}: {str(e)}.')
# Set it to automatically start when the compute host boots or the
# parent device becomes available.
# NOTE(melwitt): Make this not fatal because we can try to manually
# start mdevs in init_host() if they didn't start automatically
# after a host reboot.
try:
self._host.device_set_autostart(mdev_dev, autostart=True)
except Exception as e:
LOG.info(
'Failed to set autostart to True for mdev '
f'{mdev_dev.name()} with UUID {uuid}: {str(e)}.')
return uuid
def _create_new_mediated_device(self, parent, uuid=None):
@@ -9090,12 +9019,8 @@ class LibvirtDriver(driver.ComputeDriver):
# We need the PCI address, not the libvirt name
# The libvirt name is like 'pci_0000_84_00_0'
pci_addr = "{}:{}:{}.{}".format(*dev_name[4:].split('_'))
if not self._host.has_min_version(MIN_LIBVIRT_PERSISTENT_MDEV):
chosen_mdev = nova.privsep.libvirt.create_mdev(
pci_addr, dev_supported_type, uuid=uuid)
else:
chosen_mdev = self._create_mdev(
dev_name, dev_supported_type, uuid=uuid)
chosen_mdev = self._create_mdev(
dev_name, dev_supported_type, uuid=uuid)
LOG.info('Created mdev: %s on pGPU: %s.',
chosen_mdev, pci_addr)
return chosen_mdev