From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGSC-0002ms-Jb for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHGS3-000675-8k for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:16 -0400 Received: from mail-qe0-x22b.google.com ([2607:f8b0:400d:c02::22b]:60238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHGS3-00066x-4K for qemu-devel@nongnu.org; Wed, 04 Sep 2013 13:01:07 -0400 Received: by mail-qe0-f43.google.com with SMTP id gh4so330553qeb.30 for ; Wed, 04 Sep 2013 10:01:06 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Sep 2013 19:00:27 +0200 Message-Id: <1378314038-15525-11-git-send-email-pbonzini@redhat.com> In-Reply-To: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> References: <1378314038-15525-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v5 10/21] block: make bdrv_has_zero_init return false for copy-on-write-images List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@redhat.com This helps implementing is_allocated on top of get_block_status. Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- block.c | 5 +++++ qemu-img.c | 9 +-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index a3f7577..e18ff71 100644 --- a/block.c +++ b/block.c @@ -3011,6 +3011,11 @@ int bdrv_has_zero_init(BlockDriverState *bs) { assert(bs->drv); + /* If BS is a copy on write image, it is initialized to + the contents of the base image, which may not be zeroes. */ + if (bs->backing_hd) { + return 0; + } if (bs->drv->bdrv_has_zero_init) { return bs->drv->bdrv_has_zero_init(bs); } diff --git a/qemu-img.c b/qemu-img.c index 837f8bc..d50e0fc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1514,14 +1514,7 @@ static int img_convert(int argc, char **argv) should add a specific call to have the info to go faster */ buf1 = buf; while (n > 0) { - /* If the output image is being created as a copy on write image, - copy all sectors even the ones containing only NUL bytes, - because they may differ from the sectors in the base image. - - If the output is to a host device, we also write out - sectors that are entirely 0, since whatever data was - already there is garbage, not 0s. */ - if (!has_zero_init || out_baseimg || + if (!has_zero_init || is_allocated_sectors_min(buf1, n, &n1, min_sparse)) { ret = bdrv_write(out_bs, sector_num, buf1, n1); if (ret < 0) { -- 1.8.3.1