diff mbox

[PATCHv2,19/20] qemu-img: conditionally zero out target on convert

Message ID 1379425736-11326-20-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven Sept. 17, 2013, 1:48 p.m. UTC
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.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 qemu-img.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Eric Blake Sept. 19, 2013, 8:39 p.m. UTC | #1
On 09/17/2013 07:48 AM, Peter Lieven wrote:
> 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

You don't like the shift key, do you? :)

s/this/This/ if you care about grammar in commit messages (I care about
it in user-visible strings, but am more than willing to let it slide in
commit messages)

> is designed especially for iscsi.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  qemu-img.c |   10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 7600b58..d6af941 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1356,7 +1356,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);
@@ -1472,6 +1472,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_zeroize(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) {