From: Ján Tomko Date: Tue, 17 Feb 2015 15:47:04 +0000 (+0100) Subject: Allow parsing volumes without specifying the capacity X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2bd47d9c64b4d3d9606161453b9a821d0192174e;p=libvirt.git Allow parsing volumes without specifying the capacity Add VIR_VOL_XML_PARSE_NO_CAPACITY flag to the volume XML parser. When set, it allows the capacity element to be omitted. --- diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index b522a4d5e4..f4e68a7338 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1260,7 +1260,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, size_t i; int n; - virCheckFlags(0, NULL); + virCheckFlags(VIR_VOL_XML_PARSE_NO_CAPACITY, NULL); options = virStorageVolOptionsForPoolType(pool->type); if (options == NULL) @@ -1322,13 +1322,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, capacity = virXPathString("string(./capacity)", ctxt); unit = virXPathString("string(./capacity/@unit)", ctxt); - if (capacity == NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing capacity element")); + if (capacity) { + if (virStorageSize(unit, capacity, &ret->target.capacity) < 0) + goto error; + } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY)) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element")); goto error; } - if (virStorageSize(unit, capacity, &ret->target.capacity) < 0) - goto error; VIR_FREE(unit); allocation = virXPathString("string(./allocation)", ctxt); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 09cf77b292..c28e2dd37b 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -345,6 +345,10 @@ virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml, xmlNodePtr root); char *virStoragePoolDefFormat(virStoragePoolDefPtr def); +typedef enum { + /* do not require volume capacity at all */ + VIR_VOL_XML_PARSE_NO_CAPACITY = 1 << 0, +} virStorageVolDefParseFlags; virStorageVolDefPtr virStorageVolDefParseString(virStoragePoolDefPtr pool, const char *xml,