[PATCH 1/3] remove devices from driver->activePciHostdevs when qemuPrepareHostdevPCIDevices() failed

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

 



We should not mark pci devices as active when qemuPrepareHostdevPCIDevices()
failed.

---
 src/qemu/qemu_hostdev.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index f4b2108..30db0e2 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -112,7 +112,7 @@ int qemuPrepareHostdevPCIDevices(struct qemud_driver *driver,
     if (!(pcidevs = qemuGetPciHostDeviceList(hostdevs, nhostdevs)))
         return -1;
 
-    /* We have to use 3 loops here. *All* devices must
+    /* We have to use 4 loops here. *All* devices must
      * be detached before we reset any of them, because
      * in some cases you have to reset the whole PCI,
      * which impacts all devices on it. Also, all devices
@@ -145,14 +145,29 @@ int qemuPrepareHostdevPCIDevices(struct qemud_driver *driver,
     /* Now mark all the devices as active */
     for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
         pciDevice *dev = pciDeviceListGet(pcidevs, i);
-        pciDeviceListSteal(pcidevs, dev);
         if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
             pciFreeDevice(dev);
-            goto cleanup;
+            goto inactivedevs;
         }
     }
 
+    /* Now steal all the devices from pcidevs */
+    for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
+        pciDevice *dev = pciDeviceListGet(pcidevs, i);
+        pciDeviceListSteal(pcidevs, dev);
+    }
+
     ret = 0;
+    goto cleanup;
+
+inactivedevs:
+    /* Only steal all the devices from driver->activePciHostdevs. We will
+     * free them in pciDeviceListFree().
+     */
+    for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
+        pciDevice *dev = pciDeviceListGet(pcidevs, i);
+        pciDeviceListSteal(driver->activePciHostdevs, dev);
+    }
 
 cleanup:
     pciDeviceListFree(pcidevs);
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]