Add VIR_VOL_XML_PARSE_NO_CAPACITY flag to the volume XML
parser. When set, it allows the capacity element to be omitted.
---
src/conf/storage_conf.c | 12 ++++++------
src/conf/storage_conf.h | 4 ++++
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 00cea64..ca8fc9b 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 2162426..cd3d09c 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,
--
2.0.5