diff mbox

[v5] qemu-img: check block status of backing file when converting.

Message ID 1461773098-20356-1-git-send-email-rkx1209dev@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ren Kimura April 27, 2016, 4:04 p.m. UTC
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 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Max Reitz April 27, 2016, 4:31 p.m. UTC | #1
On 27.04.2016 18:04, 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>
> ---
>  qemu-img.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)

Thank you, I applied the patch to my block-next tree for inclusion into
qemu after the 2.6 release:

https://github.com/XanClic/qemu/commits/block-next

Max
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 1697762..cb72f14 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1478,10 +1478,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;
         }