Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx> --- src/conf/domain_conf.c | 88 ++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 55 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a5dce8a8af..54348c8c23 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15080,7 +15080,9 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { g_autoptr(virDomainVideoDef) def = NULL; - xmlNodePtr cur; + xmlNodePtr driver; + xmlNodePtr accel_node; + xmlNodePtr res_node; VIR_XPATH_NODE_AUTORESTORE(ctxt) g_autofree char *type = NULL; g_autofree char *driver_name = NULL; @@ -15096,62 +15098,28 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, ctxt->node = node; - cur = node->children; - while (cur != NULL) { - if (cur->type == XML_ELEMENT_NODE) { - if (!type && !vram && !ram && !heads && - virXMLNodeNameEqual(cur, "model")) { - xmlNodePtr child; - type = virXMLPropString(cur, "type"); - ram = virXMLPropString(cur, "ram"); - vram = virXMLPropString(cur, "vram"); - vram64 = virXMLPropString(cur, "vram64"); - vgamem = virXMLPropString(cur, "vgamem"); - heads = virXMLPropString(cur, "heads"); - - if ((primary = virXMLPropString(cur, "primary")) != NULL) { - ignore_value(virStringParseYesNo(primary, &def->primary)); - VIR_FREE(primary); - } + if ((primary = virXPathString("string(./model/@primary)", ctxt)) != NULL) + ignore_value(virStringParseYesNo(primary, &def->primary)); - child = cur->children; - while (child != NULL) { - if (child->type == XML_ELEMENT_NODE) { - if (def->accel == NULL && - virXMLNodeNameEqual(child, "acceleration")) { - if ((def->accel = virDomainVideoAccelDefParseXML(child)) == NULL) - return NULL; - } - if (def->res == NULL && - virXMLNodeNameEqual(child, "resolution")) { - if ((def->res = virDomainVideoResolutionDefParseXML(child)) == NULL) - return NULL; - } - } - child = child->next; - } - } - if (virXMLNodeNameEqual(cur, "driver")) { - if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) - return NULL; - driver_name = virXMLPropString(cur, "name"); - } - } - cur = cur->next; - } + if (def->accel == NULL && + (accel_node = virXPathNode("./model/acceleration", ctxt))) + if ((def->accel = virDomainVideoAccelDefParseXML(accel_node)) == NULL) + return NULL; - if (type) { - if ((def->type = virDomainVideoTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown video model '%s'"), type); + if (def->res == NULL && + (res_node = virXPathNode("./model/resolution", ctxt))) + if ((def->res = virDomainVideoResolutionDefParseXML(res_node)) == NULL) return NULL; - } - } else { - def->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT; + + if ((driver = virXPathNode("./driver", ctxt))) { + if (virDomainVirtioOptionsParseXML(driver, &def->virtio) < 0) + return NULL; + driver_name = virXPathString("string(./driver/@name)", ctxt); } if (driver_name) { int backend; + if ((backend = virDomainVideoBackendTypeFromString(driver_name)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown video driver '%s'"), driver_name); @@ -15162,7 +15130,17 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, def->backend = VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT; } - if (ram) { + if ((type = virXPathString("string(./model/@type)", ctxt))) { + if ((def->type = virDomainVideoTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown video model '%s'"), type); + return NULL; + } + } else { + def->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT; + } + + if ((ram = virXPathString("string(./model/@ram)", ctxt))) { if (virStrToLong_uip(ram, NULL, 10, &def->ram) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video ram '%s'"), ram); @@ -15170,7 +15148,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, } } - if (vram) { + if ((vram = virXPathString("string(./model/@vram)", ctxt))) { if (virStrToLong_uip(vram, NULL, 10, &def->vram) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video vram '%s'"), vram); @@ -15178,7 +15156,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, } } - if (vram64) { + if ((vram64 = virXPathString("string(./model/@vram64)", ctxt))) { if (virStrToLong_uip(vram64, NULL, 10, &def->vram64) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video vram64 '%s'"), vram64); @@ -15186,7 +15164,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, } } - if (vgamem) { + if ((vgamem = virXPathString("string(./model/@vgamem)", ctxt))) { if (virStrToLong_uip(vgamem, NULL, 10, &def->vgamem) < 0) { virReportError(VIR_ERR_XML_ERROR, _("cannot parse video vgamem '%s'"), vgamem); @@ -15194,7 +15172,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlopt, } } - if (heads) { + if ((heads = virXPathString("string(./model/@heads)", ctxt))) { if (virStrToLong_uip(heads, NULL, 10, &def->heads) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse video heads '%s'"), heads); -- 2.30.2