[libvirt] [PATCH 1/5] Added ephemeral flag for hostdev in domain conf.

Shradha Shah sshah at solarflare.com
Tue Sep 18 15:02:16 UTC 2012


The ephemeral flag helps support migration with PCI-passthrough.
An ephemeral hostdev is automatically unplugged before migration
and replugged (if one is available on the destination) after
migration.
---
 docs/schemas/domaincommon.rng                      |   16 +++++++++++++
 src/conf/domain_conf.c                             |   23 ++++++++++++++++++-
 src/conf/domain_conf.h                             |    1 +
 src/qemu/qemu_command.c                            |    1 +
 .../qemuxml2argv-hostdev-pci-address.xml           |    2 +-
 .../qemuxml2argv-hostdev-usb-address.xml           |    2 +-
 .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml  |    2 +-
 tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml    |    4 +-
 8 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index aafb10c..349f22b 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1644,6 +1644,14 @@
               </choice>
             </attribute>
           </optional>
+          <optional>
+            <attribute name="ephemeral">
+              <choice>
+                <value>yes</value>
+                <value>no</value>
+              </choice>
+            </attribute>
+          </optional>
           <interleave>
             <element name="source">
               <choice>
@@ -2750,6 +2758,14 @@
           </choice>
         </attribute>
       </optional>
+      <optional>
+        <attribute name="ephemeral">
+          <choice>
+            <value>yes</value>
+            <value>no</value>
+          </choice>
+        </attribute>
+      </optional>
       <group>
         <element name="source">
           <choice>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b8ba0e2..0b6332a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2888,6 +2888,7 @@ virDomainHostdevPartsParse(xmlNodePtr node,
 {
     xmlNodePtr sourcenode;
     char *managed = NULL;
+    char *ephemeral = NULL;
     int ret = -1;
 
     /* @mode is passed in separately from the caller, since an
@@ -2914,6 +2915,16 @@ virDomainHostdevPartsParse(xmlNodePtr node,
             def->managed = 1;
     }
 
+    /* @ephemeral can be read from the xml document - it is always an
+     * attribute of the toplevel element, no matter what type of
+     * element that might be (pure hostdev, or higher level device
+     * (e.g. <interface>) with type='hostdev')
+     */
+    if ((ephemeral = virXMLPropString(node, "ephemeral"))!= NULL) {
+        if (STREQ(ephemeral,"yes"))
+            def->ephemeral = 1;
+    }
+
     /* @type is passed in from the caller rather than read from the
      * xml document, because it is specified in different places for
      * different kinds of defs - it is an attribute of
@@ -12027,6 +12038,10 @@ virDomainActualNetDefFormat(virBufferPtr buf,
         def->data.hostdev.def.managed) {
         virBufferAddLit(buf, " managed='yes'");
     }
+    if (def->type == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+        def->data.hostdev.def.ephemeral) {
+        virBufferAddLit(buf, " ephemeral='yes'");
+    }
     virBufferAddLit(buf, ">\n");
 
     virBufferAdjustIndent(buf, 2);
@@ -12097,6 +12112,10 @@ virDomainNetDefFormat(virBufferPtr buf,
         def->data.hostdev.def.managed) {
         virBufferAddLit(buf, " managed='yes'");
     }
+    if (def->type == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+        def->data.hostdev.def.ephemeral) {
+        virBufferAddLit(buf, " ephemeral='yes'");
+    }
     virBufferAddLit(buf, ">\n");
 
     virBufferAdjustIndent(buf, 6);
@@ -13063,8 +13082,8 @@ virDomainHostdevDefFormat(virBufferPtr buf,
         return -1;
     }
 
-    virBufferAsprintf(buf, "    <hostdev mode='%s' type='%s' managed='%s'>\n",
-                      mode, type, def->managed ? "yes" : "no");
+    virBufferAsprintf(buf, "    <hostdev mode='%s' type='%s' managed='%s' ephemeral='%s'>\n",
+                      mode, type, def->managed ? "yes" : "no", def->ephemeral ? "yes" : "no");
 
     virBufferAdjustIndent(buf, 6);
     if (virDomainHostdevSourceFormat(buf, def, flags, false) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f0dea48..8263711 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -385,6 +385,7 @@ struct _virDomainHostdevDef {
     virDomainDeviceDef parent; /* higher level Def containing this */
     int mode; /* enum virDomainHostdevMode */
     unsigned int managed : 1;
+    unsigned int ephemeral : 1;
     union {
         virDomainHostdevSubsys subsys;
         struct {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index cbf4aee..b7fbe75 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7410,6 +7410,7 @@ qemuParseCommandLinePCI(const char *val)
 
     def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
     def->managed = 1;
+    def->ephemeral = 1;
     def->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
     def->source.subsys.u.pci.bus = bus;
     def->source.subsys.u.pci.slot = slot;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml
index 3c69f83..fc7ea5c 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml
@@ -21,7 +21,7 @@
     </disk>
     <controller type='usb' index='0'/>
     <controller type='ide' index='0'/>
-    <hostdev mode='subsystem' type='pci' managed='yes'>
+    <hostdev mode='subsystem' type='pci' managed='yes' ephemeral='yes'>
       <source>
         <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>
       </source>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml
index 811e987..d07dbe3 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml
@@ -21,7 +21,7 @@
     </disk>
     <controller type='usb' index='0'/>
     <controller type='ide' index='0'/>
-    <hostdev mode='subsystem' type='usb' managed='no'>
+    <hostdev mode='subsystem' type='usb' managed='no' ephemeral='no'>
       <source>
         <address bus='14' device='6'/>
       </source>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
index 81f70d0..54aa5e6 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
@@ -21,7 +21,7 @@
     </disk>
     <controller type='usb' index='0'/>
     <controller type='ide' index='0'/>
-    <interface type='hostdev' managed='yes'>
+    <interface type='hostdev' managed='yes' ephemeral='yes'>
       <mac address='00:11:22:33:44:55'/>
       <source>
         <address type='pci' domain='0x0002' bus='0x03' slot='0x07' function='0x1'/>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
index 371835d..cce0d7f 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml
@@ -31,13 +31,13 @@
       <model type='virtio'/>
       <rom file='/etc/fake/bootrom.bin'/>
     </interface>
-    <hostdev mode='subsystem' type='pci' managed='yes'>
+    <hostdev mode='subsystem' type='pci' managed='yes' ephemeral='no'>
       <source>
         <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>
       </source>
       <rom bar='off'/>
     </hostdev>
-    <hostdev mode='subsystem' type='pci' managed='yes'>
+    <hostdev mode='subsystem' type='pci' managed='yes' ephemeral='no'>
       <source>
         <address domain='0x0000' bus='0x06' slot='0x12' function='0x6'/>
       </source>
-- 
1.7.4.4





More information about the libvir-list mailing list