[libvirt PATCH v2 2/5] conf: refactor virDomainResourceDefParse

Pavel Hrdina phrdina at redhat.com
Thu Aug 5 13:56:06 UTC 2021


There is no need to error out for empty <partition></partition> element
as we can just simply ignore it. This allows to simplify the function
and prepare it for new sub-elements of <resource>.

It makes the <partition> element optional so we need to reflect the
change in schema as well.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 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 @@
 
   <define name="respartition">
     <element name="resource">
-      <element name="partition">
-        <ref name="absFilePath"/>
-      </element>
+      <optional>
+        <element name="partition">
+          <ref name="absFilePath"/>
+        </element>
+      </optional>
     </element>
   </define>
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 09da4ab952..de38dd7110 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17292,23 +17292,19 @@ virDomainResourceDefParse(xmlNodePtr node,
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     virDomainResourceDef *def = NULL;
+    char *partition = NULL;
 
     ctxt->node = node;
 
+    partition = virXPathString("string(./partition)", ctxt);
+
+    if (!partition)
+        return NULL;
+
     def = g_new0(virDomainResourceDef, 1);
-
-    /* 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;
-    }
+    def->partition = partition;
 
     return def;
-
- error:
-    virDomainResourceDefFree(def);
-    return NULL;
 }
 
 
-- 
2.31.1




More information about the libvir-list mailing list