yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qemu-img-conditionally-zero-out-target-on-convert.patch.patch.patch

0a122b
From 33d075d8a2d5c6f22aaefb5fcfbee61e0c46586b Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <33d075d8a2d5c6f22aaefb5fcfbee61e0c46586b.1389014116.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Date: Mon, 9 Dec 2013 14:09:10 +0100
0a122b
Subject: [PATCH 22/50] qemu-img: conditionally zero out target on convert
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-25-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56061
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 24/52] qemu-img: conditionally zero out target on convert
0a122b
Bugzilla: 1007815
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
From: Peter Lieven <pl@kamp.de>
0a122b
0a122b
If the target has_zero_init = 0, but supports efficiently
0a122b
writing zeroes by unmapping we call bdrv_make_zero to
0a122b
avoid fully allocating the target. This currently works
0a122b
only for iscsi.  It can be extended to raw with
0a122b
BLKDISCARDZEROES for example.
0a122b
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Signed-off-by: Peter Lieven <pl@kamp.de>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 5a37b60a61c4c334e3b194758871f41494317d42)
0a122b
---
0a122b
 qemu-img.c | 10 +++++++++-
0a122b
 1 file changed, 9 insertions(+), 1 deletion(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 qemu-img.c | 10 +++++++++-
0a122b
 1 file changed, 9 insertions(+), 1 deletion(-)
0a122b
0a122b
diff --git a/qemu-img.c b/qemu-img.c
0a122b
index dfd8a92..3dacbec 100644
0a122b
--- a/qemu-img.c
0a122b
+++ b/qemu-img.c
0a122b
@@ -1353,7 +1353,7 @@ static int img_convert(int argc, char **argv)
0a122b
         }
0a122b
     }
0a122b
 
0a122b
-    flags = BDRV_O_RDWR;
0a122b
+    flags = min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR;
0a122b
     ret = bdrv_parse_cache_flags(cache, &flags);
0a122b
     if (ret < 0) {
0a122b
         error_report("Invalid cache option: %s", cache);
0a122b
@@ -1469,6 +1469,14 @@ static int img_convert(int argc, char **argv)
0a122b
     } else {
0a122b
         int has_zero_init = min_sparse ? bdrv_has_zero_init(out_bs) : 0;
0a122b
 
0a122b
+        if (!has_zero_init && bdrv_can_write_zeroes_with_unmap(out_bs)) {
0a122b
+            ret = bdrv_make_zero(out_bs, BDRV_REQ_MAY_UNMAP);
0a122b
+            if (ret < 0) {
0a122b
+                goto out;
0a122b
+            }
0a122b
+            has_zero_init = 1;
0a122b
+        }
0a122b
+
0a122b
         sector_num = 0; // total number of sectors converted so far
0a122b
         nb_sectors = total_sectors - sector_num;
0a122b
         if (nb_sectors != 0) {
0a122b
-- 
0a122b
1.7.11.7
0a122b