mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
storage: expose volume meta-type in XML
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>
This commit is contained in:
parent
4d52b465bd
commit
1b5c8d4cbc
@ -283,14 +283,18 @@
|
||||
|
||||
<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>
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>sparse.img</name>
|
||||
<key>/var/lib/xen/images/sparse.img</key>
|
||||
<allocation>0</allocation>
|
||||
|
@ -13,6 +13,16 @@
|
||||
|
||||
<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'/>
|
||||
|
@ -51,6 +51,10 @@
|
||||
#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");
|
||||
|
@ -116,6 +116,7 @@ struct _virStorageVolDefList {
|
||||
virStorageVolDefPtr *objs;
|
||||
};
|
||||
|
||||
VIR_ENUM_DECL(virStorageVol)
|
||||
|
||||
enum virStoragePoolType {
|
||||
VIR_STORAGE_POOL_DIR, /* Local directory */
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='block'>
|
||||
<name>Swap</name>
|
||||
<key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='block'>
|
||||
<name>Swap</name>
|
||||
<key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='block'>
|
||||
<name>sda1</name>
|
||||
<key>/dev/sda1</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='network'>
|
||||
<name>test2</name>
|
||||
<source>
|
||||
</source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>sparse.img</name>
|
||||
<key>/var/lib/libvirt/images/sparse.img</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name><sparse>.img</name>
|
||||
<source>
|
||||
</source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>sparse.img</name>
|
||||
<source>
|
||||
</source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='block'>
|
||||
<name>Swap</name>
|
||||
<key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='block'>
|
||||
<name>Swap</name>
|
||||
<key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='block'>
|
||||
<name>sda1</name>
|
||||
<key>/dev/sda1</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='file'>
|
||||
<name>OtherDemo.img</name>
|
||||
<key>/var/lib/libvirt/images/OtherDemo.img</key>
|
||||
<source>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<volume>
|
||||
<volume type='network'>
|
||||
<name>test2</name>
|
||||
<source>
|
||||
</source>
|
||||
|
Loading…
Reference in New Issue
Block a user