From patchwork Wed Jun 22 15:51:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9193207 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 0AB696075F for ; Wed, 22 Jun 2016 15:56:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEA78283EF for ; Wed, 22 Jun 2016 15:56:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E339D28408; Wed, 22 Jun 2016 15:56:27 +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 5E2D6283EF for ; Wed, 22 Jun 2016 15:56:27 +0000 (UTC) Received: from localhost ([::1]:59287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFkVt-0006jW-V9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Jun 2016 11:56:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFkRE-0002Np-U1 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 11:51:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFkR6-0002AU-Gb for qemu-devel@nongnu.org; Wed, 22 Jun 2016 11:51:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFkQx-00026R-EK; Wed, 22 Jun 2016 11:51:19 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 F3D96C0467E6; Wed, 22 Jun 2016 15:51:18 +0000 (UTC) Received: from red.redhat.com (ovpn-116-13.phx2.redhat.com [10.3.116.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5MFpGuv031046; Wed, 22 Jun 2016 11:51:18 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 22 Jun 2016 09:51:00 -0600 Message-Id: <1466610674-23157-4-git-send-email-eblake@redhat.com> In-Reply-To: <1466610674-23157-1-git-send-email-eblake@redhat.com> References: <1466610674-23157-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 22 Jun 2016 15:51:19 +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 03/17] block: Switch BlockRequest to byte-based 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, Fam Zheng , Stefan Hajnoczi , 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 BlockRequest is the internal struct used by bdrv_aio_*. At the moment, all such calls were sector-based, but we will eventually convert to byte-based; start by changing the internal variables to be byte-based. No change to behavior, although the read and write code can now go byte-based through more of the stack. Signed-off-by: Eric Blake --- block/io.c | 64 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/block/io.c b/block/io.c index 305e5c5..d442ce7 100644 --- a/block/io.c +++ b/block/io.c @@ -33,14 +33,13 @@ #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */ -static BlockAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs, - int64_t sector_num, - QEMUIOVector *qiov, - int nb_sectors, - BdrvRequestFlags flags, - BlockCompletionFunc *cb, - void *opaque, - bool is_write); +static BlockAIOCB *bdrv_co_aio_prw_vector(BlockDriverState *bs, + int64_t offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags, + BlockCompletionFunc *cb, + void *opaque, + bool is_write); static void coroutine_fn bdrv_co_do_rw(void *opaque); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int count, BdrvRequestFlags flags); @@ -2010,8 +2009,9 @@ BlockAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num, { trace_bdrv_aio_readv(bs, sector_num, nb_sectors, opaque); - return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors, 0, - cb, opaque, false); + assert(nb_sectors << BDRV_SECTOR_BITS == qiov->size); + return bdrv_co_aio_prw_vector(bs, sector_num << BDRV_SECTOR_BITS, qiov, 0, + cb, opaque, false); } BlockAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, @@ -2020,8 +2020,9 @@ BlockAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, { trace_bdrv_aio_writev(bs, sector_num, nb_sectors, opaque); - return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors, 0, - cb, opaque, true); + assert(nb_sectors << BDRV_SECTOR_BITS == qiov->size); + return bdrv_co_aio_prw_vector(bs, sector_num << BDRV_SECTOR_BITS, qiov, 0, + cb, opaque, true); } void bdrv_aio_cancel(BlockAIOCB *acb) @@ -2057,8 +2058,8 @@ typedef struct BlockRequest { union { /* Used during read, write, trim */ struct { - int64_t sector; - int nb_sectors; + int64_t offset; + int bytes; int flags; QEMUIOVector *qiov; }; @@ -2122,24 +2123,23 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque) BlockDriverState *bs = acb->common.bs; if (!acb->is_write) { - acb->req.error = bdrv_co_do_readv(bs, acb->req.sector, - acb->req.nb_sectors, acb->req.qiov, acb->req.flags); + acb->req.error = bdrv_co_preadv(bs, acb->req.offset, + acb->req.qiov->size, acb->req.qiov, acb->req.flags); } else { - acb->req.error = bdrv_co_do_writev(bs, acb->req.sector, - acb->req.nb_sectors, acb->req.qiov, acb->req.flags); + acb->req.error = bdrv_co_pwritev(bs, acb->req.offset, + acb->req.qiov->size, acb->req.qiov, acb->req.flags); } bdrv_co_complete(acb); } -static BlockAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs, - int64_t sector_num, - QEMUIOVector *qiov, - int nb_sectors, - BdrvRequestFlags flags, - BlockCompletionFunc *cb, - void *opaque, - bool is_write) +static BlockAIOCB *bdrv_co_aio_prw_vector(BlockDriverState *bs, + int64_t offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags, + BlockCompletionFunc *cb, + void *opaque, + bool is_write) { Coroutine *co; BlockAIOCBCoroutine *acb; @@ -2147,8 +2147,7 @@ static BlockAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs, acb = qemu_aio_get(&bdrv_em_co_aiocb_info, bs, cb, opaque); acb->need_bh = true; acb->req.error = -EINPROGRESS; - acb->req.sector = sector_num; - acb->req.nb_sectors = nb_sectors; + acb->req.offset = offset; acb->req.qiov = qiov; acb->req.flags = flags; acb->is_write = is_write; @@ -2193,8 +2192,8 @@ static void coroutine_fn bdrv_aio_discard_co_entry(void *opaque) BlockAIOCBCoroutine *acb = opaque; BlockDriverState *bs = acb->common.bs; - acb->req.error = bdrv_co_pdiscard(bs, acb->req.sector << BDRV_SECTOR_BITS, - acb->req.nb_sectors << BDRV_SECTOR_BITS); + acb->req.error = bdrv_co_pdiscard(bs, acb->req.offset, + acb->req.qiov->size); bdrv_co_complete(acb); } @@ -2204,14 +2203,15 @@ BlockAIOCB *bdrv_aio_discard(BlockDriverState *bs, { Coroutine *co; BlockAIOCBCoroutine *acb; + QEMUIOVector qiov = { .size = nb_sectors << BDRV_SECTOR_BITS, }; trace_bdrv_aio_discard(bs, sector_num, nb_sectors, opaque); acb = qemu_aio_get(&bdrv_em_co_aiocb_info, bs, cb, opaque); acb->need_bh = true; acb->req.error = -EINPROGRESS; - acb->req.sector = sector_num; - acb->req.nb_sectors = nb_sectors; + acb->req.offset = sector_num << BDRV_SECTOR_BITS; + acb->req.qiov = &qiov; co = qemu_coroutine_create(bdrv_aio_discard_co_entry); qemu_coroutine_enter(co, acb);