From 77b53057c7f8e9a147e748bce2ed867d298f881f Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Thu, 5 Aug 2021 15:27:17 +0200 Subject: [PATCH] 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 --- docs/schemas/domaincommon.rng | 8 +++++--- src/conf/domain_conf.c | 18 +++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) 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; } -- 2.47.2