yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qemu-img-Add-C-option-for-convert-with-copy-offloadi.patch

26ba25
From 06e8357157c82b57f86ea04ba2d782ddee0e09df Mon Sep 17 00:00:00 2001
26ba25
From: John Snow <jsnow@redhat.com>
26ba25
Date: Thu, 17 Jan 2019 19:11:10 +0000
26ba25
Subject: [PATCH 13/14] qemu-img: Add -C option for convert with copy
26ba25
 offloading
26ba25
26ba25
RH-Author: John Snow <jsnow@redhat.com>
26ba25
Message-id: <20190117191111.30782-2-jsnow@redhat.com>
26ba25
Patchwork-id: 84041
26ba25
O-Subject: [RHEL8/rhel qemu-kvm PATCH 1/2] qemu-img: Add -C option for convert with copy offloading
26ba25
Bugzilla: 1623082
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
26ba25
26ba25
From: Fam Zheng <famz@redhat.com>
26ba25
26ba25
Signed-off-by: Fam Zheng <famz@redhat.com>
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit e11ce12f5eb26438419e486a3ae2c9bb58a23c1f)
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
26ba25
Conflicts:
26ba25
  qemu-img-cmds.hx
26ba25
  qemu-img.c
26ba25
  qemu-img.texi
26ba25
26ba25
  All relating to downstream addition of -s
26ba25
  argument not present when -C was added.
26ba25
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 qemu-img-cmds.hx |  2 +-
26ba25
 qemu-img.c       | 21 +++++++++++++++++----
26ba25
 qemu-img.texi    |  8 +++++++-
26ba25
 3 files changed, 25 insertions(+), 6 deletions(-)
26ba25
26ba25
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
26ba25
index 2fe3189..48815c0 100644
26ba25
--- a/qemu-img-cmds.hx
26ba25
+++ b/qemu-img-cmds.hx
26ba25
@@ -41,7 +41,7 @@ STEXI
26ba25
 ETEXI
26ba25
 
26ba25
 DEF("convert", img_convert,
26ba25
-    "convert [--object objectdef] [--image-opts] [--target-image-opts] [-U] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename")
26ba25
+    "convert [--object objectdef] [--image-opts] [--target-image-opts] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename")
26ba25
 STEXI
26ba25
 @item convert [--object @var{objectdef}] [--image-opts] [--target-image-opts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename}
26ba25
 ETEXI
26ba25
diff --git a/qemu-img.c b/qemu-img.c
26ba25
index b9bd401..f42750a 100644
26ba25
--- a/qemu-img.c
26ba25
+++ b/qemu-img.c
26ba25
@@ -2000,11 +2000,12 @@ static int img_convert(int argc, char **argv)
26ba25
          skip_create = false, progress = false, tgt_image_opts = false;
26ba25
     int64_t ret = -EINVAL;
26ba25
     bool force_share = false;
26ba25
+    bool explict_min_sparse = false;
26ba25
 
26ba25
     ImgConvertState s = (ImgConvertState) {
26ba25
         /* Need at least 4k of zeros for sparse detection */
26ba25
         .min_sparse         = 8,
26ba25
-        .copy_range         = true,
26ba25
+        .copy_range         = false,
26ba25
         .buf_sectors        = IO_BUF_SIZE / BDRV_SECTOR_SIZE,
26ba25
         .wr_in_order        = true,
26ba25
         .num_coroutines     = 8,
26ba25
@@ -2019,7 +2020,7 @@ static int img_convert(int argc, char **argv)
26ba25
             {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS},
26ba25
             {0, 0, 0, 0}
26ba25
         };
26ba25
-        c = getopt_long(argc, argv, ":hf:O:B:co:s:l:S:pt:T:qnm:WU",
26ba25
+        c = getopt_long(argc, argv, ":hf:O:B:Cco:s:l:S:pt:T:qnm:WU",
26ba25
                         long_options, NULL);
26ba25
         if (c == -1) {
26ba25
             break;
26ba25
@@ -2043,9 +2044,11 @@ static int img_convert(int argc, char **argv)
26ba25
         case 'B':
26ba25
             out_baseimg = optarg;
26ba25
             break;
26ba25
+        case 'C':
26ba25
+            s.copy_range = true;
26ba25
+            break;
26ba25
         case 'c':
26ba25
             s.compressed = true;
26ba25
-            s.copy_range = false;
26ba25
             break;
26ba25
         case 'o':
26ba25
             if (!is_valid_option_list(optarg)) {
26ba25
@@ -2087,7 +2090,7 @@ static int img_convert(int argc, char **argv)
26ba25
             }
26ba25
 
26ba25
             s.min_sparse = sval / BDRV_SECTOR_SIZE;
26ba25
-            s.copy_range = false;
26ba25
+            explict_min_sparse = true;
26ba25
             break;
26ba25
         }
26ba25
         case 'p':
26ba25
@@ -2152,6 +2155,16 @@ static int img_convert(int argc, char **argv)
26ba25
         goto fail_getopt;
26ba25
     }
26ba25
 
26ba25
+    if (s.compressed && s.copy_range) {
26ba25
+        error_report("Cannot enable copy offloading when -c is used");
26ba25
+        goto fail_getopt;
26ba25
+    }
26ba25
+
26ba25
+    if (explict_min_sparse && s.copy_range) {
26ba25
+        error_report("Cannot enable copy offloading when -S is used");
26ba25
+        goto fail_getopt;
26ba25
+    }
26ba25
+
26ba25
     if (tgt_image_opts && !skip_create) {
26ba25
         error_report("--target-image-opts requires use of -n flag");
26ba25
         goto fail_getopt;
26ba25
diff --git a/qemu-img.texi b/qemu-img.texi
26ba25
index 8a26400..74d7290 100644
26ba25
--- a/qemu-img.texi
26ba25
+++ b/qemu-img.texi
26ba25
@@ -172,6 +172,12 @@ Number of parallel coroutines for the convert process
26ba25
 Allow out-of-order writes to the destination. This option improves performance,
26ba25
 but is only recommended for preallocated devices like host devices or other
26ba25
 raw block devices.
26ba25
+@item -C
26ba25
+Try to use copy offloading to move data from source image to target. This may
26ba25
+improve performance if the data is remote, such as with NFS or iSCSI backends,
26ba25
+but will not automatically sparsify zero sectors, and may result in a fully
26ba25
+allocated target image depending on the host support for getting allocation
26ba25
+information.
26ba25
 @end table
26ba25
 
26ba25
 Parameters to dd subcommand:
26ba25
@@ -340,7 +346,7 @@ Error on reading data
26ba25
 
26ba25
 @end table
26ba25
 
26ba25
-@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-m @var{num_coroutines}] [-W] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
26ba25
+@item convert [-C] [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-m @var{num_coroutines}] [-W] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
26ba25
 
26ba25
 Convert the disk image @var{filename} or a snapshot @var{snapshot_param}(@var{snapshot_id_or_name} is deprecated)
26ba25
 to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c}
26ba25
-- 
26ba25
1.8.3.1
26ba25