]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Clean up and report error in virDomainCapsFormat
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 21 Aug 2017 06:50:47 +0000 (08:50 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 29 Aug 2017 09:17:16 +0000 (11:17 +0200)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_capabilities.c

index 7a81c10fd10ff0f1461b831183c800c6d53a1bc2..35f8128e70dd0cbf47ea28ef726d018070bb0e81 100644 (file)
@@ -516,62 +516,50 @@ virDomainCapsFeatureGICFormat(virBufferPtr buf,
 }
 
 
-static int
-virDomainCapsFormatInternal(virBufferPtr buf,
-                            virDomainCapsPtr const caps)
+char *
+virDomainCapsFormat(virDomainCapsPtr const caps)
 {
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
     const char *virttype_str = virDomainVirtTypeToString(caps->virttype);
     const char *arch_str = virArchToString(caps->arch);
 
-    virBufferAddLit(buf, "<domainCapabilities>\n");
-    virBufferAdjustIndent(buf, 2);
+    virBufferAddLit(&buf, "<domainCapabilities>\n");
+    virBufferAdjustIndent(&buf, 2);
 
-    virBufferEscapeString(buf, "<path>%s</path>\n", caps->path);
-    virBufferAsprintf(buf, "<domain>%s</domain>\n", virttype_str);
+    virBufferEscapeString(&buf, "<path>%s</path>\n", caps->path);
+    virBufferAsprintf(&buf, "<domain>%s</domain>\n", virttype_str);
     if (caps->machine)
-        virBufferAsprintf(buf, "<machine>%s</machine>\n", caps->machine);
-    virBufferAsprintf(buf, "<arch>%s</arch>\n", arch_str);
+        virBufferAsprintf(&buf, "<machine>%s</machine>\n", caps->machine);
+    virBufferAsprintf(&buf, "<arch>%s</arch>\n", arch_str);
 
     if (caps->maxvcpus)
-        virBufferAsprintf(buf, "<vcpu max='%d'/>\n", caps->maxvcpus);
+        virBufferAsprintf(&buf, "<vcpu max='%d'/>\n", caps->maxvcpus);
 
-    virDomainCapsOSFormat(buf, &caps->os);
-    virDomainCapsCPUFormat(buf, &caps->cpu);
+    virDomainCapsOSFormat(&buf, &caps->os);
+    virDomainCapsCPUFormat(&buf, &caps->cpu);
 
-    virBufferAddLit(buf, "<devices>\n");
-    virBufferAdjustIndent(buf, 2);
+    virBufferAddLit(&buf, "<devices>\n");
+    virBufferAdjustIndent(&buf, 2);
 
-    virDomainCapsDeviceDiskFormat(buf, &caps->disk);
-    virDomainCapsDeviceGraphicsFormat(buf, &caps->graphics);
-    virDomainCapsDeviceVideoFormat(buf, &caps->video);
-    virDomainCapsDeviceHostdevFormat(buf, &caps->hostdev);
+    virDomainCapsDeviceDiskFormat(&buf, &caps->disk);
+    virDomainCapsDeviceGraphicsFormat(&buf, &caps->graphics);
+    virDomainCapsDeviceVideoFormat(&buf, &caps->video);
+    virDomainCapsDeviceHostdevFormat(&buf, &caps->hostdev);
 
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</devices>\n");
+    virBufferAdjustIndent(&buf, -2);
+    virBufferAddLit(&buf, "</devices>\n");
 
-    virBufferAddLit(buf, "<features>\n");
-    virBufferAdjustIndent(buf, 2);
+    virBufferAddLit(&buf, "<features>\n");
+    virBufferAdjustIndent(&buf, 2);
 
-    virDomainCapsFeatureGICFormat(buf, &caps->gic);
+    virDomainCapsFeatureGICFormat(&buf, &caps->gic);
 
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</features>\n");
+    virBufferAdjustIndent(&buf, -2);
+    virBufferAddLit(&buf, "</features>\n");
 
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</domainCapabilities>\n");
-    return 0;
-}
-
-
-char *
-virDomainCapsFormat(virDomainCapsPtr const caps)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-
-    if (virDomainCapsFormatInternal(&buf, caps) < 0) {
-        virBufferFreeAndReset(&buf);
-        return NULL;
-    }
+    virBufferAdjustIndent(&buf, -2);
+    virBufferAddLit(&buf, "</domainCapabilities>\n");
 
+    virBufferCheckError(&buf);
     return virBufferContentAndReset(&buf);
 }