]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: expose volume meta-type in XML
authorEric Blake <eblake@redhat.com>
Tue, 19 Nov 2013 20:14:54 +0000 (13:14 -0700)
committerEric Blake <eblake@redhat.com>
Mon, 25 Nov 2013 17:55:19 +0000 (10:55 -0700)
I got annoyed at having to use both 'virsh vol-list $pool --details'
AND 'virsh vol-dumpxml $vol $pool' to learn if I had populated
the volume correctly.  Since two-thirds of the data present in
virStorageVolGetInfo() already appears in virStorageVolGetXMLDesc(),
this just adds the remaining piece of information, as:

<volume type='...'>
  ...
</volume>

* docs/formatstorage.html.in: Document new <volume type=...>.
* docs/schemas/storagevol.rng (vol): Add it to RelaxNG.
* src/conf/storage_conf.h (virStorageVolTypeToString): Declare.
* src/conf/storage_conf.c (virStorageVolTargetDefFormat): Output
the metatype.
(virStorageVolDefParseXML): Parse it, for unit tests.
* tests/storagevolxml2xmlout/vol-*.xml: Update tests to match.

Signed-off-by: Eric Blake <eblake@redhat.com>
20 files changed:
docs/formatstorage.html.in
docs/schemas/storagevol.rng
src/conf/storage_conf.c
src/conf/storage_conf.h
tests/storagevolxml2xmlin/vol-logical-backing.xml
tests/storagevolxml2xmlin/vol-logical.xml
tests/storagevolxml2xmlin/vol-partition.xml
tests/storagevolxml2xmlin/vol-sheepdog.xml
tests/storagevolxml2xmlout/vol-file-backing.xml
tests/storagevolxml2xmlout/vol-file-naming.xml
tests/storagevolxml2xmlout/vol-file.xml
tests/storagevolxml2xmlout/vol-logical-backing.xml
tests/storagevolxml2xmlout/vol-logical.xml
tests/storagevolxml2xmlout/vol-partition.xml
tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml
tests/storagevolxml2xmlout/vol-qcow2-1.1.xml
tests/storagevolxml2xmlout/vol-qcow2-lazy.xml
tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml
tests/storagevolxml2xmlout/vol-qcow2.xml
tests/storagevolxml2xmlout/vol-sheepdog.xml

index 90eeaa3ab3db8b52b77adf2f0ec4a2f26265d69c..c90d7b1baaf656aec9825ba899d232b510db4335 100644 (file)
 
     <h2><a name="StorageVol">Storage volume XML</a></h2>
     <p>
-      A storage volume will be either a file or a device node.
-      The storage volume XML format is available <span class="since">since 0.4.1</span>
+      A storage volume will generally be either a file or a device
+      node; <span class="since">since 1.2.0</span>, an optional
+      output-only attribute <code>type</code> lists the actual type
+      (file, block, dir, or network), which is also available
+      from <code>virStorageVolGetInfo()</code>.  The storage volume
+      XML format is available <span class="since">since 0.4.1</span>
     </p>
 
     <h3><a name="StorageVolFirst">General metadata</a></h3>
 
     <pre>
-      &lt;volume&gt;
+      &lt;volume type='file'&gt;
         &lt;name&gt;sparse.img&lt;/name&gt;
         &lt;key&gt;/var/lib/xen/images/sparse.img&lt;/key&gt;
         &lt;allocation&gt;0&lt;/allocation&gt;
index e79bc3591966f36bb8485e6c066cc224e0c67009..f8081d9c51d03f48b67cfd430e6e48c14b90afd4 100644 (file)
 
   <define name='vol'>
     <element name='volume'>
+      <optional>
+        <attribute name='type'>
+          <choice>
+            <value>file</value>
+            <value>block</value>
+            <value>dir</value>
+            <value>network</value>
+          </choice>
+        </attribute>
+      </optional>
       <interleave>
         <element name='name'>
           <ref name='volName'/>
index 8b378c208ebbd7c9ec1e137c68f35d1ae8651c90..0cd80c32c491bfdeda8fbd61701ddc262a4bb36f 100644 (file)
 #define DEFAULT_POOL_PERM_MODE 0755
 #define DEFAULT_VOL_PERM_MODE  0600
 
