From 1cd95f858ab83f2baab0e35070d00766bb06ce3a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 28 Feb 2022 14:48:37 +0100 Subject: [PATCH] virsh: cmdBlockcopy: Use virXMLFormatElement MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Rewrite the formatting of the block copy target xml using virXMLFormatElement. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- 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, "\n", - blockdev ? "block" : "file"); - virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "\n", dest); + g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + + if (blockdev) { + virBufferAddLit(&attrBuf, " type='block'"); + virBufferAddLit(&childBuf, "\n", dest); virBufferEscapeString(&buf, "\n", format); - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virXMLFormatElement(&buf, "disk", &attrBuf, &childBuf); xmlstr = virBufferContentAndReset(&buf); } -- 2.47.2