From 8f1912c58d6ea00622413641abfd949130eb080a Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 3 Mar 2009 08:59:45 +0000 Subject: [PATCH] Don't try to detach & reset PCI devices while running test suite for XML-> ARGV conversion. --- ChangeLog | 9 ++++++ src/qemu_conf.c | 46 ---------------------------- src/qemu_driver.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index acc2dece18..767dd679c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Mar 3 08:55:13 GMT 2009 Daniel P. Berrange + + 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 * qemud/qemud.c: fix qemu+tls handshake negotiation, patch by diff --git a/src/qemu_conf.c b/src/qemu_conf.c index d7257fa0df..c24f8b893f 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -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) { diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 5221c35693..99de25353e 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -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, -- GitLab