From patchwork Tue May 17 09:15:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9110761 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7801D9F1C1 for ; Tue, 17 May 2016 09:18:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6D642022D for ; Tue, 17 May 2016 09:18:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96D3E202EC for ; Tue, 17 May 2016 09:18:04 +0000 (UTC) Received: from localhost ([::1]:49434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2b8d-00029F-P2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 17 May 2016 05:18:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2b6a-0005gz-4M for qemu-devel@nongnu.org; Tue, 17 May 2016 05:15:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2b6X-0007M5-Uw for qemu-devel@nongnu.org; Tue, 17 May 2016 05:15:54 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:32675 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2b6X-0007Lu-GD for qemu-devel@nongnu.org; Tue, 17 May 2016 05:15:53 -0400 Received: from irbis.sw.ru ([10.24.38.119]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u4H9FhxM030135; Tue, 17 May 2016 12:15:52 +0300 (MSK) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Date: Tue, 17 May 2016 12:15:43 +0300 Message-Id: <1463476543-3087-6-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463476543-3087-1-git-send-email-den@openvz.org> References: <1463476543-3087-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 5/5] qcow2: merge is_zero_cluster helpers into qcow2_co_write_zeroes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP They are used once only. This makes code more compact. The patch also improves comments in the code. Signed-off-by: Denis V. Lunev CC: Kevin Wolf --- block/qcow2.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 05beb64..feaf146 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2405,27 +2405,6 @@ finish: } -static bool is_zero_cluster(BlockDriverState *bs, int64_t start) -{ - BDRVQcow2State *s = bs->opaque; - int nr; - BlockDriverState *file; - int64_t res = bdrv_get_block_status_above(bs, NULL, start, - s->cluster_sectors, &nr, &file); - return res >= 0 && (res & BDRV_BLOCK_ZERO); -} - -static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start) -{ - BDRVQcow2State *s = bs->opaque; - int nr = s->cluster_sectors; - uint64_t off; - int ret; - - ret = qcow2_get_cluster_offset(bs, start << BDRV_SECTOR_BITS, &nr, &off); - return ret == QCOW2_CLUSTER_UNALLOCATED || ret == QCOW2_CLUSTER_ZERO; -} - static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors, BdrvRequestFlags flags) { @@ -2439,20 +2418,32 @@ static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs, nb_sectors); if (head != 0 || tail != 0) { - int64_t cl_start = sector_num - head; + BlockDriverState *file; + uint64_t off; + int nr; + + int64_t cl_start = sector_num - head, res; assert(cl_start + s->cluster_sectors >= sector_num + nb_sectors); sector_num = cl_start; nb_sectors = s->cluster_sectors; - if (!is_zero_cluster(bs, sector_num)) { + /* check that the cluster is zeroed taking into account entire + backing chain */ + nr = s->cluster_sectors; + res = bdrv_get_block_status_above(bs, NULL, cl_start, + s->cluster_sectors, &nr, &file); + if (res < 0 || !(res & BDRV_BLOCK_ZERO)) { return -ENOTSUP; } qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ - if (!is_zero_cluster_top_locked(bs, sector_num)) { + nr = s->cluster_sectors; + ret = qcow2_get_cluster_offset(bs, cl_start << BDRV_SECTOR_BITS, + &nr, &off); + if (ret != QCOW2_CLUSTER_UNALLOCATED && ret != QCOW2_CLUSTER_ZERO) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; }