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

357786
From 2d72f0886af14ab032974dd228e1c55e1501f117 Mon Sep 17 00:00:00 2001
357786
From: Fam Zheng <famz@redhat.com>
357786
Date: Wed, 1 Aug 2018 06:35:37 +0200
357786
Subject: [PATCH 01/13] qemu-img: Add -C option for convert with copy
357786
 offloading
357786
357786
RH-Author: Fam Zheng <famz@redhat.com>
357786
Message-id: <20180801063538.32582-2-famz@redhat.com>
357786
Patchwork-id: 81560
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 1/2] qemu-img: Add -C option for convert with copy offloading
357786
Bugzilla: 1607774
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
Signed-off-by: Fam Zheng <famz@redhat.com>
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
(cherry picked from commit e11ce12f5eb26438419e486a3ae2c9bb58a23c1f)
357786
Signed-off-by: Fam Zheng <famz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
Conflicts:
357786
357786
	qemu-img-cmds.hx
357786
	qemu-img.texi
357786
	qemu-img.c
357786
357786
All contextual conflicts.
357786
357786
1) Downstream doesn't have 46e8d272ba (qemu-img: Remove deprecated -s
357786
snapshot_id_or_name option).
357786
2) Downstream doesn't have 88481329c0 (qemu-img: allow compressed
357786
not-in-order writes).
357786
---
357786
 qemu-img-cmds.hx |  2 +-
357786
 qemu-img.c       | 21 +++++++++++++++++----
357786
 qemu-img.texi    |  8 +++++++-
357786
 3 files changed, 25 insertions(+), 6 deletions(-)
357786
357786
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
357786
index 2fe3189..48815c0 100644
357786
--- a/qemu-img-cmds.hx
357786
+++ b/qemu-img-cmds.hx
357786
@@ -41,7 +41,7 @@ STEXI
357786
 ETEXI
357786
 
357786
 DEF("convert", img_convert,
357786
-    "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")
357786
+    "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")
357786
 STEXI
357786
 @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}
357786
 ETEXI
357786
diff --git a/qemu-img.c b/qemu-img.c
357786
index eaee6d6..c9ccc1e 100644
357786
--- a/qemu-img.c
357786
+++ b/qemu-img.c
357786
@@ -2000,11 +2000,12 @@ static int img_convert(int argc, char **argv)
357786
          skip_create = false, progress = false, tgt_image_opts = false;
357786
     int64_t ret = -EINVAL;
357786
     bool force_share = false;
357786
+    bool explict_min_sparse = false;
357786
 
357786
     ImgConvertState s = (ImgConvertState) {
357786
         /* Need at least 4k of zeros for sparse detection */
357786
         .min_sparse         = 8,
357786
-        .copy_range         = true,
357786
+        .copy_range         = false,
357786
         .buf_sectors        = IO_BUF_SIZE / BDRV_SECTOR_SIZE,
357786
         .wr_in_order        = true,
357786
         .num_coroutines     = 8,
357786
@@ -2019,7 +2020,7 @@ static int img_convert(int argc, char **argv)
357786
             {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS},
357786
             {0, 0, 0, 0}
357786
         };
357786
-        c = getopt_long(argc, argv, ":hf:O:B:co:s:l:S:pt:T:qnm:WU",
357786
+        c = getopt_long(argc, argv, ":hf:O:B:Cco:s:l:S:pt:T:qnm:WU",
357786
                         long_options, NULL);
357786
         if (c == -1) {
357786
             break;
357786
@@ -2043,9 +2044,11 @@ static int img_convert(int argc, char **argv)
357786
         case 'B':
357786
             out_baseimg = optarg;
357786
             break;
357786
+        case 'C':
357786
+            s.copy_range = true;
357786
+            break;
357786
         case 'c':
357786
             s.compressed = true;
357786
-            s.copy_range = false;
357786
             break;
357786
         case 'o':
357786
             if (!is_valid_option_list(optarg)) {
357786
@@ -2087,7 +2090,7 @@ static int img_convert(int argc, char **argv)
357786
             }
357786
 
357786
             s.min_sparse = sval / BDRV_SECTOR_SIZE;
357786
-            s.copy_range = false;
357786
+            explict_min_sparse = true;
357786
             break;
357786
         }
357786
         case 'p':
357786
@@ -2152,6 +2155,16 @@ static int img_convert(int argc, char **argv)
357786
         goto fail_getopt;
357786
     }
357786
 
357786
+    if (s.compressed && s.copy_range) {
357786
+        error_report("Cannot enable copy offloading when -c is used");
357786
+        goto fail_getopt;
357786
+    }
357786
+
357786
+    if (explict_min_sparse && s.copy_range) {
357786
+        error_report("Cannot enable copy offloading when -S is used");
357786
+        goto fail_getopt;
357786
+    }
357786
+
357786
     if (tgt_image_opts && !skip_create) {
357786
         error_report("--target-image-opts requires use of -n flag");
357786
         goto fail_getopt;
357786
diff --git a/qemu-img.texi b/qemu-img.texi
357786
index 8a26400..74d7290 100644
357786
--- a/qemu-img.texi
357786
+++ b/qemu-img.texi
357786
@@ -172,6 +172,12 @@ Number of parallel coroutines for the convert process
357786
 Allow out-of-order writes to the destination. This option improves performance,
357786
 but is only recommended for preallocated devices like host devices or other
357786
 raw block devices.
357786
+@item -C
357786
+Try to use copy offloading to move data from source image to target. This may
357786
+improve performance if the data is remote, such as with NFS or iSCSI backends,
357786
+but will not automatically sparsify zero sectors, and may result in a fully
357786
+allocated target image depending on the host support for getting allocation
357786
+information.
357786
 @end table
357786
 
357786
 Parameters to dd subcommand:
357786
@@ -340,7 +346,7 @@ Error on reading data
357786
 
357786
 @end table
357786
 
357786
-@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}
357786
+@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}
357786
 
357786
 Convert the disk image @var{filename} or a snapshot @var{snapshot_param}(@var{snapshot_id_or_name} is deprecated)
357786
 to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c}
357786
-- 
357786
1.8.3.1
357786