Use XPath when parsing snapshot disk definition

Instead of going through XML nodes in a loop and
having to check if they are duplicate.
This commit is contained in:
Ján Tomko 2015-04-10 11:55:43 +02:00
parent 9b90899915
commit c59304e7e8

View File

@ -113,7 +113,11 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
int ret = -1; int ret = -1;
char *snapshot = NULL; char *snapshot = NULL;
char *type = NULL; char *type = NULL;
char *driver = NULL;
xmlNodePtr cur; xmlNodePtr cur;
xmlNodePtr saved = ctxt->node;
ctxt->node = node;
if (VIR_ALLOC(def->src) < 0) if (VIR_ALLOC(def->src) < 0)
goto cleanup; goto cleanup;
@ -148,20 +152,11 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
def->src->type = VIR_STORAGE_TYPE_FILE; def->src->type = VIR_STORAGE_TYPE_FILE;
} }
for (cur = node->children; cur; cur = cur->next) { if ((cur = virXPathNode("./source", ctxt)) &&
if (cur->type != XML_ELEMENT_NODE) virDomainDiskSourceParse(cur, ctxt, def->src) < 0)
continue;
if (!def->src->path &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
if (virDomainDiskSourceParse(cur, ctxt, def->src) < 0)
goto cleanup; goto cleanup;
} else if (!def->src->format && if ((driver = virXPathString("string(./driver/@type)", ctxt))) {
xmlStrEqual(cur->name, BAD_CAST "driver")) {
char *driver = virXMLPropString(cur, "type");
if (driver) {
def->src->format = virStorageFileFormatTypeFromString(driver); def->src->format = virStorageFileFormatTypeFromString(driver);
if (def->src->format < VIR_STORAGE_FILE_BACKING) { if (def->src->format < VIR_STORAGE_FILE_BACKING) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -170,12 +165,8 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
: _("disk format '%s' lacks backing file " : _("disk format '%s' lacks backing file "
"support"), "support"),
driver); driver);
VIR_FREE(driver);
goto cleanup; goto cleanup;
} }
VIR_FREE(driver);
}
}
} }
/* validate that the passed path is absolute */ /* validate that the passed path is absolute */
@ -193,6 +184,9 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = saved;
VIR_FREE(driver);
VIR_FREE(snapshot); VIR_FREE(snapshot);
VIR_FREE(type); VIR_FREE(type);
if (ret < 0) if (ret < 0)