Skip to contentSkip to conversation

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

PATCH In review Ren Kimura 2 participants 2 messages Apr 27, 2016

lore
Share & tools
lore

Ren Kimura

author
#0 lore raw

PATCH v5 1/1 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.

---
 qemu-img.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
qemu-img.c +13 -2
index 1697762..cb72f14 100644
@@ -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;
         }
Signature · 1 line
2.5.0