From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLvi7-000174-6O for qemu-devel@nongnu.org; Tue, 17 Sep 2013 09:53:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLvhw-0002SZ-NU for qemu-devel@nongnu.org; Tue, 17 Sep 2013 09:52:58 -0400 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:50321 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLvhw-0002SH-CC for qemu-devel@nongnu.org; Tue, 17 Sep 2013 09:52:48 -0400 From: Peter Lieven Date: Tue, 17 Sep 2013 15:48:55 +0200 Message-Id: <1379425736-11326-20-git-send-email-pl@kamp.de> In-Reply-To: <1379425736-11326-1-git-send-email-pl@kamp.de> References: <1379425736-11326-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCHv2 19/20] qemu-img: conditionally zero out target on convert List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, ronniesahlberg@gmail.com, Peter Lieven , stefanha@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com 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 --- qemu-img.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) { -- 1.7.9.5