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; size_t i;
int n; int n;
virCheckFlags(0, NULL); virCheckFlags(VIR_VOL_XML_PARSE_NO_CAPACITY, NULL);
options = virStorageVolOptionsForPoolType(pool->type); options = virStorageVolOptionsForPoolType(pool->type);
if (options == NULL) if (options == NULL)
@ -1322,13 +1322,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
capacity = virXPathString("string(./capacity)", ctxt); capacity = virXPathString("string(./capacity)", ctxt);
unit = virXPathString("string(./capacity/@unit)", ctxt); unit = virXPathString("string(./capacity/@unit)", ctxt);
if (capacity == NULL) { if (capacity) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing capacity element"));
goto error;
}
if (virStorageSize(unit, capacity, &ret->target.capacity) < 0) if (virStorageSize(unit, capacity, &ret->target.capacity) < 0)
goto error; 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); VIR_FREE(unit);
allocation = virXPathString("string(./allocation)", ctxt); allocation = virXPathString("string(./allocation)", ctxt);

View File

@ -345,6 +345,10 @@ virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml,
xmlNodePtr root); xmlNodePtr root);
char *virStoragePoolDefFormat(virStoragePoolDefPtr def); char *virStoragePoolDefFormat(virStoragePoolDefPtr def);
typedef enum {
/* do not require volume capacity at all */
VIR_VOL_XML_PARSE_NO_CAPACITY = 1 << 0,
} virStorageVolDefParseFlags;
virStorageVolDefPtr virStorageVolDefPtr
virStorageVolDefParseString(virStoragePoolDefPtr pool, virStorageVolDefParseString(virStoragePoolDefPtr pool,
const char *xml, const char *xml,