qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/1] qemu-img: check block status of backing file wh


From: Ren Kimura
Subject: [Qemu-devel] [PATCH 1/1] qemu-img: check block status of backing file when converting.
Date: Wed, 13 Apr 2016 22:24:07 +0900

Signed-off-by: Ren Kimura <address@hidden>
---
 qemu-img.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 06264d9..53471a1 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1451,6 +1451,21 @@ 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,
+                                  BlockDriverState **file)
+{
+    int64_t ret;
+    if (bs->backing) {
+        ret = get_backing_status(bs->backing->bs, sector_num,
+                                 nb_sectors, pnum, file);
+    } else {
+        ret = bdrv_get_block_status(bs, sector_num, nb_sectors, pnum, file);
+    }
+    return ret;
+}
+
 static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num)
 {
     int64_t ret;
@@ -1469,7 +1484,6 @@ static int convert_iteration_sectors(ImgConvertState *s, 
int64_t sector_num)
         if (ret < 0) {
             return ret;
         }
-
         if (ret & BDRV_BLOCK_ZERO) {
             s->status = BLK_ZERO;
         } else if (ret & BDRV_BLOCK_DATA) {
@@ -1477,10 +1491,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, &file);
+            if (ret & BDRV_BLOCK_ZERO) {
+                s->status = BLK_ZERO;
+            } else {
+                s->status = BLK_DATA;
+            }
         } else {
             s->status = BLK_BACKING_FILE;
         }
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]