+Mon Mar 2 17:35:09 CET 2009 Daniel Veillard <veillard@redhat.com>
+
+ * docs/schemas/domain.rng src/domain_conf.c src/domain_conf.h
+ src/qemu_conf.c
+ tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml
+ tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml
+ tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml:
+ adds a new <hostdev managed='(yes|no)'> property
+ to host devices indicating whether or not we should
+ automatically dettach/reset, patch by Mark McLoughlin
+
Mon Mar 2 17:31:48 CET 2009 Daniel Veillard <veillard@redhat.com>
* src/qemu_driver.c: add qemu dettach/reattach/reset implementation
<value>pci</value>
</choice>
</attribute>
+ <attribute name='managed'>
+ <choice>
+ <value>yes</value>
+ <value>no</value>
+ </choice>
+ </attribute>
</optional>
<group>
<element name='source'>
xmlNodePtr cur;
virDomainHostdevDefPtr def;
- char *mode, *type = NULL;
+ char *mode, *type = NULL, *managed = NULL;
if (VIR_ALLOC(def) < 0) {
virReportOOMError(conn);
goto error;
}
+ managed = virXMLPropString(node, "managed");
+ if (managed != NULL) {
+ if (STREQ(managed, "yes"))
+ def->managed = 1;
+ VIR_FREE(managed);
+ }
+
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
return -1;
}
- virBufferVSprintf(buf, " <hostdev mode='%s' type='%s'>\n", mode, type);
+ virBufferVSprintf(buf, " <hostdev mode='%s' type='%s' managed='%s'>\n",
+ mode, type, def->managed ? "yes" : "no");
virBufferAddLit(buf, " <source>\n");
if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
typedef virDomainHostdevDef *virDomainHostdevDefPtr;
struct _virDomainHostdevDef {
int mode; /* enum virDomainHostdevMode */
+ unsigned int managed : 1;
union {
struct {
int type; /* enum virDomainHostdevBusType */
#include "datatypes.h"
#include "xml.h"
#include "nodeinfo.h"
+#include "pci.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
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);
+ }
}
}
+ /* 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->managed ||
+ 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) {
ADD_ARG_LIT("-incoming");
ADD_ARG_LIT(migrateFrom);
<source dev='/dev/HostVG/QEMUGuest2'/>
<target dev='hda' bus='ide'/>
</disk>
- <hostdev mode='subsystem' type='pci'>
+ <hostdev mode='subsystem' type='pci' managed='no'>
<source>
<address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>
</source>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
</disk>
- <hostdev mode='subsystem' type='usb'>
+ <hostdev mode='subsystem' type='usb' managed='no'>
<source>
<address bus='14' device='6'/>
</source>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
</disk>
- <hostdev mode='subsystem' type='usb'>
+ <hostdev mode='subsystem' type='usb' managed='no'>
<source>
<vendor id='0x0204'/>
<product id='0x6025'/>