From patchwork Sat Jun 22 20:58:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 253430 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 B18CB2C01FC for ; Sun, 23 Jun 2013 06:59:35 +1000 (EST) Received: from localhost ([::1]:52535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqUuD-0008O5-IT for incoming@patchwork.ozlabs.org; Sat, 22 Jun 2013 16:59:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqUti-0008CD-7Z for qemu-devel@nongnu.org; Sat, 22 Jun 2013 16:59:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UqUte-0005cw-Tx for qemu-devel@nongnu.org; Sat, 22 Jun 2013 16:59:02 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:54228 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqUte-0005cn-N2 for qemu-devel@nongnu.org; Sat, 22 Jun 2013 16:58:58 -0400 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 2EAC5147CA3; Sat, 22 Jun 2013 22:58:58 +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 ZyBQJyu8Tiih; Sat, 22 Jun 2013 22:58:53 +0200 (CEST) Received: from trinity64-ssd (unknown [82.141.7.8]) by ssl.dlh.net (Postfix) with ESMTP id 1A67814AF98; Sat, 22 Jun 2013 22:58:44 +0200 (CEST) Received: by trinity64-ssd (Postfix, from userid 1000) id 0C1D320211D; Sat, 22 Jun 2013 22:58:44 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Sat, 22 Jun 2013 22:58:30 +0200 Message-Id: <1371934712-11714-7-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1371934712-11714-1-git-send-email-pl@kamp.de> References: <1371934712-11714-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 , pbonzini@redhat.com, Peter Lieven , ronniesahlberg@gmail.com, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 6/8] qemu-img: use bdrv_write_zeroes to write zeroes 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 Signed-off-by: Peter Lieven --- qemu-img.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 809b4f1..5aa53ab 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1513,9 +1513,13 @@ static int img_convert(int argc, char **argv) If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ - if (!has_zero_init || out_baseimg || - is_allocated_sectors_min(buf1, n, &n1, min_sparse)) { - ret = bdrv_write(out_bs, sector_num, buf1, n1); + int allocated = is_allocated_sectors_min(buf1, n, &n1, min_sparse); + if (!has_zero_init || out_baseimg || allocated) { + if (allocated || out_baseimg) { + ret = bdrv_write(out_bs, sector_num, buf1, n1); + } else { + ret = bdrv_write_zeroes(out_bs, sector_num, n1); + } if (ret < 0) { error_report("error while writing sector %" PRId64 ": %s", sector_num, strerror(-ret));