Blame SOURCES/kvm-block-make-bdrv_has_zero_init-return-false-for-copy-.patch

218e99
From 455a0cc4e93815b2cd2741554076029f2c365e25 Mon Sep 17 00:00:00 2001
218e99
From: Paolo Bonzini <pbonzini@redhat.com>
218e99
Date: Fri, 18 Oct 2013 08:14:36 +0200
218e99
Subject: [PATCH 11/81] block: make bdrv_has_zero_init return false for copy-on-write-images
218e99
218e99
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
218e99
Message-id: <1382084091-16636-12-git-send-email-pbonzini@redhat.com>
218e99
Patchwork-id: 54994
218e99
O-Subject: [RHEL 7.0 qemu-kvm PATCH 11/26] block: make bdrv_has_zero_init return false for copy-on-write-images
218e99
Bugzilla: 989646
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
218e99
This helps implementing is_allocated on top of get_block_status.
218e99
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
(cherry picked from commit 11212d8fa08a4e5bd56bb4f6877f9a4c0439a02b)
218e99
---
218e99
 block.c    | 5 +++++
218e99
 qemu-img.c | 9 +--------
218e99
 2 files changed, 6 insertions(+), 8 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block.c    |    5 +++++
218e99
 qemu-img.c |    9 +--------
218e99
 2 files changed, 6 insertions(+), 8 deletions(-)
218e99
218e99
diff --git a/block.c b/block.c
218e99
index d838a3c..f5d6658 100644
218e99
--- a/block.c
218e99
+++ b/block.c
218e99
@@ -2998,6 +2998,11 @@ int bdrv_has_zero_init(BlockDriverState *bs)
218e99
 {
218e99
     assert(bs->drv);
218e99
 
218e99
+    /* If BS is a copy on write image, it is initialized to
218e99
+       the contents of the base image, which may not be zeroes.  */
218e99
+    if (bs->backing_hd) {
218e99
+        return 0;
218e99
+    }
218e99
     if (bs->drv->bdrv_has_zero_init) {
218e99
         return bs->drv->bdrv_has_zero_init(bs);
218e99
     }
218e99
diff --git a/qemu-img.c b/qemu-img.c
218e99
index 71cbc59..a9aabd5 100644
218e99
--- a/qemu-img.c
218e99
+++ b/qemu-img.c
218e99
@@ -1511,14 +1511,7 @@ static int img_convert(int argc, char **argv)
218e99
                should add a specific call to have the info to go faster */
218e99
             buf1 = buf;
218e99
             while (n > 0) {
218e99
-                /* If the output image is being created as a copy on write image,
218e99
-                   copy all sectors even the ones containing only NUL bytes,
218e99
-                   because they may differ from the sectors in the base image.
218e99
-
218e99
-                   If the output is to a host device, we also write out
218e99
-                   sectors that are entirely 0, since whatever data was
218e99
-                   already there is garbage, not 0s. */
218e99
-                if (!has_zero_init || out_baseimg ||
218e99
+                if (!has_zero_init ||
218e99
                     is_allocated_sectors_min(buf1, n, &n1, min_sparse)) {
218e99
                     ret = bdrv_write(out_bs, sector_num, buf1, n1);
218e99
                     if (ret < 0) {
218e99
-- 
218e99
1.7.1
218e99