aboutsummaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorRen Kimura <rkx1209dev@gmail.com>2016-04-28 01:04:58 +0900
committerMax Reitz <mreitz@redhat.com>2016-05-12 15:33:23 +0200
commit263a6f4c3aa9b6cd9f58d1368b318d948156a4e8 (patch)
tree791196fe0ea31c07a3be25c7fec8b946e748a723 /qemu-img.c
parent9036e87c7437388365a419a5f26445eb7809b941 (diff)
qemu-img: check block status of backing file when converting.
When converting images, check the block status of its backing file chain to avoid needlessly reading zeros. Signed-off-by: Ren Kimura <rkx1209dev@gmail.com> Message-id: 1461773098-20356-1-git-send-email-rkx1209dev@gmail.com Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 491a460ecf..47923663be 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1475,10 +1475,21 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)
} else if (!s->target_has_backing) {
/* Without a target backing file we must copy over the contents of
* the backing file as well. */
- /* TODO Check block status of the backing file chain to avoid
+ /* Check block status of the backing file chain to avoid
* needlessly reading zeroes and limiting the iteration to the
* buffer size */
- s->status = BLK_DATA;
+ ret = bdrv_get_block_status_above(blk_bs(s->src[s->src_cur]), NULL,
+ sector_num - s->src_cur_offset,
+ n, &n, &file);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (ret & BDRV_BLOCK_ZERO) {
+ s->status = BLK_ZERO;
+ } else {
+ s->status = BLK_DATA;
+ }
} else {
s->status = BLK_BACKING_FILE;
}