From 8fb0b087629f90c2c183565c3810a8cc4230acf9 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Tue, 26 Jan 2021 00:31:16 -0500 Subject: [PATCH] hostdevmgr: remove unneeded oldStateDir Back in commit 2c71d3826, which appeared in libvirt-1.2.3 in April 2014, the location used to store saved MAC addresses and vlan tags of SRIOV VFs was changed from /var/run/libvirt/qemu to /var/run/libvirt/hostdevmgr. For backward compatibility the code was made to continue looking in the old location for the files when it didn't find them in the new location. It's now been 6 years, and even if there was somebody still running libvirt-1.2.3 on their system, that system would now be out of support for libvirt, so there would be no way for them to upgrade to a new libvirt that no longer looks in "oldStateDir" for the files. So let's no longer look in "oldStateDir" for the files! Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/hypervisor/virhostdev.c | 60 ++++++++----------------------------- src/hypervisor/virhostdev.h | 6 ++-- src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 4 +-- src/qemu/qemu_hostdev.c | 4 +-- tests/virhostdevtest.c | 10 +++---- 6 files changed, 23 insertions(+), 63 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index bd35397f2c..09995a52ed 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -484,17 +484,9 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, } -/* @oldStateDir: - * For upgrade purpose: - * To an existing VM on QEMU, the hostdev netconfig file is originally stored - * in cfg->stateDir (/var/run/libvirt/qemu). Switch to new version, it uses new - * location (mgr->stateDir) but certainly will not find it. In this - * case, try to find in the old state dir. - */ static int virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev, - const char *stateDir, - const char *oldStateDir) + const char *stateDir) { g_autofree char *linkdev = NULL; g_autofree virMacAddrPtr MAC = NULL; @@ -528,16 +520,11 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev, NULL, port_profile_associate); } else { - /* we need to try 3 different places for the config file: + /* we need to try 2 different places for the config file: * 1) ${stateDir}/${PF}_vf${vf} * This is almost always where the saved config is * - * 2) ${oldStateDir/${PF}_vf${vf} - * saved config is only here if this machine was running a - * (by now *very*) old version of libvirt that saved the - * file in a different directory - * - * 3) ${stateDir}${PF[1]}_vf${VF} + * 2) ${stateDir}${PF[1]}_vf${VF} * PF[1] means "the netdev for port 2 of the PF device", and * is only valid when the PF is a Mellanox dual port NIC with * a VF that was created in "single port" mode. @@ -556,18 +543,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev, return -1; } - /* 2) "old" (pre-1.2.3 circa 2014) location - whenever we get - * to the point that nobody will ever upgrade directly from - * 1.2.3 (or older) directly to current libvirt, we can - * eliminate this clause - **/ - if (!(adminMAC || vlan || MAC) && oldStateDir && - virNetDevReadNetConfig(linkdev, vf, oldStateDir, - &adminMAC, &vlan, &MAC) < 0) { - return -1; - } - - /* 3) try using the PF's "port 2" netdev as the name of the + /* 2) try using the PF's "port 2" netdev as the name of the * config file */ if (!(adminMAC || vlan || MAC)) { @@ -918,7 +894,7 @@ virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mgr, resetvfnetconfig: if (last_processed_hostdev_vf >= 0) { for (i = 0; i <= last_processed_hostdev_vf; i++) - virHostdevRestoreNetConfig(hostdevs[i], mgr->stateDir, NULL); + virHostdevRestoreNetConfig(hostdevs[i], mgr->stateDir); } reattachdevs: @@ -960,8 +936,7 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr, const char *dom_name, virPCIDeviceListPtr pcidevs, virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) + int nhostdevs) { size_t i; @@ -1043,8 +1018,7 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr, if (actual) { VIR_DEBUG("Restoring network configuration of PCI device %s", virPCIDeviceGetName(actual)); - virHostdevRestoreNetConfig(hostdev, mgr->stateDir, - oldStateDir); + virHostdevRestoreNetConfig(hostdev, mgr->stateDir); } } } @@ -1061,16 +1035,12 @@ virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr, } -/* @oldStateDir: - * For upgrade purpose: see virHostdevRestoreNetConfig - */ void virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) + int nhostdevs) { g_autoptr(virPCIDeviceList) pcidevs = NULL; @@ -1085,7 +1055,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, } virHostdevReAttachPCIDevicesImpl(mgr, drv_name, dom_name, pcidevs, - hostdevs, nhostdevs, oldStateDir); + hostdevs, nhostdevs); } @@ -2120,23 +2090,18 @@ virHostdevPrepareDomainDevices(virHostdevManagerPtr mgr, return 0; } -/* @oldStateDir - * For upgrade purpose: see virHostdevReAttachPCIHostdevs - */ void virHostdevReAttachDomainDevices(virHostdevManagerPtr mgr, const char *driver, virDomainDefPtr def, - unsigned int flags, - const char *oldStateDir) + unsigned int flags) { if (!def->nhostdevs || !mgr) return; if (flags & VIR_HOSTDEV_SP_PCI) { virHostdevReAttachPCIDevices(mgr, driver, def->name, - def->hostdevs, def->nhostdevs, - oldStateDir); + def->hostdevs, def->nhostdevs); } if (flags & VIR_HOSTDEV_SP_USB) { @@ -2388,8 +2353,7 @@ virHostdevReAttachOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, goto cleanup; virHostdevReAttachPCIDevicesImpl(hostdev_mgr, - drv_name, dom_name, pciDevices, - NULL, 0, NULL); + drv_name, dom_name, pciDevices, NULL, 0); for (i = 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { virNVMeDevicePtr temp = virNVMeDeviceListGet(nvmeDevices, i); diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h index 811bda40ed..19e1938d9e 100644 --- a/src/hypervisor/virhostdev.h +++ b/src/hypervisor/virhostdev.h @@ -113,8 +113,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) + int nhostdevs) ATTRIBUTE_NONNULL(1); void virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr, @@ -188,8 +187,7 @@ void virHostdevReAttachDomainDevices(virHostdevManagerPtr mgr, const char *driver, virDomainDefPtr def, - unsigned int flags, - const char *oldStateDir) + unsigned int flags) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); /* functions used by NodeDevDetach/Reattach/Reset */ diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index afa21bf02e..380f7e0b56 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -868,7 +868,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, } virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME, - vm->def, hostdev_flags, NULL); + vm->def, hostdev_flags); VIR_FREE(priv->lockState); if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 3eaf106006..f480f8067e 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3153,7 +3153,7 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, error: virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME, - vm->def->name, &hostdev, 1, NULL); + vm->def->name, &hostdev, 1); cleanup: virObjectUnref(cfg); @@ -3690,7 +3690,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, virDomainHostdevRemove(vm->def, idx); virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME, - vm->def->name, &hostdev, 1, NULL); + vm->def->name, &hostdev, 1); ret = 0; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 721fe5da82..c5d89e1fc8 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -405,12 +405,10 @@ qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver, virDomainHostdevDefPtr *hostdevs, int nhostdevs) { - g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); - const char *oldStateDir = cfg->stateDir; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevReAttachPCIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name, - hostdevs, nhostdevs, oldStateDir); + hostdevs, nhostdevs); } void diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 40c14a5281..91f9112e8b 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -245,13 +245,13 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void) inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs); VIR_TEST_DEBUG("Test 0 hostdevs"); - virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, NULL, 0, NULL); + virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, NULL, 0); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); VIR_TEST_DEBUG("Test >=1 unmanaged hostdevs"); virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, - hostdevs, nhostdevs, NULL); + hostdevs, nhostdevs); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostdevs); @@ -329,13 +329,13 @@ testVirHostdevReAttachPCIHostdevs_managed(bool mixed) inactive_count = virPCIDeviceListCount(mgr->inactivePCIHostdevs); VIR_TEST_DEBUG("Test 0 hostdevs"); - virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, NULL, 0, NULL); + virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, NULL, 0); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); VIR_TEST_DEBUG("Test >=1 hostdevs"); virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, - hostdevs, nhostdevs, NULL); + hostdevs, nhostdevs); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); /* If testing a mixed roundtrip, devices are added back to the inactive * list as soon as we detach from the guest */ @@ -542,7 +542,7 @@ testNVMeDiskRoundtrip(const void *opaque G_GNUC_UNUSED) /* Don't rely on a state that previous test cases might have * left the manager in. Start with a clean slate. */ virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, - hostdevs, nhostdevs, NULL); + hostdevs, nhostdevs); CHECK_NVME_LIST_COUNT(mgr->activeNVMeHostdevs, 0); CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, 0);