aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Lieven <pl@kamp.de>2013-10-24 12:07:06 +0200
committerKevin Wolf <kwolf@redhat.com>2013-11-28 10:30:52 +0100
commit5a37b60a61c4c334e3b194758871f41494317d42 (patch)
treef8c169029b78de6fa1012b4f94ccf02ae174a34d
parent11b6699af59b8684128debacfc7c44cbaa6ac53b (diff)
qemu-img: conditionally zero out target on convert
If the target has_zero_init = 0, but supports efficiently writing zeroes by unmapping we call bdrv_make_zero to avoid fully allocating the target. This currently works only for iscsi. It can be extended to raw with BLKDISCARDZEROES for example. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Peter Lieven <pl@kamp.de> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--qemu-img.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/qemu-img.c b/qemu-img.c
index cc3fed7b44..dc0c2f0ed3 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1355,7 +1355,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);
@@ -1471,6 +1471,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_can_write_zeroes_with_unmap(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) {