Patchwork [PATCHv4,16/17] qemu-img: conditionally zero out target on convert

login
register
mail settings
Submitter Peter Lieven
Date Oct. 8, 2013, 11:58 a.m.
Message ID <1381233491-17019-17-git-send-email-pl@kamp.de>
Download mbox | patch
Permalink /patch/281423/
State New
Headers show

Comments

Peter Lieven - Oct. 8, 2013, 11:58 a.m.
If the target has_zero_init = 0, but supports efficiently
writing zeroes by unmapping we call bdrv_zeroize to
avoid fully allocating the target. This currently
is designed especially for iscsi.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 qemu-img.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Stefan Hajnoczi - Oct. 18, 2013, 12:26 p.m.
On Tue, Oct 08, 2013 at 01:58:10PM +0200, Peter Lieven wrote:
> If the target has_zero_init = 0, but supports efficiently
> writing zeroes by unmapping we call bdrv_zeroize to

s/bdrv_zeroize/bdrv_make_zero/

No need to respin.

Patch

diff --git a/qemu-img.c b/qemu-img.c
index c6eff15..2d46de8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1353,7 +1353,7 @@  static int img_convert(int argc, char **argv)
         }
     }
 
-    flags = BDRV_O_RDWR;
+    flags = min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR;
     ret = bdrv_parse_cache_flags(cache, &flags);
     if (ret < 0) {
         error_report("Invalid cache option: %s", cache);
@@ -1469,6 +1469,14 @@  static int img_convert(int argc, char **argv)
     } else {
         int has_zero_init = min_sparse ? bdrv_has_zero_init(out_bs) : 0;
 
+        if (!has_zero_init && bdrv_has_discard_write_zeroes(out_bs)) {
+            ret = bdrv_make_zero(out_bs, BDRV_REQ_MAY_UNMAP);
+            if (ret < 0) {
+                goto out;
+            }
+            has_zero_init = 1;
+        }
+
         sector_num = 0; // total number of sectors converted so far
         nb_sectors = total_sectors - sector_num;
         if (nb_sectors != 0) {