From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RdOcK-0007lU-QC for qemu-devel@nongnu.org; Wed, 21 Dec 2011 11:02:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RdOcJ-0001tO-GI for qemu-devel@nongnu.org; Wed, 21 Dec 2011 11:02:08 -0500 Received: from e06smtp18.uk.ibm.com ([195.75.94.114]:34270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RdOcJ-0001tC-4J for qemu-devel@nongnu.org; Wed, 21 Dec 2011 11:02:07 -0500 Received: from /spool/local by e06smtp18.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Dec 2011 16:02:06 -0000 Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBLG229M2277570 for ; Wed, 21 Dec 2011 16:02:02 GMT Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBLG22Ya002320 for ; Wed, 21 Dec 2011 16:02:02 GMT From: Stefan Hajnoczi Date: Wed, 21 Dec 2011 16:00:37 +0000 Message-Id: <1324483240-31726-4-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1324483240-31726-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1324483240-31726-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v3 3/6] block: perform zero-detection during copy-on-read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Marcelo Tosatti , 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 --- block.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 5ebbd4d..967a583 100644 --- a/block.c +++ b/block.c @@ -1506,6 +1506,7 @@ static int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, */ void *bounce_buffer; + BlockDriver *drv = bs->drv; struct iovec iov; QEMUIOVector bounce_qiov; int64_t cluster_sector_num; @@ -1526,14 +1527,21 @@ static int coroutine_fn bdrv_co_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. -- 1.7.7.3