[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 26/62] conf: Allow formatting and parsing of 'index' for disk source image



Similarly to backing store indexes which will become stable eventually
we need also to be able to format and store in the status XML for later
use the index for the top level of the backing chain.

Add XML formatter, parser, schema and docs.

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
 docs/formatdomain.html.in                           |  7 ++++++-
 docs/schemas/domaincommon.rng                       | 19 +++++++++++++++++++
 src/conf/domain_conf.c                              | 21 +++++++++++++++++----
 .../qemuxml2argvdata/disk-backing-chains-index.xml  | 12 ++++++------
 .../disk-backing-chains-index-active.xml            | 12 ++++++------
 5 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 34664f7903..231e74e6b8 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2962,6 +2962,11 @@
         is only valid when the specified storage volume is of 'file' or
         'block' type).
         <p>
+        The <code>source</code> element may also have the <code>index</code>
+        attribute with same semantics the <a href='#elementsDiskBackingStoreIndex'>
+        <code>index</code></a> attribute of <code>backingStore</code>
+        </p>
+        <p>
         The <code>source</code> element may contain the following sub elements:
         </p>

@@ -3170,7 +3175,7 @@
             by the backing store, see disk type attribute above for more
             details and possible values.
           </dd>
-          <dt><code>index</code></dt>
+          <dt><code><a id="elementsDiskBackingStoreIndex">index</a></code></dt>
           <dd>
             This attribute is only valid in output (and ignored on input) and
             it can be used to refer to a specific part of the disk chain when
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 1a786968cc..e98f71536f 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1528,6 +1528,14 @@
     </optional>
   </define>

+  <define name="diskSourceCommon">
+    <optional>
+      <attribute name="index">
+        <ref name="positiveInteger"/>
+      </attribute>
+    </optional>
+  </define>
+
   <define name="diskSource">
     <choice>
       <ref name="diskSourceFile"/>
@@ -1551,6 +1559,7 @@
             <ref name="absFilePath"/>
           </attribute>
         </optional>
+        <ref name="diskSourceCommon"/>
         <optional>
           <ref name="storageStartupPolicy"/>
         </optional>
@@ -1575,6 +1584,7 @@
             <ref name="absFilePath"/>
           </attribute>
         </optional>
+        <ref name="diskSourceCommon"/>
         <optional>
           <ref name="storageStartupPolicy"/>
         </optional>
@@ -1600,6 +1610,7 @@
         <attribute name="dir">
           <ref name="absFilePath"/>
         </attribute>
+        <ref name="diskSourceCommon"/>
         <optional>
           <ref name="storageStartupPolicy"/>
         </optional>
@@ -1653,6 +1664,7 @@
         <attribute name="protocol">
           <value>rbd</value>
         </attribute>
+        <ref name="diskSourceCommon"/>
         <optional>
           <attribute name="name"/>
         </optional>
@@ -1692,6 +1704,7 @@
         <value>iscsi</value>
       </attribute>
       <attribute name="name"/>
+      <ref name="diskSourceCommon"/>
       <ref name="diskSourceNetworkHost"/>
       <optional>
         <ref name="diskAuth"/>
@@ -1714,6 +1727,7 @@
         </choice>
       </attribute>
       <attribute name="name"/>
+      <ref name="diskSourceCommon"/>
       <ref name="diskSourceNetworkHost"/>
       <optional>
         <ref name="encryption"/>
@@ -1732,6 +1746,7 @@
         </choice>
       </attribute>
       <attribute name="name"/>
+      <ref name="diskSourceCommon"/>
       <ref name="diskSourceNetworkHost"/>
       <optional>
         <ref name="encryption"/>
@@ -1752,6 +1767,7 @@
           <ref name="virYesNo"/>
         </attribute>
       </optional>
+      <ref name="diskSourceCommon"/>
       <ref name="diskSourceNetworkHost"/>
       <optional>
         <ref name="encryption"/>
