]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: refactor virDomainResourceDefFormat
authorPavel Hrdina <phrdina@redhat.com>
Thu, 5 Aug 2021 13:29:45 +0000 (15:29 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 17 Aug 2021 10:35:45 +0000 (12:35 +0200)
Prepare the function for additional sub-elements where all of the
sub-elements are optional.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_conf.c

index 7dff6c8beb19fd058c5620815e15cb5648d3efaf..571650bfd3aa080516e8b342fe609f1c084d78d4 100644 (file)
@@ -26761,11 +26761,15 @@ static void
 virDomainResourceDefFormat(virBuffer *buf,
                            virDomainResourceDef *def)
 {
-    virBufferAddLit(buf, "<resource>\n");
-    virBufferAdjustIndent(buf, 2);
-    virBufferEscapeString(buf, "<partition>%s</partition>\n", def->partition);
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</resource>\n");
+    g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+
+    if (!def)
+        return;
+
+    if (def->partition)
+        virBufferEscapeString(&childBuf, "<partition>%s</partition>\n", def->partition);
+
+    virXMLFormatElement(buf, "resource", NULL, &childBuf);
 }
 
 
@@ -27918,8 +27922,7 @@ virDomainDefFormatInternalSetRootName(virDomainDef *def,
     if (virDomainNumatuneFormatXML(buf, def->numa) < 0)
         return -1;
 
-    if (def->resource)
-        virDomainResourceDefFormat(buf, def->resource);
+    virDomainResourceDefFormat(buf, def->resource);
 
     for (i = 0; i < def->nsysinfo; i++) {
         if (virSysinfoFormat(buf, def->sysinfo[i]) < 0)