From: Pavel Hrdina Date: Thu, 5 Aug 2021 13:27:17 +0000 (+0200) Subject: conf: refactor virDomainResourceDefParse X-Git-Tag: v7.7.0-rc1~179 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77b53057c7f8e9a147e748bce2ed867d298f881f;p=thirdparty%2Flibvirt.git conf: refactor virDomainResourceDefParse There is no need to error out for empty element as we can just simply ignore it. This allows to simplify the function and prepare it for new sub-elements of . It makes the element optional so we need to reflect the change in schema as well. Signed-off-by: Pavel Hrdina Reviewed-by: Martin Kletzander --- diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 2442078969..9b669d9de5 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1172,9 +1172,11 @@ - - - + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e9bdbbfd74..7dff6c8beb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17284,23 +17284,19 @@ virDomainResourceDefParse(xmlNodePtr node, { VIR_XPATH_NODE_AUTORESTORE(ctxt) virDomainResourceDef *def = NULL; + char *partition = NULL; ctxt->node = node; - def = g_new0(virDomainResourceDef, 1); + partition = virXPathString("string(./partition)", ctxt); - /* Find out what type of virtualization to use */ - if (!(def->partition = virXPathString("string(./partition)", ctxt))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing resource partition attribute")); - goto error; - } + if (!partition) + return NULL; - return def; + def = g_new0(virDomainResourceDef, 1); + def->partition = partition; - error: - virDomainResourceDefFree(def); - return NULL; + return def; }