]> xenbits.xensource.com Git - libvirt.git/commitdiff
Don't try to detach & reset PCI devices while running test suite for XML-> ARGV conve...
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 3 Mar 2009 08:59:45 +0000 (08:59 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 3 Mar 2009 08:59:45 +0000 (08:59 +0000)
ChangeLog
src/qemu_conf.c
src/qemu_driver.c

index acc2dece18c14f752b75d4c1438cfab0723446f9..767dd679c0ff0860d55691cdd3ac6c2598716f99 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Mar  3 08:55:13 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
+
+       Don't try to detach & reset PCI devices while running test
+       suite for XML-> ARGV conversion.
+       * src/qemu_driver.c: Add qemuPrepareHostDevices() helper to
+       detach and reset PCI devices.
+       * src/qemu_conf.c: Don't detach & reset PCI devices while
+       building the command line argv
+
 Tue Mar  3 09:24:13 CET 2009 Daniel Veillard <veillard@redhat.com>
 
        * qemud/qemud.c: fix qemu+tls handshake negotiation, patch by
index d7257fa0dfa0a97b2b71cfbbc59c3ab315dca04e..c24f8b893ff81128d2901b0753d7efb9a79f9a2a 100644 (file)
@@ -47,7 +47,6 @@
 #include "datatypes.h"
 #include "xml.h"
 #include "nodeinfo.h"
-#include "pci.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -1395,52 +1394,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
             ADD_ARG_LIT("-pcidevice");
             ADD_ARG_LIT(pcidev);
             VIR_FREE(pcidev);
-
-            if (hostdev->managed) {
-                pciDevice *dev = pciGetDevice(conn,
-                                              hostdev->source.subsys.u.pci.domain,
-                                              hostdev->source.subsys.u.pci.bus,
-                                              hostdev->source.subsys.u.pci.slot,
-                                              hostdev->source.subsys.u.pci.function);
-                if (!dev)
-                    goto error;
-
-                if (pciDettachDevice(conn, dev) < 0) {
-                    pciFreeDevice(conn, dev);
-                    goto error;
-                }
-
-                pciFreeDevice(conn, dev);
-            } /* else {
-                XXX validate that non-managed device isn't in use, eg
-                by checking that device is either un-bound, or bound
-                to pci-stub.ko
-            } */
         }
-
-    }
-
-    /* Now that all the PCI hostdevs have be dettached, we can reset them */
-    for (i = 0 ; i < vm->def->nhostdevs ; i++) {
-        virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
-        pciDevice *dev;
-
-        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
-            continue;
-
-        dev = pciGetDevice(conn,
-                           hostdev->source.subsys.u.pci.domain,
-                           hostdev->source.subsys.u.pci.bus,
-                           hostdev->source.subsys.u.pci.slot,
-                           hostdev->source.subsys.u.pci.function);
-        if (!dev)
-            goto error;
-
-        if (pciResetDevice(conn, dev) < 0)
-            goto error;
-
-        pciFreeDevice(conn, dev);
     }
 
     if (migrateFrom) {
index 5221c35693fd6a32737a15f93d9c460896ea46c1..99de25353e4a7b314e64f974b469abceeb01892f 100644 (file)
@@ -1133,6 +1133,79 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
     return -1;
 }
 
+static int qemuPrepareHostDevices(virConnectPtr conn,
+                                  virDomainDefPtr def) {
+    int i;
+
+    /* We have to use 2 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
+     */
+
+    for (i = 0 ; i < def->nhostdevs ; i++) {
+        virDomainHostdevDefPtr hostdev = def->hostdevs[i];
+
+        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+            continue;
+        if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+            continue;
+
+        if (!hostdev->managed) {
+            pciDevice *dev = pciGetDevice(conn,
+                                          hostdev->source.subsys.u.pci.domain,
+                                          hostdev->source.subsys.u.pci.bus,
+                                          hostdev->source.subsys.u.pci.slot,
+                                          hostdev->source.subsys.u.pci.function);
+            if (!dev)
+                goto error;
+
+            if (pciDettachDevice(conn, dev) < 0) {
+                pciFreeDevice(conn, dev);
+                goto error;
+            }
+
+            pciFreeDevice(conn, dev);
+        } /* else {
+             XXX validate that non-managed device isn't in use, eg
+             by checking that device is either un-bound, or bound
+             to pci-stub.ko
+        } */
+    }
+
+    /* Now that all the PCI hostdevs have be dettached, we can safely
+     * reset them */
+    for (i = 0 ; i < def->nhostdevs ; i++) {
+        virDomainHostdevDefPtr hostdev = def->hostdevs[i];
+        pciDevice *dev;
+
+        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+            continue;
+        if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+            continue;
+
+        dev = pciGetDevice(conn,
+                           hostdev->source.subsys.u.pci.domain,
+                           hostdev->source.subsys.u.pci.bus,
+                           hostdev->source.subsys.u.pci.slot,
+                           hostdev->source.subsys.u.pci.function);
+        if (!dev)
+            goto error;
+
+        if (pciResetDevice(conn, dev) < 0) {
+            pciFreeDevice(conn, dev);
+            goto error;
+        }
+
+        pciFreeDevice(conn, dev);
+    }
+
+    return 0;
+
+error:
+    return -1;
+}
+
 static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
                                             const char *name);
 
@@ -1210,6 +1283,9 @@ static int qemudStartVMDaemon(virConnectPtr conn,
         return -1;
     }
 
+    if (qemuPrepareHostDevices(conn, vm->def) < 0)
+        return -1;
+
     vm->def->id = driver->nextvmid++;
     if (qemudBuildCommandLine(conn, driver, vm,
                               qemuCmdFlags, &argv, &progenv,