cryptospore / 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

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