From patchwork Sun Oct 20 15:43:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 285014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E76352C00C4 for ; Mon, 21 Oct 2013 02:48:46 +1100 (EST) Received: from localhost ([::1]:36601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXvFE-0003DM-Sn for incoming@patchwork.ozlabs.org; Sun, 20 Oct 2013 11:48:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXvAr-0005DN-CT for qemu-devel@nongnu.org; Sun, 20 Oct 2013 11:44:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VXvAl-0003kM-6x for qemu-devel@nongnu.org; Sun, 20 Oct 2013 11:44:13 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:40602 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXvAl-0003kA-0O for qemu-devel@nongnu.org; Sun, 20 Oct 2013 11:44:07 -0400 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 8974614E74D; Sun, 20 Oct 2013 17:44:06 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6o6nIZOQ9FVl; Sun, 20 Oct 2013 17:44:02 +0200 (CEST) Received: from trinity64-ssd (unknown [82.141.7.8]) by ssl.dlh.net (Postfix) with ESMTP id 4E80314E760; Sun, 20 Oct 2013 17:43:57 +0200 (CEST) Received: by trinity64-ssd (Postfix, from userid 1000) id 3A1F82021C1; Sun, 20 Oct 2013 17:43:12 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Sun, 20 Oct 2013 17:43:10 +0200 Message-Id: <1382283791-11181-17-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1382283791-11181-1-git-send-email-pl@kamp.de> References: <1382283791-11181-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Kevin Wolf , Stefan Hajnoczi , Peter Lieven , ronniesahlberg@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCHv5 16/17] qemu-img: conditionally zero out target on convert X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 is designed especially for iscsi. Reviewed-by: Eric Blake 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 c6eff15..fe0bdb1 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_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) {