[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] pass stub driver name instead of pciFindStubDriver



Pass stub driver name directly to pciDettachDevice and pciReAttachDevice to fit
for different libvirt drivers. For example, qemu driver prefers pci-stub, but
Xen prefers pciback.
 
Signed-off-by: Chunyan Liu <cyliu suse com>
---
 src/qemu/qemu_driver.c  |    4 +-
 src/qemu/qemu_hostdev.c |    6 ++--
 src/util/virpci.c       |   62 +++++++++++++++-------------------------------
 src/util/virpci.h       |    6 +++-
 src/xen/xen_driver.c    |    4 +-
 5 files changed, 31 insertions(+), 51 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 06b0d28..3427d3f 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 174d125..896ad9b 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 4b26452..fb305e2 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 115da4e..bf7da01 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 559025e..2795ebc 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;
-- 
1.7.3.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]