From patchwork Wed Jun 1 21:10:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9148151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9E5260751 for ; Wed, 1 Jun 2016 21:15:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBE8B200F4 for ; Wed, 1 Jun 2016 21:15:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0E4E26B39; Wed, 1 Jun 2016 21:15:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 46E20200F4 for ; Wed, 1 Jun 2016 21:15:49 +0000 (UTC) Received: from localhost ([::1]:44151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8DUS-0006Is-BZ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Jun 2016 17:15:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8DPJ-00027M-6f for qemu-devel@nongnu.org; Wed, 01 Jun 2016 17:10:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8DPG-0008D2-TC for qemu-devel@nongnu.org; Wed, 01 Jun 2016 17:10:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8DPA-0008AG-LN; Wed, 01 Jun 2016 17:10:20 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59DFD4944E; Wed, 1 Jun 2016 21:10:20 +0000 (UTC) Received: from red.redhat.com (ovpn-116-150.phx2.redhat.com [10.3.116.150]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u51LAF6T027968; Wed, 1 Jun 2016 17:10:19 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 1 Jun 2016 15:10:06 -0600 Message-Id: <1464815413-613-7-git-send-email-eblake@redhat.com> In-Reply-To: <1464815413-613-1-git-send-email-eblake@redhat.com> References: <1464815413-613-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 01 Jun 2016 21:10:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 06/13] qcow2: Convert to bdrv_co_pwrite_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: kwolf@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Another step on our continuing quest to switch to byte-based interfaces. Signed-off-by: Eric Blake --- block/qcow2.c | 37 +++++++++++++++++++------------------ trace-events | 4 ++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index cc59efc..5e26c3d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2421,38 +2421,39 @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start, return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == count; } -static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, BdrvRequestFlags flags) +static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, + int64_t offset, int count, BdrvRequestFlags flags) { int ret; BDRVQcow2State *s = bs->opaque; - uint32_t head = sector_num % s->cluster_sectors; - uint32_t tail = (sector_num + nb_sectors) % s->cluster_sectors; + uint32_t head = offset % s->cluster_size; + uint32_t tail = (offset + count) % s->cluster_size; - trace_qcow2_write_zeroes_start_req(qemu_coroutine_self(), sector_num, - nb_sectors); + trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, count); if (head || tail) { - int64_t cl_start = sector_num - head; + int64_t cl_start = (offset - head) >> BDRV_SECTOR_BITS; uint64_t off; int nr; - assert(cl_start + s->cluster_sectors >= sector_num + nb_sectors); + assert(head + count <= s->cluster_size); /* check whether remainder of cluster already reads as zero */ - if (!(is_zero_sectors(bs, cl_start, head) && - is_zero_sectors(bs, sector_num + nb_sectors, - -tail & (s->cluster_sectors - 1)))) { + if (!(is_zero_sectors(bs, cl_start, + DIV_ROUND_UP(head, BDRV_SECTOR_SIZE)) && + is_zero_sectors(bs, (offset + count) >> BDRV_SECTOR_BITS, + DIV_ROUND_UP(-tail & (s->cluster_size - 1), + BDRV_SECTOR_SIZE)))) { return -ENOTSUP; } qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ - sector_num = cl_start; - nb_sectors = nr = s->cluster_sectors; - ret = qcow2_get_cluster_offset(bs, cl_start << BDRV_SECTOR_BITS, - &nr, &off); + offset = cl_start << BDRV_SECTOR_BITS; + count = s->cluster_size; + nr = s->cluster_sectors; + ret = qcow2_get_cluster_offset(bs, offset, &nr, &off); if (ret != QCOW2_CLUSTER_UNALLOCATED && ret != QCOW2_CLUSTER_ZERO) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; @@ -2461,10 +2462,10 @@ static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs, qemu_co_mutex_lock(&s->lock); } - trace_qcow2_write_zeroes(qemu_coroutine_self(), sector_num, nb_sectors); + trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, count); /* Whatever is left can use real zero clusters */ - ret = qcow2_zero_clusters(bs, sector_num << BDRV_SECTOR_BITS, nb_sectors); + ret = qcow2_zero_clusters(bs, offset, count >> BDRV_SECTOR_BITS); qemu_co_mutex_unlock(&s->lock); return ret; @@ -3371,7 +3372,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_co_writev = qcow2_co_writev, .bdrv_co_flush_to_os = qcow2_co_flush_to_os, - .bdrv_co_write_zeroes = qcow2_co_write_zeroes, + .bdrv_co_pwrite_zeroes = qcow2_co_pwrite_zeroes, .bdrv_co_discard = qcow2_co_discard, .bdrv_truncate = qcow2_truncate, .bdrv_write_compressed = qcow2_write_compressed, diff --git a/trace-events b/trace-events index 6329c01..2537eec 100644 --- a/trace-events +++ b/trace-events @@ -612,8 +612,8 @@ qcow2_writev_done_req(void *co, int ret) "co %p ret %d" qcow2_writev_start_part(void *co) "co %p" qcow2_writev_done_part(void *co, int cur_nr_sectors) "co %p cur_nr_sectors %d" qcow2_writev_data(void *co, uint64_t offset) "co %p offset %" PRIx64 -qcow2_write_zeroes_start_req(void *co, int64_t sector, int nb_sectors) "co %p sector %" PRIx64 " nb_sectors %d" -qcow2_write_zeroes(void *co, int64_t sector, int nb_sectors) "co %p sector %" PRIx64 " nb_sectors %d" +qcow2_pwrite_zeroes_start_req(void *co, int64_t offset, int count) "co %p offset %" PRIx64 " count %d" +qcow2_pwrite_zeroes(void *co, int64_t offset, int count) "co %p offset %" PRIx64 " count %d" # block/qcow2-cluster.c qcow2_alloc_clusters_offset(void *co, uint64_t offset, int num) "co %p offset %" PRIx64 " num %d"