]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
remove devices from driver->activePciHostdevs when qemuPrepareHostdevPCIDevices(...
authorWen Congyang <wency@cn.fujitsu.com>
Mon, 28 Mar 2011 07:01:14 +0000 (15:01 +0800)
committerWen Congyang <wency@cn.fujitsu.com>
Thu, 7 Apr 2011 05:09:45 +0000 (13:09 +0800)
We should not mark pci devices as active when qemuPrepareHostdevPCIDevices()
failed.

src/qemu/qemu_hostdev.c

index f4b210856094b290917bdc988ae375c70b4b9ef3..30db0e2dd0ea8974b9412e3a4aea480b63c48002 100644 (file)
@@ -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);