From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRDP-0004AW-6j for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:46:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmRDK-0002ta-AY for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:46:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60299) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRDK-0002tU-2m for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:46:46 -0500 From: Kevin Wolf Date: Fri, 29 Nov 2013 17:45:32 +0100 Message-Id: <1385743555-27888-18-git-send-email-kwolf@redhat.com> In-Reply-To: <1385743555-27888-1-git-send-email-kwolf@redhat.com> References: <1385743555-27888-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 17/41] qemu-img: conditionally zero out target on convert List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Peter Lieven 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 Signed-off-by: Peter Lieven Signed-off-by: Stefan Hajnoczi --- qemu-img.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index cc3fed7..dc0c2f0 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) { -- 1.8.1.4