thebeanogamer / rpms / qemu-kvm

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