]> xenbits.xensource.com Git - libvirt.git/commitdiff
adds a new <hostdev managed='(yes|no)'> property to host devices in domains
authorDaniel Veillard <veillard@redhat.com>
Mon, 2 Mar 2009 16:40:30 +0000 (16:40 +0000)
committerDaniel Veillard <veillard@redhat.com>
Mon, 2 Mar 2009 16:40:30 +0000 (16:40 +0000)
* 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
daniel

ChangeLog
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

index 21fdf8ddb8bc2452a2c0ebd8cef0b0a2de71c201..42a3fb6fd4c711f378f1af9ee4fc16d6d832f073 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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
index 04f6e78d8984e3ee2fe62a59e6e8403cdaeda9ec..8bd3ffb029b18351eb91ec1f0db1baed102deb3d 100644 (file)
            <value>pci</value>
           </choice>
         </attribute>
+       <attribute name='managed'>
+         <choice>
+           <value>yes</value>
+           <value>no</value>
+         </choice>
+       </attribute>
       </optional>
       <group>
           <element name='source'>
index 622665c4c4516174fdf59426800760fff2c57ab8..23618b93df5462b808343f157ae75b5c9205e731 100644 (file)
@@ -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, "    <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) {
index b6f6b43b34942fc6887136f8d159051680f1d575..d370b5d0e7bcf4a767fb2003a5f9627622beddbd 100644 (file)
@@ -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 */
index 6f58ee81239e1caaaa5d7ef2d0e33c08024cb18b..fad3eeb622c8946005f4714dde83600526be387d 100644 (file)
@@ -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);
index af2f400b0b5dcecac148824d2b843a822bf6ac15..9a6207e5eff24486936b949e876ca8ae8de3d43f 100644 (file)
@@ -18,7 +18,7 @@
       <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>
index 0c044e17875cbc8db0ec2ff3f933f6b38671f345..61bb2a2b2a137403bcb4fe9c18d51b4ea2a0d1a1 100644 (file)
@@ -18,7 +18,7 @@
       <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>
index aecad4ca257d8c290cf8835e53d790bc528a07ab..b86166563ed39338460a4ad83794490e7d694757 100644 (file)
@@ -18,7 +18,7 @@
       <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'/>