@@ -1765,6 +1781,7 @@
         <value>gluster</value>
       </attribute>
       <attribute name="name"/>
+      <ref name="diskSourceCommon"/>
       <oneOrMore>
         <ref name="diskSourceNetworkHost"/>
       </oneOrMore>
@@ -1782,6 +1799,7 @@
         </choice>
       </attribute>
       <attribute name="name"/>
+      <ref name="diskSourceCommon"/>
       <optional>
         <attribute name="tls">
           <ref name="virYesNo"/>
@@ -1826,6 +1844,7 @@
             </choice>
           </attribute>
         </optional>
+        <ref name="diskSourceCommon"/>
         <optional>
           <ref name="storageStartupPolicy"/>
         </optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c10e0a9eca..72602fb48c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9805,6 +9805,13 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,

             startupPolicy = virXMLPropString(cur, "startupPolicy");

+            if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
+                (tmp = virXMLPropString(cur, "index")) &&
+                virStrToLong_uip(tmp, NULL, 10, &def->src->id) < 0) {
+                virReportError(VIR_ERR_XML_ERROR, _("invalid disk index '%s'"), tmp);
+                goto error;
+            }
+            VIR_FREE(tmp);
         } else if (!target &&
                    virXMLNodeNameEqual(cur, "target")) {
             target = virXMLPropString(cur, "dev");
@@ -23776,6 +23783,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
                                   int policy,
                                   unsigned int flags,
                                   bool skipSeclabels,
+                                  bool attrIndex,
                                   virDomainXMLOptionPtr xmlopt)
 {
     virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
@@ -23792,6 +23800,9 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
         virBufferEscapeString(&attrBuf, " startupPolicy='%s'",
                               virDomainStartupPolicyTypeToString(policy));

+    if (attrIndex && src->id != 0)
+        virBufferAsprintf(&attrBuf, " index='%u'", src->id);
+
     if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0)
         goto cleanup;

@@ -23814,7 +23825,8 @@ virDomainDiskSourceFormat(virBufferPtr buf,
                           unsigned int flags,
                           virDomainXMLOptionPtr xmlopt)
 {
-    return virDomainDiskSourceFormatInternal(buf, src, policy, flags, false, xmlopt);
+    return virDomainDiskSourceFormatInternal(buf, src, policy, flags, false,
+                                             false, xmlopt);
 }


@@ -23856,7 +23868,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,

     virBufferAsprintf(buf, "<format type='%s'/>\n", format);
     /* We currently don't output seclabels for backing chain element */
-    if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, flags, true, xmlopt) < 0 ||
+    if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, flags, true,
+                                          false, xmlopt) < 0 ||
         virDomainDiskBackingStoreFormat(buf, backingStore->backingStore,
                                         xmlopt, flags) < 0)
         return -1;
@@ -24122,8 +24135,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
     if (def->src->auth && !def->src->authInherited)
         virStorageAuthDefFormat(buf, def->src->auth);

