[libvirt PATCH v2 3/5] conf: refactor virDomainResourceDefFormat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Prepare the function for additional sub-elements where all of the
sub-elements are optional.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index de38dd7110..d33d708189 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -26794,11 +26794,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);
 }
 
 
@@ -27951,8 +27955,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)
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux