
On 11/25/2013 11:56 AM, Eric Blake wrote:
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> ---
v1: https://www.redhat.com/archives/libvir-list/2013-November/msg00955.html Since then, delay 'network-dir' until later in gluster series, change XML to <volume type='file'> instead of <volume><type>file</type>, and use 1.2.0 instead of 1.1.5
docs/formatstorage.html.in | 10 +++++++--- docs/schemas/storagevol.rng | 10 ++++++++++ src/conf/storage_conf.c | 19 ++++++++++++++++++- src/conf/storage_conf.h | 1 + tests/storagevolxml2xmlin/vol-logical-backing.xml | 2 +- tests/storagevolxml2xmlin/vol-logical.xml | 2 +- tests/storagevolxml2xmlin/vol-partition.xml | 2 +- tests/storagevolxml2xmlin/vol-sheepdog.xml | 2 +- tests/storagevolxml2xmlout/vol-file-backing.xml | 2 +- tests/storagevolxml2xmlout/vol-file-naming.xml | 2 +- tests/storagevolxml2xmlout/vol-file.xml | 2 +- tests/storagevolxml2xmlout/vol-logical-backing.xml | 2 +- tests/storagevolxml2xmlout/vol-logical.xml | 2 +- tests/storagevolxml2xmlout/vol-partition.xml | 2 +- tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml | 2 +- tests/storagevolxml2xmlout/vol-qcow2-1.1.xml | 2 +- tests/storagevolxml2xmlout/vol-qcow2-lazy.xml | 2 +- tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml | 2 +- tests/storagevolxml2xmlout/vol-qcow2.xml | 2 +- tests/storagevolxml2xmlout/vol-sheepdog.xml | 2 +- 20 files changed, 52 insertions(+), 20 deletions(-)
You and Peter seem to be touching the same code in storage_conf.c: https://www.redhat.com/archives/libvir-list/2013-November/msg01030.html Although added virStorageVol was added in a different location... That'll make the 3 way merge interesting... Also, he seems to have also touched libvirt_private.syms too... John <...snip...>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 8b378c2..0cd80c3 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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"); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index f062bd8..c4dd403 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -116,6 +116,7 @@ struct _virStorageVolDefList { virStorageVolDefPtr *objs; };
+VIR_ENUM_DECL(virStorageVol)
enum virStoragePoolType { VIR_STORAGE_POOL_DIR, /* Local directory */
<...snip...>