[PATCH 3/4] conf: Clean up and report error in virDomainCapsFormat

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

 



Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/conf/domain_capabilities.c | 68 +++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 40 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 7a81c10fd10f..35f8128e70dd 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -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);
 }
-- 
2.14.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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