* [Qemu-devel] [PATCH v3] qemu-img: check block status of backing file when converting.
@ 2016-04-17 4:30 Ren Kimura
2016-04-21 5:28 ` Ren Kimura
2016-04-21 6:53 ` Denis V. Lunev
0 siblings, 2 replies; 3+ messages in thread
From: Ren Kimura @ 2016-04-17 4:30 UTC (permalink / raw)
To: mreitz; +Cc: kwolf, qemu-block, qemu-devel
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>
---
qemu-img.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 06264d9..ad1df5f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1451,6 +1451,22 @@ static void convert_select_part(ImgConvertState *s, int64_t sector_num)
}
}
+static int64_t get_backing_status(BlockDriverState *bs,
+ int64_t sector_num,
+ int nb_sectors, int *pnum)
+{
+ int64_t ret;
+ BlockDriverState *file;
+ ret = bdrv_get_block_status(bs, sector_num, nb_sectors, pnum, &file);
+ if (!(ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO))) {
+ if (bs->backing) {
+ ret = get_backing_status(bs->backing->bs, sector_num,
+ nb_sectors, pnum);
+ }
+ }
+ return ret;
+}
+
static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)
{
int64_t ret;
@@ -1477,10 +1493,17 @@ 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 = get_backing_status(blk_bs(s->src[s->src_cur]),
+ sector_num - s->src_cur_offset,
+ n, &n);
+ if (ret & BDRV_BLOCK_ZERO) {
+ s->status = BLK_ZERO;
+ } else {
+ s->status = BLK_DATA;
+ }
} else {
s->status = BLK_BACKING_FILE;
}
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v3] qemu-img: check block status of backing file when converting.
2016-04-17 4:30 [Qemu-devel] [PATCH v3] qemu-img: check block status of backing file when converting Ren Kimura
@ 2016-04-21 5:28 ` Ren Kimura
2016-04-21 6:53 ` Denis V. Lunev
1 sibling, 0 replies; 3+ messages in thread
From: Ren Kimura @ 2016-04-21 5:28 UTC (permalink / raw)
To: Max Reitz; +Cc: kwolf, qemu-block, QEMU Developers
[-- Attachment #1: Type: text/plain, Size: 5 bytes --]
ping
[-- Attachment #2: Type: text/html, Size: 60 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v3] qemu-img: check block status of backing file when converting.
2016-04-17 4:30 [Qemu-devel] [PATCH v3] qemu-img: check block status of backing file when converting Ren Kimura
2016-04-21 5:28 ` Ren Kimura
@ 2016-04-21 6:53 ` Denis V. Lunev
1 sibling, 0 replies; 3+ messages in thread
From: Denis V. Lunev @ 2016-04-21 6:53 UTC (permalink / raw)
To: Ren Kimura, mreitz; +Cc: kwolf, qemu-devel, qemu-block
On 04/17/2016 07:30 AM, Ren Kimura wrote:
> 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>
IMHO bdrv_get_block_status_above(bs, NULL, ...) should do the job
without recursion.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-21 7:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-17 4:30 [Qemu-devel] [PATCH v3] qemu-img: check block status of backing file when converting Ren Kimura
2016-04-21 5:28 ` Ren Kimura
2016-04-21 6:53 ` Denis V. Lunev
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).