]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: caps: Modernize virCapabilitiesFormatCaches
authorPeter Krempa <pkrempa@redhat.com>
Fri, 25 Oct 2019 14:16:41 +0000 (16:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Nov 2019 13:37:59 +0000 (14:37 +0100)
Use automatic memory freeing and use virXMLFormatElement instead of open
coding it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/capabilities.c

index 0a0de447b53b5606e29d11d192b39c77e165191e..1ab389bc65ac7ba6600f1085e7f762e7c620cbda 100644 (file)
@@ -938,7 +938,6 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
 {
     size_t i = 0;
     size_t j = 0;
-    virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
 
     if (!cache->nbanks)
         return 0;
@@ -947,6 +946,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
     virBufferAdjustIndent(buf, 2);
 
     for (i = 0; i < cache->nbanks; i++) {
+        g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+        g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER;
         virCapsHostCacheBankPtr bank = cache->banks[i];
         g_autofree char *cpus_str = virBitmapFormat(bank->cpus);
         const char *unit = NULL;
@@ -959,8 +960,8 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
          * Let's just *hope* the size is aligned to KiBs so that it does not
          * bite is back in the future
          */
-        virBufferAsprintf(buf,
-                          "<bank id='%u' level='%u' type='%s' "
+        virBufferAsprintf(&attrBuf,
+                          " id='%u' level='%u' type='%s' "
                           "size='%llu' unit='%s' cpus='%s'",
                           bank->id, bank->level,
                           virCacheTypeToString(bank->type),
@@ -1006,13 +1007,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
                               controls->max_allocation);
         }
 
-        if (virBufferUse(&childrenBuf)) {
-            virBufferAddLit(buf, ">\n");
-            virBufferAddBuffer(buf, &childrenBuf);
-            virBufferAddLit(buf, "</bank>\n");
-        } else {
-            virBufferAddLit(buf, "/>\n");
-        }
+        virXMLFormatElement(buf, "bank", &attrBuf, &childrenBuf);
     }
 
     if (virCapabilitiesFormatResctrlMonitor(buf, cache->monitor) < 0)