-    if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy,
-                                  flags, xmlopt) < 0)
+    if (virDomainDiskSourceFormatInternal(buf, def->src, def->startupPolicy,
+                                          flags, false, true, xmlopt) < 0)
         return -1;

     /* Don't format backingStore to inactive XMLs until the code for
diff --git a/tests/qemuxml2argvdata/disk-backing-chains-index.xml b/tests/qemuxml2argvdata/disk-backing-chains-index.xml
index 95b8a64cf8..5e0a03fbc4 100644
--- a/tests/qemuxml2argvdata/disk-backing-chains-index.xml
+++ b/tests/qemuxml2argvdata/disk-backing-chains-index.xml
@@ -16,7 +16,7 @@
     <emulator>/usr/bin/qemu-system-i686</emulator>
     <disk type='network' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source protocol='gluster' name='Volume2/Image'>
+      <source protocol='gluster' name='Volume2/Image' index='2'>
         <host transport='unix' socket='/path/to/sock'/>
       </source>
       <backingStore type='file' index='1'>
@@ -27,7 +27,7 @@
     </disk>
     <disk type='network' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source protocol='nbd' name='bar'>
+      <source protocol='nbd' name='bar' index='9'>
         <host transport='unix' socket='/var/run/nbdsock'/>
       </source>
       <backingStore type='block' index='8'>
@@ -61,7 +61,7 @@
     <disk type='network' device='disk'>
       <driver name='qemu' type='raw'/>
       <backingStore/>
-      <source protocol='gluster' name='Volume1/Image'>
+      <source protocol='gluster' name='Volume1/Image' index='10'>
         <host name='example.org' port='6000'/>
       </source>
       <target dev='vdc' bus='virtio'/>
@@ -71,7 +71,7 @@
       <auth username='myname'>
         <secret type='ceph' usage='mycluster_myname'/>
       </auth>
-      <source protocol='rbd' name='pool/image'>
+      <source protocol='rbd' name='pool/image' index='12'>
         <host name='mon1.example.org' port='6321'/>
         <host name='mon2.example.org' port='6322'/>
         <host name='mon3.example.org' port='6322'/>
@@ -85,12 +85,12 @@
     </disk>
     <disk type='block' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source dev='/dev/HostVG/QEMUGuest11'/>
+      <source dev='/dev/HostVG/QEMUGuest11' index='13'/>
       <target dev='vde' bus='virtio'/>
     </disk>
     <disk type='file' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source file='/var/lib/libvirt/images/rhel7.1484071880'/>
+      <source file='/var/lib/libvirt/images/rhel7.1484071880' index='25'/>
       <backingStore type='file' index='24'>
         <format type='qcow2'/>
         <source file='/var/lib/libvirt/images/rhel7.1484071877'/>
diff --git a/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml b/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
index 724afa4e83..2b5bc9e1b4 100644
--- a/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
+++ b/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
@@ -16,7 +16,7 @@
     <emulator>/usr/bin/qemu-system-i686</emulator>
     <disk type='network' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source protocol='gluster' name='Volume2/Image'>
+      <source protocol='gluster' name='Volume2/Image' index='2'>
         <host transport='unix' socket='/path/to/sock'/>
       </source>
       <backingStore type='file' index='1'>
@@ -28,7 +28,7 @@
     </disk>
     <disk type='network' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source protocol='nbd' name='bar'>
+      <source protocol='nbd' name='bar' index='9'>
         <host transport='unix' socket='/var/run/nbdsock'/>
       </source>
       <backingStore type='block' index='8'>
@@ -61,7 +61,7 @@
     </disk>
     <disk type='network' device='disk'>
       <driver name='qemu' type='raw'/>
-      <source protocol='gluster' name='Volume1/Image'>
+      <source protocol='gluster' name='Volume1/Image' index='10'>
         <host name='example.org' port='6000'/>
       </source>
       <backingStore/>
@@ -73,7 +73,7 @@
       <auth username='myname'>
         <secret type='ceph' usage='mycluster_myname'/>
       </auth>
-      <source protocol='rbd' name='pool/image'>
+      <source protocol='rbd' name='pool/image' index='12'>
         <host name='mon1.example.org' port='6321'/>
         <host name='mon2.example.org' port='6322'/>
         <host name='mon3.example.org' port='6322'/>
@@ -88,13 +88,13 @@
     </disk>
     <disk type='block' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source dev='/dev/HostVG/QEMUGuest11'/>
+      <source dev='/dev/HostVG/QEMUGuest11' index='13'/>
       <target dev='vde' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
     </disk>
     <disk type='file' device='disk'>
       <driver name='qemu' type='qcow2'/>
-      <source file='/var/lib/libvirt/images/rhel7.1484071880'/>
+      <source file='/var/lib/libvirt/images/rhel7.1484071880' index='25'/>
       <backingStore type='file' index='24'>
         <format type='qcow2'/>
         <source file='/var/lib/libvirt/images/rhel7.1484071877'/>
-- 
2.16.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]