]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: refactor virDomainResourceDefParse
authorPavel Hrdina <phrdina@redhat.com>
Thu, 5 Aug 2021 13:27:17 +0000 (15:27 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 17 Aug 2021 10:35:45 +0000 (12:35 +0200)
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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
docs/schemas/domaincommon.rng
src/conf/domain_conf.c

index 24420789696fdb6cbfe12a84f526a67402e10f49..9b669d9de5f5e8c0499a33d064da2cc9893e715d 100644 (file)
 
   <define name="respartition">
     <element name="resource">
-      <element name="partition">
-        <ref name="absFilePath"/>
-      </element>
+      <optional>
+        <element name="partition">
+          <ref name="absFilePath"/>
+        </element>
+      </optional>
     </element>
   </define>
 
index e9bdbbfd7426175ad98a217040fd1049d1dc9c1e..7dff6c8beb19fd058c5620815e15cb5648d3efaf 100644 (file)
@@ -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;
 }