+VIR_ENUM_IMPL(virStorageVol,
+              VIR_STORAGE_VOL_LAST,
+              "file", "block", "dir", "network")
+
 VIR_ENUM_IMPL(virStoragePool,
               VIR_STORAGE_POOL_LAST,
               "dir", "fs", "netfs",
@@ -1253,6 +1257,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 {
     virStorageVolDefPtr ret;
     virStorageVolOptionsPtr options;
+    char *type = NULL;
     char *allocation = NULL;
     char *capacity = NULL;
     char *unit = NULL;
@@ -1278,6 +1283,16 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     /* Normally generated by pool refresh, but useful for unit tests */
     ret->key = virXPathString("string(./key)", ctxt);
 
+    /* Technically overridden by pool refresh, but useful for unit tests */
+    type = virXPathString("string(./@type)", ctxt);
+    if (type) {
+        if ((ret->type = virStorageVolTypeFromString(type)) < 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("unknown volume type '%s'"), type);
+            goto error;
+        }
+    }
+
     capacity = virXPathString("string(./capacity)", ctxt);
     unit = virXPathString("string(./capacity/@unit)", ctxt);
     if (capacity == NULL) {
@@ -1394,6 +1409,7 @@ cleanup:
     VIR_FREE(allocation);
     VIR_FREE(capacity);
     VIR_FREE(unit);
+    VIR_FREE(type);
     return ret;
 
 error:
@@ -1563,7 +1579,8 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
     if (options == NULL)
         return NULL;
 
-    virBufferAddLit(&buf, "<volume>\n");
+    virBufferAsprintf(&buf, "<volume type='%s'>\n",
+                      virStorageVolTypeToString(def->type));
     virBufferEscapeString(&buf, "  <name>%s</name>\n", def->name);
     virBufferEscapeString(&buf, "  <key>%s</key>\n", def->key);
     virBufferAddLit(&buf, "  <source>\n");
index f062bd8213b181bb753e92e63fc6ea1cc122e48c..c4dd403459239b4b86fa88576a7df6ef6d3402d4 100644 (file)
@@ -116,6 +116,7 @@ struct _virStorageVolDefList {
     virStorageVolDefPtr *objs;
 };
 
+VIR_ENUM_DECL(virStorageVol)
 
 enum virStoragePoolType {
     VIR_STORAGE_POOL_DIR,      /* Local directory */
index b4141a5c99715ff3cc362e5ac78fc53f1beb1194..38ff8c5121f134f2a8b6c797bd10e087af182865 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='block'>
   <name>Swap</name>
   <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
   <source>
index cd4d3f7f03c79eee305f4de1de04c998161bf8f7..46a607acb68e777d7d4c149ed1c2f34ffc6b6cba 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='block'>
   <name>Swap</name>
   <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
   <source>
index 6990bb59030fdabf08cddb6062bc3f64911d319a..d810fff3eef080d47b1b3b2edcab4ea3647d21b5 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='block'>
   <name>sda1</name>
   <key>/dev/sda1</key>
   <source>
index 49e221ca5547c5ce4890eaee6fd35f1ee6ffe27e..d6e920bb8101c07d0c4ccb1c9e7709b51bb61903 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='network'>
   <name>test2</name>
   <source>
   </source>
index 8d2fb576242d816c8786ac36d195c2007bf33b06..cd33bee523ea381df6cc9cdac726b9da3a360448 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>sparse.img</name>
   <key>/var/lib/libvirt/images/sparse.img</key>
   <source>
index 7022b0287eb1db7b83bb387a41b5b17aff32bfe5..e515502af163ac68eae6be58ec249a36016b6266 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>&lt;sparse&gt;.img</name>
   <source>
   </source>
index b97dd5040140ce8db378c71988c7b900f9b01011..2923188e656c17e61e21c47df37ab09c8c1e0f2c 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>sparse.img</name>
   <source>
   </source>
index bf34b086782f61ab1acfbbbf8f7c05b0654d1658..07fe27767d0f86b57900d0b8713592af1a37dd73 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='block'>
   <name>Swap</name>
   <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
   <source>
index e9b4e4baf4a5fa98598c649de81e1a516fba4dd1..0df5cc0864848418ceca9a1978857a91a3963c5b 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='block'>
   <name>Swap</name>
   <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
   <source>
index 9be1cf175b22fe27c1bb38e99bc98996d0662cf1..147899edb1e160a3c13dab7c6ef66c9629b78306 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='block'>
   <name>sda1</name>
   <key>/dev/sda1</key>
   <source>
index fd3d6069e0b244f8639e02c5fde85cc35ff6e808..1f799dae0106ba1d593b1832bb886af2d5ab565c 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>OtherDemo.img</name>
   <key>/var/lib/libvirt/images/OtherDemo.img</key>
   <source>
index 99fb5acafbf0feae01e4597907d4165c39839959..14f805ff2a5a9e7148b0e951f87b6ef7a4817f5d 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>OtherDemo.img</name>
   <key>/var/lib/libvirt/images/OtherDemo.img</key>
   <source>
index 3708ea742bfde58527e135cadfd9785445d704dc..68a9756d4fb444a13cb5b6c4dd043589b4608644 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>OtherDemo.img</name>
   <key>/var/lib/libvirt/images/OtherDemo.img</key>
   <source>
index f6a2e2183da93c7d45faf538af8e3ac0623cf6fa..075dc6996b85889cc7d98e57626aedc26fadc7d4 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>OtherDemo.img</name>
   <key>/var/lib/libvirt/images/OtherDemo.img</key>
   <source>
index b9adcb4e205f035367bad8b632ee620a5a76708a..31dc57873c9dfa062a6c160d6122073a61fa53e6 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='file'>
   <name>OtherDemo.img</name>
   <key>/var/lib/libvirt/images/OtherDemo.img</key>
   <source>
index bd5d6d8f06bc6951905d503eb3b8eeb0d6e05efc..e08e36c1cac30f41817d55ad3580a88c41931ea6 100644 (file)
@@ -1,4 +1,4 @@
-<volume>
+<volume type='network'>
   <name>test2</name>
   <source>
   </source>