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

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