Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx> --- src/conf/domain_conf.c | 108 ++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 60 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 69f25c30a8..22700c3064 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10178,7 +10178,8 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, { VIR_XPATH_NODE_AUTORESTORE(ctxt) virDomainFSDef *def; - xmlNodePtr cur; + xmlNodePtr driver_node = NULL; + xmlNodePtr source_node = NULL; g_autofree char *type = NULL; g_autofree char *fsdriver = NULL; g_autofree char *source = NULL; @@ -10271,57 +10272,62 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, 1, ULLONG_MAX, false) < 0) goto error; - cur = node->children; - while (cur != NULL) { - if (cur->type == XML_ELEMENT_NODE) { - if (!source && - virXMLNodeNameEqual(cur, "source")) { - - if (def->type == VIR_DOMAIN_FS_TYPE_MOUNT || - def->type == VIR_DOMAIN_FS_TYPE_BIND) { - source = virXMLPropString(cur, "dir"); - } else if (def->type == VIR_DOMAIN_FS_TYPE_FILE) { - source = virXMLPropString(cur, "file"); - } else if (def->type == VIR_DOMAIN_FS_TYPE_BLOCK) { - source = virXMLPropString(cur, "dev"); - } else if (def->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) { - source = virXMLPropString(cur, "name"); - } else if (def->type == VIR_DOMAIN_FS_TYPE_RAM) { - usage = virXMLPropString(cur, "usage"); - units = virXMLPropString(cur, "units"); - } else if (def->type == VIR_DOMAIN_FS_TYPE_VOLUME) { - def->src->type = VIR_STORAGE_TYPE_VOLUME; - if (virDomainDiskSourcePoolDefParse(cur, &def->src->srcpool) < 0) - goto error; - } - } else if (!target && - virXMLNodeNameEqual(cur, "target")) { - target = virXMLPropString(cur, "dir"); - } else if (virXMLNodeNameEqual(cur, "readonly")) { - def->readonly = true; - } else if (virXMLNodeNameEqual(cur, "driver")) { - if (!fsdriver) - fsdriver = virXMLPropString(cur, "type"); - if (!wrpolicy) - wrpolicy = virXMLPropString(cur, "wrpolicy"); - if (!format) - format = virXMLPropString(cur, "format"); - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - goto error; - } + if ((source_node = virXPathNode("./source", ctxt))) { + if (def->type == VIR_DOMAIN_FS_TYPE_MOUNT || + def->type == VIR_DOMAIN_FS_TYPE_BIND) { + source = virXPathString("string(./source/@dir)", ctxt); + } else if (def->type == VIR_DOMAIN_FS_TYPE_FILE) { + source = virXPathString("string(./source/@file)", ctxt); + } else if (def->type == VIR_DOMAIN_FS_TYPE_BLOCK) { + source = virXPathString("string(./source/@dev)", ctxt); + } else if (def->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) { + source = virXPathString("string(./source/@name)", ctxt); + } else if (def->type == VIR_DOMAIN_FS_TYPE_RAM) { + usage = virXPathString("string(./source/@usage)", ctxt); + units = virXPathString("string(./source/@units)", ctxt); + } else if (def->type == VIR_DOMAIN_FS_TYPE_VOLUME) { + def->src->type = VIR_STORAGE_TYPE_VOLUME; + if (virDomainDiskSourcePoolDefParse(source_node, &def->src->srcpool) < 0) + goto error; } - cur = cur->next; } - if (fsdriver) { - if ((def->fsdriver = virDomainFSDriverTypeFromString(fsdriver)) <= 0) { + target = virXPathString("string(./target/@dir)", ctxt); + + if (virXPathNode("./readonly", ctxt)) + def->readonly = true; + + if ((driver_node = virXPathNode("./driver", ctxt))) { + if (virDomainVirtioOptionsParseXML(driver_node, &def->virtio) < 0) + goto error; + + if ((fsdriver = virXPathString("string(./driver/@type)", ctxt)) && + ((def->fsdriver = virDomainFSDriverTypeFromString(fsdriver)) <= 0)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown fs driver type '%s'"), fsdriver); goto error; } + + if ((wrpolicy = virXPathString("string(./driver/@wrpolicy)", ctxt))) { + if ((def->wrpolicy = virDomainFSWrpolicyTypeFromString(wrpolicy)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown filesystem write policy '%s'"), wrpolicy); + goto error; + } + } else { + def->wrpolicy = VIR_DOMAIN_FS_WRPOLICY_DEFAULT; + } + + if ((format = virXPathString("string(./driver/@format)", ctxt)) && + ((def->format = virStorageFileFormatTypeFromString(format)) <= 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown driver format value '%s'"), format); + goto error; + } } + if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) { g_autofree char *queue_size = virXPathString("string(./driver/@queue)", ctxt); g_autofree char *binary = virXPathString("string(./binary/@path)", ctxt); @@ -10379,24 +10385,6 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, } } - if (format) { - if ((def->format = virStorageFileFormatTypeFromString(format)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown driver format value '%s'"), format); - goto error; - } - } - - if (wrpolicy) { - if ((def->wrpolicy = virDomainFSWrpolicyTypeFromString(wrpolicy)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown filesystem write policy '%s'"), wrpolicy); - goto error; - } - } else { - def->wrpolicy = VIR_DOMAIN_FS_WRPOLICY_DEFAULT; - } - if (source == NULL && def->type != VIR_DOMAIN_FS_TYPE_RAM && def->type != VIR_DOMAIN_FS_TYPE_VOLUME) { virReportError(VIR_ERR_NO_SOURCE, -- 2.30.2