]> xenbits.xensource.com Git - libvirt.git/commitdiff
Allow parsing volumes without specifying the capacity
authorJán Tomko <jtomko@redhat.com>
Tue, 17 Feb 2015 15:47:04 +0000 (16:47 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 2 Mar 2015 07:07:11 +0000 (08:07 +0100)
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
src/conf/storage_conf.h

index b522a4d5e40d95b5589a8f04f96e08773db6392f..f4e68a7338fe4751c626c4e5eda6604db0b3fd85 100644 (file)
@@ -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);
index 09cf77b29297833c30a73ce28cab56675e9d44d1..c28e2dd37bef6995d51d1bfb8ac22fb8e20f9f33 100644 (file)
@@ -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,