From nobody Sat May 18 18:01:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1650875860; cv=none; d=zohomail.com; s=zohoarc; b=A+1JoP9iEheHFkti6JevqzSUsw2OtGSBrRhX1eiTwG6YoU/LgeNJRhraeDu5O23ykKDUOr+b/YFjW0Heuxc3ZY/gkoRyr3UG5S0K2TzKZVbkxouRs28uwmxeAs/gggfptT/0pnuhkTODs66p66/exJ2K/a82SFUXnKz6NXR+aO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650875860; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mJ0uwjFNWZc5SUWFzqAE9ZVZMQna7tDsksnNS9lJALc=; b=I6HmcBuZSihbuyAWidcwtYZDy6u5+y7v9ZmMEY/mTwX0VhUPbPolePvW/3TuFgOpik7++XwOrfjUlBXtw8vJ2vrAXHNY6HroPUqFXnkuJeueHG0c0vPnGBHPfD8ahQl5fnclmpU7CJAjRhI/t3QC++1Zd0SCJD3Yo+wqvreu/bI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1650875860601990.2834678330948; Mon, 25 Apr 2022 01:37:40 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-54TJPuZCOaSRCH5DWMrJKg-1; Mon, 25 Apr 2022 04:37:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B748F3834C18; Mon, 25 Apr 2022 08:37:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 506CB2167D61; Mon, 25 Apr 2022 08:37:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 070C81947BBE; Mon, 25 Apr 2022 08:37:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4A3BB1947BBD for ; Mon, 25 Apr 2022 08:37:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 45F67432487; Mon, 25 Apr 2022 08:37:25 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB1F343248E for ; Mon, 25 Apr 2022 08:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650875859; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mJ0uwjFNWZc5SUWFzqAE9ZVZMQna7tDsksnNS9lJALc=; b=W0z+a3Vzubxgl3uCAR5fa7e1V+AGgn1vfOAx1YEg3em+tCobM0CqsAZk9GxjvU7rD8oHWo fqx8lQiPrnHZe5NwluSL2iWfpPabwVaawGi5qT+tOHW1zLGgb8ZwucpDpKzUSG580IP9+K ptrC/R39UAB8ltOXhbwrrFo5+3QO9ak= X-MC-Unique: 54TJPuZCOaSRCH5DWMrJKg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] virsh: cmdBlockcopy: Add '--print-xml' flag Date: Mon, 25 Apr 2022 10:37:21 +0200 Message-Id: <2d8bf9c6fdaa97dc42bf22f3d5c2899dd76c2693.1650875792.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1650875861285100003 Content-Type: text/plain; charset="utf-8" Useful for knowing how to construct the XML and debugging. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- docs/manpages/virsh.rst | 4 +++- tools/virsh-domain.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index e8568559fa..e73e590754 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1232,7 +1232,7 @@ blockcopy [--shallow] [--reuse-external] [bandwidth] [--wait [--async] [--verbose]] [{--pivot | --finish}] [--timeout seconds] [granularity] [buf-size] [--bytes] - [--transient-job] [--synchronous-writes] + [--transient-job] [--synchronous-writes] [--print-xml] Copy a disk backing image chain to a destination. Either *dest* as the destination file name, or *--xml* with the name of an XML file contain= ing @@ -1297,6 +1297,8 @@ to be propagated both to the original image and to th= e destination of the copy so that it's guaranteed that the job converges if the destination storage = is slower. This may impact performance of writes while the blockjob is runnin= g. +If *--print-xml* is specified, then the XML used to start the block copy j= ob +is printed instead of starting the job. blockjob -------- diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index df8df9c2f3..452e518156 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2332,6 +2332,10 @@ static const vshCmdOptDef opts_blockcopy[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("the copy job forces guest writes to be synchronously wr= itten to the destination") }, + {.name =3D "print-xml", + .type =3D VSH_OT_BOOL, + .help =3D N_("print the XML used to start the copy job instead of sta= rting the job") + }, {.name =3D NULL} }; @@ -2360,6 +2364,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) int abort_flags =3D 0; const char *xml =3D NULL; char *xmlstr =3D NULL; + bool print_xml =3D vshCommandOptBool(cmd, "print-xml"); virTypedParameterPtr params =3D NULL; virshBlockJobWaitData *bjWait =3D NULL; int nparams =3D 0; @@ -2437,7 +2442,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) } if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xm= l || - transientjob || syncWrites) { + transientjob || syncWrites || print_xml) { /* New API */ if (bandwidth || granularity || buf_size) { params =3D g_new0(virTypedParameter, 3); @@ -2492,6 +2497,12 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) xmlstr =3D virBufferContentAndReset(&buf); } + if (print_xml) { + vshPrint(ctl, "%s", xmlstr); + ret =3D true; + goto cleanup; + } + if (virDomainBlockCopy(dom, path, xmlstr, params, nparams, flags) = < 0) goto cleanup; } else { --=20 2.35.1 From nobody Sat May 18 18:01:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1650875883; cv=none; d=zohomail.com; s=zohoarc; b=Bt7eSkVesDS+4tgH2vv082L1+ucrwIKkKoF5Xse3jels0GbUiNUTKoCG4p9C93s4PnDn6+hFzJiNx00BUoBMZfRc3em2r5MNOl9UoNCY35kMYBnRCDLuVRcvq/o8aNKHPFE+uTqgzHa+qkmigcyVuzRg6KMa5oTz062XwIDOuGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650875883; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PYvE9brRVqogdmrDIpuNoNg0lApmYkoBmhPoHF6F6lA=; b=e2YJ8EZ6bLv2e5NcGMCpbH5wQUiGMttr/X9hpLRxmq4klX6Mz94btckP8AbjG3TBawyvCEAUqH8XbcHAU87nuOT3oyKFLmlWMlVA8+Iay5ARJtrasl7ZmJTjE6h0aUBaZaK8MPb7OkupQ7Hjydvau+mYOM4tHvZvShhrDXu/rYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1650875883612832.1915383953204; Mon, 25 Apr 2022 01:38:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-77-HYebgDFbMjKQw6vcLqCl-A-1; Mon, 25 Apr 2022 04:37:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11E2B85A5BE; Mon, 25 Apr 2022 08:37:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0EB32167D61; Mon, 25 Apr 2022 08:37:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4A31E194036D; Mon, 25 Apr 2022 08:37:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 907D01947BBD for ; Mon, 25 Apr 2022 08:37:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 61CEF43247C; Mon, 25 Apr 2022 08:37:26 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id B13A2432497 for ; Mon, 25 Apr 2022 08:37:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650875882; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PYvE9brRVqogdmrDIpuNoNg0lApmYkoBmhPoHF6F6lA=; b=d5JxYJai7ej1e1Vm5scJTBAkPuAh/Us42RxIn65sCRGWoDGJGlWzR16VpR3pWow3/U3Csx NEgJK+drJmXoh8z4zJ7qqe+8//CVmhUH/M6erM46X8NDAqyivYHijUackFR0+q3Wm9IqAQ AIxfKXOJ9R7giIoYLXdhgSP80NRNW3I= X-MC-Unique: HYebgDFbMjKQw6vcLqCl-A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/2] virsh: cmdBlockcopy: Fix generator of block copy disk XML Date: Mon, 25 Apr 2022 10:37:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1650875885424100001 Content-Type: text/plain; charset="utf-8" In a recent commit I've attempted to rewrite the XML generator to use virXMLFormatElement instead of manual steps. Unfortunately the commit had multiple problems resulting in a garbled XML: 1) in certain cases the wrong buffer was used resulting in misplaced snippets 2) the child element buffer was improperly set up so sub-elements were not indented This resulted in following XML being generated: $ virsh blockcopy cd vda /tmp/test.copy --raw --print-xml type=3D'file''/tmp/test.copy'/> To fix this we'll generate the '' element in one go and use the proper buffer for it and other places. Fixes: 1cd95f858ab83f2baab0e35070d00766bb06ce3a Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2078274 Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 452e518156..ba492e807e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2481,18 +2481,17 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) if (!xmlstr) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(&buf); if (blockdev) { virBufferAddLit(&attrBuf, " type=3D'block'"); - virBufferAddLit(&childBuf, "\n",= dest); } else { - virBufferAddLit(&buf, " type=3D'file'"); - virBufferAddLit(&childBuf, "\n"= , dest); } - virBufferEscapeString(&buf, "'%s'/>\n", dest); - virBufferEscapeString(&buf, "\n", format); + virBufferEscapeString(&childBuf, "\n", fo= rmat); virXMLFormatElement(&buf, "disk", &attrBuf, &childBuf); xmlstr =3D virBufferContentAndReset(&buf); } --=20 2.35.1