diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 06b0d28efb194e5c78f384a1977c3146d3151127..3427d3faa35c89b600940e01e04aabd56d998e11 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10022,7 +10022,7 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev) in_inactive_list = pciDeviceListFind(driver->inactivePciHostdevs, pci); if (pciDettachDevice(pci, driver->activePciHostdevs, - driver->inactivePciHostdevs) < 0) + driver->inactivePciHostdevs, "pci-stub") < 0) goto out; ret = 0; @@ -10067,7 +10067,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) qemuDriverLock(driver); if (pciReAttachDevice(pci, driver->activePciHostdevs, - driver->inactivePciHostdevs) < 0) + driver->inactivePciHostdevs, "pci-stub") < 0) goto out; ret = 0; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 174d125de9fc998714dceab16b3c500c7b90fc1a..896ad9be67683d684c68fd1f90695b685eddbc78 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -458,7 +458,7 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver, for (i = 0; i < pciDeviceListCount(pcidevs); i++) { pciDevice *dev = pciDeviceListGet(pcidevs, i); if (pciDeviceGetManaged(dev) && - pciDettachDevice(dev, driver->activePciHostdevs, NULL) < 0) + pciDettachDevice(dev, driver->activePciHostdevs, NULL, "pci-stub") < 0) goto reattachdevs; } @@ -574,7 +574,7 @@ resetvfnetconfig: reattachdevs: for (i = 0; i < pciDeviceListCount(pcidevs); i++) { pciDevice *dev = pciDeviceListGet(pcidevs, i); - pciReAttachDevice(dev, driver->activePciHostdevs, NULL); + pciReAttachDevice(dev, driver->activePciHostdevs, NULL, "pci-stub"); } cleanup: @@ -830,7 +830,7 @@ void qemuReattachPciDevice(pciDevice *dev, virQEMUDriverPtr driver) } if (pciReAttachDevice(dev, driver->activePciHostdevs, - driver->inactivePciHostdevs) < 0) { + driver->inactivePciHostdevs, "pci-stub") < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to re-attach PCI device: %s"), err ? err->message : _("unknown error")); diff --git a/src/util/virpci.c b/src/util/virpci.c index 4b26452d20aee3edd949f0e5ea58e990c1bc045e..0fb9923558016bc6fa10821436c8d6a34f17b387 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -855,57 +855,35 @@ pciDeviceFile(char **buffer, const char *device, const char *file) return 0; } - -static const char * -pciFindStubDriver(void) +static int +pciProbeStubDriver(const char *driver) { char *drvpath = NULL; int probed = 0; recheck: - if (pciDriverDir(&drvpath, "pci-stub") < 0) { - return NULL; - } - - if (virFileExists(drvpath)) { - VIR_FREE(drvpath); - return "pci-stub"; - } - - if (pciDriverDir(&drvpath, "pciback") < 0) { - return NULL; - } - - if (virFileExists(drvpath)) { + if (pciDriverDir(&drvpath, driver) == 0 && virFileExists(drvpath)) { + /* driver already loaded, return */ VIR_FREE(drvpath); - return "pciback"; + return 0; } VIR_FREE(drvpath); if (!probed) { - const char *const stubprobe[] = { MODPROBE, "pci-stub", NULL }; - const char *const backprobe[] = { MODPROBE, "pciback", NULL }; - + const char *const probecmd[] = { MODPROBE, driver, NULL }; probed = 1; - /* - * Probing for pci-stub will succeed regardless of whether - * on native or Xen kernels. - * On Xen though, we want to prefer pciback, so probe - * for that first, because that will only work on Xen - */ - if (virRun(backprobe, NULL) < 0 && - virRun(stubprobe, NULL) < 0) { + if (virRun(probecmd, NULL) < 0) { char ebuf[1024]; - VIR_WARN("failed to load pci-stub or pciback drivers: %s", + VIR_WARN("failed to load driver %s: %s", driver, virStrerror(errno, ebuf, sizeof(ebuf))); - return NULL; + return -1; } goto recheck; } - return NULL; + return -1; } static int @@ -1149,12 +1127,12 @@ cleanup: int pciDettachDevice(pciDevice *dev, pciDeviceList *activeDevs, - pciDeviceList *inactiveDevs) + pciDeviceList *inactiveDevs, + const char *driver) { - const char *driver = pciFindStubDriver(); - if (!driver) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot find any PCI stub module")); + if (pciProbeStubDriver(driver) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to load PCI stub module %s"), driver); return -1; } @@ -1179,12 +1157,12 @@ pciDettachDevice(pciDevice *dev, int pciReAttachDevice(pciDevice *dev, pciDeviceList *activeDevs, - pciDeviceList *inactiveDevs) + pciDeviceList *inactiveDevs, + const char *driver) { - const char *driver = pciFindStubDriver(); - if (!driver) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot find any PCI stub module")); + if (pciProbeStubDriver(driver) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to load PCI stub module %s"), driver); return -1; } diff --git a/src/util/virpci.h b/src/util/virpci.h index 115da4eda7db90991530864eb7cf241a19ef0173..bf7da019c1cbb44d06c9de1fa4b1c997f084513b 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -44,10 +44,12 @@ void pciFreeDevice (pciDevice *dev); const char *pciDeviceGetName (pciDevice *dev); int pciDettachDevice (pciDevice *dev, pciDeviceList *activeDevs, - pciDeviceList *inactiveDevs); + pciDeviceList *inactiveDevs, + const char *driver); int pciReAttachDevice (pciDevice *dev, pciDeviceList *activeDevs, - pciDeviceList *inactiveDevs); + pciDeviceList *inactiveDevs, + const char *driver); int pciResetDevice (pciDevice *dev, pciDeviceList *activeDevs, pciDeviceList *inactiveDevs); diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 559025ec7d59602889d4c7d582a08815ab5b7ffa..2795ebcb5cfe48213439b41c8420f3c974aa55b3 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2113,7 +2113,7 @@ xenUnifiedNodeDeviceDettach(virNodeDevicePtr dev) if (!pci) return -1; - if (pciDettachDevice(pci, NULL, NULL) < 0) + if (pciDettachDevice(pci, NULL, NULL, "pciback") < 0) goto out; ret = 0; @@ -2203,7 +2203,7 @@ xenUnifiedNodeDeviceReAttach(virNodeDevicePtr dev) goto out; } - if (pciReAttachDevice(pci, NULL, NULL) < 0) + if (pciReAttachDevice(pci, NULL, NULL, "pciback") < 0) goto out; ret = 0;