From 09fb8845a774bf5ea6551d654ea05e5b6caf7309 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 2 Mar 2009 16:40:30 +0000 Subject: [PATCH] adds a new property to host devices in domains * 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 property to host devices indicating whether or not we should automatically dettach/reset, patch by Mark McLoughlin daniel --- ChangeLog | 11 +++++ docs/schemas/domain.rng | 6 +++ src/domain_conf.c | 12 +++++- src/domain_conf.h | 1 + src/qemu_conf.c | 42 +++++++++++++++++++ .../qemuxml2argv-hostdev-pci-address.xml | 2 +- .../qemuxml2argv-hostdev-usb-address.xml | 2 +- .../qemuxml2argv-hostdev-usb-product.xml | 2 +- 8 files changed, 73 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21fdf8ddb8..42a3fb6fd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Mon Mar 2 17:35:09 CET 2009 Daniel Veillard + + * 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 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 * src/qemu_driver.c: add qemu dettach/reattach/reset implementation diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index 04f6e78d89..8bd3ffb029 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -911,6 +911,12 @@ pci + + + yes + no + + diff --git a/src/domain_conf.c b/src/domain_conf.c index 622665c4c4..23618b93df 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -1729,7 +1729,7 @@ virDomainHostdevDefParseXML(virConnectPtr conn, xmlNodePtr cur; virDomainHostdevDefPtr def; - char *mode, *type = NULL; + char *mode, *type = NULL, *managed = NULL; if (VIR_ALLOC(def) < 0) { virReportOOMError(conn); @@ -1761,6 +1761,13 @@ virDomainHostdevDefParseXML(virConnectPtr 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) { @@ -3185,7 +3192,8 @@ virDomainHostdevDefFormat(virConnectPtr conn, return -1; } - virBufferVSprintf(buf, " \n", mode, type); + virBufferVSprintf(buf, " \n", + mode, type, def->managed ? "yes" : "no"); virBufferAddLit(buf, " \n"); if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { diff --git a/src/domain_conf.h b/src/domain_conf.h index b6f6b43b34..d370b5d0e7 100644 --- a/src/domain_conf.h +++ b/src/domain_conf.h @@ -305,6 +305,7 @@ typedef struct _virDomainHostdevDef virDomainHostdevDef; typedef virDomainHostdevDef *virDomainHostdevDefPtr; struct _virDomainHostdevDef { int mode; /* enum virDomainHostdevMode */ + unsigned int managed : 1; union { struct { int type; /* enum virDomainHostdevBusType */ diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 6f58ee8123..fad3eeb622 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -47,6 +47,7 @@ #include "datatypes.h" #include "xml.h" #include "nodeinfo.h" +#include "pci.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -1394,10 +1395,51 @@ 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); + } } } + /* 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); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml index af2f400b0b..9a6207e5ef 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml @@ -18,7 +18,7 @@ - +
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml index 0c044e1787..61bb2a2b2a 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml @@ -18,7 +18,7 @@ - +
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml index aecad4ca25..b86166563e 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml @@ -18,7 +18,7 @@ - + -- GitLab