From patchwork Thu Mar 8 17:15:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 145594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BCEF6B6FEF for ; Fri, 9 Mar 2012 04:30:48 +1100 (EST) Received: from localhost ([::1]:52536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwj-0004kl-Ss for incoming@patchwork.ozlabs.org; Thu, 08 Mar 2012 12:16:09 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwR-0004WM-5c for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5gwI-0004p8-GL for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:50 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:47906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwI-0004n5-7d for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:42 -0500 Received: by mail-iy0-f173.google.com with SMTP id j26so1015616iaf.4 for ; Thu, 08 Mar 2012 09:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=xcbuTpzgpI507cvc5QMlx3dWQuINARW5Ws/QhGxX4uk=; b=yhDWNcUtX75U2SpHsj3d0gEQBFHMcXlUQf/Tc0PG8mT5AMFg/AwegiiB4qv8n9X0bj FNTpHXRPJdk5XBJkXfYJt7vlx0vb2gG70rKShdTClMIth6W3MSHdlakA0fdCUXeUbllf AmEnNXl8hGQJKlxNm7vjhk/PzARa0WSOqISBUX4hHc5zbF2D1p6S0iiqSj5HG/Nr+6Oh 0RYU09YotCH5M18YgEqPYmmnK3QcR7nFO0zkP3PPGrgci3FPqO19BhqWzGbcn74g7vgv 9fq+NzlBEsx7uvCmwRtnAxjNWacyiTf/9lUDwn3a7w1bmD5AcDCM4koRZrHZAr5BYXB1 OZpQ== Received: by 10.50.219.170 with SMTP id pp10mr7984137igc.49.1331226940611; Thu, 08 Mar 2012 09:15:40 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id s3sm2123819igw.17.2012.03.08.09.15.38 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Mar 2012 09:15:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 8 Mar 2012 18:15:06 +0100 Message-Id: <1331226917-6658-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> References: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.173 Subject: [Qemu-devel] [RFC PATCH 06/17] block: use bdrv_{co, aio}_discard for write_zeroes operations 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 Remove the bdrv_co_write_zeroes callback. Instead use the discard information from bdrv_get_info to choose between bdrv_co_discard and a normal write. Signed-off-by: Paolo Bonzini --- block.c | 12 +++++++++--- block/qed.c | 8 -------- block_int.h | 8 -------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index e4f7782..34db914 100644 --- a/block.c +++ b/block.c @@ -1656,6 +1656,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, int cluster_nb_sectors; size_t skip_bytes; int ret; + BlockDriverInfo bdi; /* Cover entire cluster so no additional backing file I/O is required when * allocating cluster in the image file. @@ -1676,7 +1677,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs, goto err; } - if (drv->bdrv_co_write_zeroes && + /* If it is worthless, do not check if the buffer is zero. */ + if (bdrv_get_info(bs, &bdi) >= 0 && bdi.discard_zeroes_data && buffer_is_zero(bounce_buffer, iov.iov_len)) { ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num, cluster_nb_sectors, &bounce_qiov); @@ -1785,13 +1787,17 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BlockDriver *drv = bs->drv; + BlockDriverInfo bdi; QEMUIOVector my_qiov; struct iovec iov; int ret; /* First try the efficient write zeroes operation */ - if (drv->bdrv_co_write_zeroes) { - return drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors); + if (bdrv_get_info(bs, &bdi) >= 0 && bdi.discard_zeroes_data && + bdi.discard_granularity && + (sector_num & (bdi.discard_granularity - 1)) == 0 && + (nb_sectors & (bdi.discard_granularity - 1)) == 0) { + return bdrv_co_discard(bs, sector_num, nb_sectors); } if (qiov) { diff --git a/block/qed.c b/block/qed.c index 9944be5..33fe03f 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1395,13 +1395,6 @@ static BlockDriverAIOCB *bdrv_qed_aio_flush(BlockDriverState *bs, return bdrv_aio_flush(bs->file, cb, opaque); } -static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors) -{ - return bdrv_co_discard(bs, sector_num, nb_sectors); -} - static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset) { BDRVQEDState *s = bs->opaque; @@ -1563,7 +1556,6 @@ static BlockDriver bdrv_qed = { .bdrv_aio_writev = bdrv_qed_aio_writev, .bdrv_aio_flush = bdrv_qed_aio_flush, .bdrv_aio_discard = bdrv_qed_aio_discard, - .bdrv_co_write_zeroes = bdrv_qed_co_write_zeroes, .bdrv_truncate = bdrv_qed_truncate, .bdrv_getlength = bdrv_qed_getlength, .bdrv_get_info = bdrv_qed_get_info, diff --git a/block_int.h b/block_int.h index b460c36..2e8cdfe 100644 --- a/block_int.h +++ b/block_int.h @@ -131,14 +131,6 @@ struct BlockDriver { int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); - /* - * Efficiently zero a region of the disk image. Typically an image format - * would use a compact metadata representation to implement this. This - * function pointer may be NULL and .bdrv_co_writev() will be called - * instead. - */ - int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs, - int64_t sector_num, int nb_sectors); int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs,