qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v4 09/21] qemu-img: always probe the input image for allocated sectors
Date: Thu, 29 Aug 2013 16:00:09 +0200	[thread overview]
Message-ID: <1377784821-29561-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1377784821-29561-1-git-send-email-pbonzini@redhat.com>

qemu-img convert can assume "that sectors which are unallocated in the
input image are present in both the output's and input's base images".

However it is only doing this if the output image returns true for
bdrv_has_zero_init().  Testing bdrv_has_zero_init() does not make much
sense if the output image is copy-on-write, because a copy-on-write
image is never initialized to zero (it is initialized to the content
of the backing file).

There is nothing here that makes has_zero_init images special.  The
input and output must be equal for the operation to make sense, and
that's it.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-img.c | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index b01998b..837f8bc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1479,28 +1479,26 @@ static int img_convert(int argc, char **argv)
                 n = bs_offset + bs_sectors - sector_num;
             }
 
-            if (has_zero_init) {
-                /* If the output image is being created as a copy on write image,
-                   assume that sectors which are unallocated in the input image
-                   are present in both the output's and input's base images (no
-                   need to copy them). */
-                if (out_baseimg) {
-                    ret = bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
-                                            n, &n1);
-                    if (ret < 0) {
-                        error_report("error while reading metadata for sector "
-                                     "%" PRId64 ": %s",
-                                     sector_num - bs_offset, strerror(-ret));
-                        goto out;
-                    }
-                    if (!ret) {
-                        sector_num += n1;
-                        continue;
-                    }
-                    /* The next 'n1' sectors are allocated in the input image. Copy
-                       only those as they may be followed by unallocated sectors. */
-                    n = n1;
+            /* If the output image is being created as a copy on write image,
+               assume that sectors which are unallocated in the input image
+               are present in both the output's and input's base images (no
+               need to copy them). */
+            if (out_baseimg) {
+                ret = bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
+                                        n, &n1);
+                if (ret < 0) {
+                    error_report("error while reading metadata for sector "
+                                 "%" PRId64 ": %s",
+                                 sector_num - bs_offset, strerror(-ret));
+                    goto out;
+                }
+                if (!ret) {
+                    sector_num += n1;
+                    continue;
                 }
+                /* The next 'n1' sectors are allocated in the input image. Copy
+                   only those as they may be followed by unallocated sectors. */
+                n = n1;
             } else {
                 n1 = n;
             }
-- 
1.8.3.1

  parent reply	other threads:[~2013-08-29 14:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-29 14:00 [Qemu-devel] [PATCH v4 00/21] Add qemu-img subcommand to dump file metadata Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 01/21] cow: make reads go at a decent speed Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 02/21] cow: make writes go at a less indecent speed Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 03/21] cow: do not call bdrv_co_is_allocated Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 04/21] block: keep bs->total_sectors up to date even for growable block devices Paolo Bonzini
2013-08-29 19:51   ` Eric Blake
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 05/21] block: make bdrv_co_is_allocated static Paolo Bonzini
2013-08-29 19:53   ` Eric Blake
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 06/21] block: do not use ->total_sectors in bdrv_co_is_allocated Paolo Bonzini
2013-08-29 19:58   ` Eric Blake
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 07/21] block: remove bdrv_is_allocated_above/bdrv_co_is_allocated_above distinction Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 08/21] block: expect errors from bdrv_co_is_allocated Paolo Bonzini
2013-08-29 21:35   ` Eric Blake
2013-08-30  7:18     ` Paolo Bonzini
2013-08-29 14:00 ` Paolo Bonzini [this message]
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 10/21] block: make bdrv_has_zero_init return false for copy-on-write-images Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 11/21] block: introduce bdrv_get_block_status API Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 12/21] block: define get_block_status return value Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 13/21] block: return get_block_status data and flags for formats Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 14/21] block: use bdrv_has_zero_init to return BDRV_BLOCK_ZERO Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 15/21] block: return BDRV_BLOCK_ZERO past end of backing file Paolo Bonzini
2013-08-29 21:59   ` Eric Blake
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 16/21] qemu-img: add a "map" subcommand Paolo Bonzini
2013-08-29 22:49   ` Eric Blake
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 17/21] docs, qapi: document qemu-img map Paolo Bonzini
2013-08-29 15:31   ` Eric Blake
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 18/21] raw-posix: return get_block_status data and flags Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 19/21] raw-posix: report unwritten extents as zero Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 20/21] block: add default get_block_status implementation for protocols Paolo Bonzini
2013-08-29 14:00 ` [Qemu-devel] [PATCH v4 21/21] block: look for zero blocks in bs->file Paolo Bonzini
2013-09-04 15:50 ` [Qemu-devel] [PATCH v4 00/21] Add qemu-img subcommand to dump file metadata Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377784821-29561-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).