[PATCH 01/23] virsh: cmdBlockcopy: Use virXMLFormatElement

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

 



Rewrite the formatting of the block copy target xml using
virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tools/virsh-domain.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 9b1b14cdc2..6f0c063438 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2475,14 +2475,20 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)

         if (!xmlstr) {
             g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-            virBufferAsprintf(&buf, "<disk type='%s'>\n",
-                              blockdev ? "block" : "file");
-            virBufferAdjustIndent(&buf, 2);
-            virBufferAsprintf(&buf, "<source %s", blockdev ? "dev" : "file");
-            virBufferEscapeString(&buf, "='%s'/>\n", dest);
+            g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+            g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+
+            if (blockdev) {
+                virBufferAddLit(&attrBuf, " type='block'");
+                virBufferAddLit(&childBuf, "<source dev=");
+            } else {
+                virBufferAddLit(&buf, " type='file'");
+                virBufferAddLit(&childBuf, "<source file=");
+            }
+
+            virBufferEscapeString(&buf, "'%s'/>\n", dest);
             virBufferEscapeString(&buf, "<driver type='%s'/>\n", format);
-            virBufferAdjustIndent(&buf, -2);
-            virBufferAddLit(&buf, "</disk>\n");
+            virXMLFormatElement(&buf, "disk", &attrBuf, &childBuf);
             xmlstr = virBufferContentAndReset(&buf);
         }

-- 
2.35.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