]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: cmdBlockcopy: Use virXMLFormatElement
authorPeter Krempa <pkrempa@redhat.com>
Mon, 28 Feb 2022 13:48:37 +0000 (14:48 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 3 Mar 2022 10:06:56 +0000 (11:06 +0100)
Rewrite the formatting of the block copy target xml using
virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index 9b1b14cdc2f57c74353709bbae6e7db9f8088a64..6f0c06343832b0444a5927c0f7cabb71bdc6a105 100644 (file)
@@ -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);
         }