From patchwork Fri Feb 10 12:47:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 140610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CC151B6EEC for ; Fri, 10 Feb 2012 23:57:58 +1100 (EST) Received: from localhost ([::1]:37902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rvpqh-0002TS-C3 for incoming@patchwork.ozlabs.org; Fri, 10 Feb 2012 07:45:11 -0500 Received: from eggs.gnu.org ([140.186.70.92]:53461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rvpq9-00012Z-6q for qemu-devel@nongnu.org; Fri, 10 Feb 2012 07:44:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rvpq3-0006Bv-Ix for qemu-devel@nongnu.org; Fri, 10 Feb 2012 07:44:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23255) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rvpq3-0006BG-7x for qemu-devel@nongnu.org; Fri, 10 Feb 2012 07:44:31 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1ACiTGq019381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 10 Feb 2012 07:44:29 -0500 Received: from dhcp-5-188.str.redhat.com (vpn1-7-203.ams2.redhat.com [10.36.7.203]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1ACiH04006010; Fri, 10 Feb 2012 07:44:28 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 10 Feb 2012 13:47:32 +0100 Message-Id: <1328878064-4907-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1328878064-4907-1-git-send-email-kwolf@redhat.com> References: <1328878064-4907-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 03/15] block: perform zero-detection during copy-on-read 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 From: Stefan Hajnoczi Copy-on-Read populates the image file with data read from a backing image. In order to avoid bloating the image file when all zeroes are read we should scan the buffer and perform an optimized zero write operation. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index c9fa5c1..ae297bb 100644 --- a/block.c +++ b/block.c @@ -1517,6 +1517,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, */ void *bounce_buffer; + BlockDriver *drv = bs->drv; struct iovec iov; QEMUIOVector bounce_qiov; int64_t cluster_sector_num; @@ -1537,14 +1538,21 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, iov.iov_base = bounce_buffer = qemu_blockalign(bs, iov.iov_len); qemu_iovec_init_external(&bounce_qiov, &iov, 1); - ret = bs->drv->bdrv_co_readv(bs, cluster_sector_num, cluster_nb_sectors, - &bounce_qiov); + ret = drv->bdrv_co_readv(bs, cluster_sector_num, cluster_nb_sectors, + &bounce_qiov); if (ret < 0) { goto err; } - ret = bs->drv->bdrv_co_writev(bs, cluster_sector_num, cluster_nb_sectors, + if (drv->bdrv_co_write_zeroes && + buffer_is_zero(bounce_buffer, iov.iov_len)) { + ret = drv->bdrv_co_write_zeroes(bs, cluster_sector_num, + cluster_nb_sectors); + } else { + ret = drv->bdrv_co_writev(bs, cluster_sector_num, cluster_nb_sectors, &bounce_qiov); + } + if (ret < 0) { /* It might be okay to ignore write errors for guest requests. If this * is a deliberate copy-on-read then we don't want to ignore the error.