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

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



Signed-off-by: Martin Kletzander <mkletzan redhat com>
---
 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


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