[PATCH 5/7] virsh: Add support for 'VIR_DOMAIN_BLOCK_COPY_TARGET_ZEROED' as '--dest-is-zero'

Peter Krempa via Devel posted 7 patches 5 days, 6 hours ago
[PATCH 5/7] virsh: Add support for 'VIR_DOMAIN_BLOCK_COPY_TARGET_ZEROED' as '--dest-is-zero'
Posted by Peter Krempa via Devel 5 days, 6 hours ago
From: Peter Krempa <pkrempa@redhat.com>

Add the aforementioned flag for 'virsh blockcopy'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 docs/manpages/virsh.rst | 6 +++++-
 tools/virsh-domain.c    | 9 ++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 591c47a7ce..da9e9f8658 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -1472,7 +1472,7 @@ blockcopy
       [--shallow] [--reuse-external] [bandwidth]
       [--wait [--async] [--verbose]] [{--pivot | --finish}]
       [--timeout seconds] [granularity] [buf-size] [--bytes]
-      [--transient-job] [--synchronous-writes] [--print-xml]
+      [--transient-job] [--synchronous-writes] [--dest-is-zero] [--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 containing
@@ -1537,6 +1537,10 @@ to be propagated both to the original image and to the 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 running.

+If *--dest-is-zero* is specified the hypervisor may assume that the target
+image was already cleared (any offset reads 0x00 bytes) and thus may skip
+clearing it.
+
 If *--print-xml* is specified, then the XML used to start the block copy job
 is printed instead of starting the job.

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 5a2ae75379..1af7f9eb0e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2714,6 +2714,10 @@ static const vshCmdOptDef opts_blockcopy[] = {
      .type = VSH_OT_BOOL,
      .help = N_("print the XML used to start the copy job instead of starting the job")
     },
+    {.name = "dest-is-zero",
+     .type = VSH_OT_BOOL,
+     .help = N_("the destination image is already zeroed; hypervisor may skip pre-zeroing")
+    },
     {.name = NULL}
 };

@@ -2737,6 +2741,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
     bool bytes = vshCommandOptBool(cmd, "bytes");
     bool transientjob = vshCommandOptBool(cmd, "transient-job");
     bool syncWrites = vshCommandOptBool(cmd, "synchronous-writes");
+    bool destIsZero = vshCommandOptBool(cmd, "dest-is-zero");
     int timeout = 0;
     const char *path = NULL;
     int abort_flags = 0;
@@ -2773,6 +2778,8 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_BLOCK_COPY_SYNCHRONOUS_WRITES;
     if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
         return false;
+    if (destIsZero)
+        flags |= VIR_DOMAIN_BLOCK_COPY_TARGET_ZEROED;

     if (timeout)
         blocking = true;
@@ -2818,7 +2825,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
     }

     if (granularity || buf_size || (format && STRNEQ(format, "raw")) || xml ||
-        transientjob || syncWrites || print_xml) {
+        transientjob || syncWrites || destIsZero || print_xml) {
         /* New API */
         if (bandwidth || granularity || buf_size) {
             params = g_new0(virTypedParameter, 3);
-- 
2.53.0