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.
This commit is contained in:
Ján Tomko 2015-02-17 16:47:04 +01:00
parent 21f58a5854
commit 2bd47d9c64
2 changed files with 10 additions and 6 deletions

View 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"));
goto error;
}
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;
}
VIR_FREE(unit);
allocation = virXPathString("string(./allocation)", ctxt);

View 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,