From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56946 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PgZnD-00036H-On for qemu-devel@nongnu.org; Sat, 22 Jan 2011 04:30:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PgZnA-0001mq-H2 for qemu-devel@nongnu.org; Sat, 22 Jan 2011 04:29:59 -0500 Received: from mtagate1.uk.ibm.com ([194.196.100.161]:56680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PgZnA-0001mL-4g for qemu-devel@nongnu.org; Sat, 22 Jan 2011 04:29:56 -0500 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p0M9TtB2021923 for ; Sat, 22 Jan 2011 09:29:55 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0M9TwJG1593506 for ; Sat, 22 Jan 2011 09:29:58 GMT Received: from d06av07.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0M9TsdL028225 for ; Sat, 22 Jan 2011 02:29:55 -0700 From: Stefan Hajnoczi Date: Sat, 22 Jan 2011 09:29:24 +0000 Message-Id: <1295688567-25496-10-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1295688567-25496-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1295688567-25496-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC][PATCH 09/12] block: Add bdrv_co_readv() and bdrv_co_writev() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi Add coroutine versions of the bdrv_aio_readv() and bdrv_aio_writev() functions. The coroutine version doesn't take a callback and simply returns the error value. Behind the scenes they are implemented using bdrv_aio_readv() and bdrv_aio_writev(). Signed-off-by: Stefan Hajnoczi --- block.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ block.h | 7 +++++++ 2 files changed, 58 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index ff2795b..ecb6538 100644 --- a/block.c +++ b/block.c @@ -2614,6 +2614,57 @@ void qemu_aio_release(void *p) } /**************************************************************/ +/* I/O for coroutines */ + +typedef struct CoroutineIOCompletion { + Coroutine *coroutine; + int ret; +} CoroutineIOCompletion; + +static void bdrv_co_complete(void *opaque, int ret) +{ + CoroutineIOCompletion *co = opaque; + + co->ret = ret; + qemu_coroutine_enter(co->coroutine, NULL); +} + +static int coroutine_fn bdrv_co_io(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *iov, int nb_sectors, + int is_write) +{ + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + BlockDriverAIOCB *acb; + + if (is_write) { + acb = bdrv_aio_writev(bs, sector_num, iov, nb_sectors, + bdrv_co_complete, &co); + } else { + acb = bdrv_aio_readv(bs, sector_num, iov, nb_sectors, + bdrv_co_complete, &co); + } + if (!acb) { + return -EIO; + } + qemu_coroutine_yield(NULL); + return co.ret; +} + +int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *iov, int nb_sectors) +{ + return bdrv_co_io(bs, sector_num, iov, nb_sectors, 0); +} + +int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *iov, int nb_sectors) +{ + return bdrv_co_io(bs, sector_num, iov, nb_sectors, 1); +} + +/**************************************************************/ /* removable device support */ /** diff --git a/block.h b/block.h index f923add..472e3d4 100644 --- a/block.h +++ b/block.h @@ -4,6 +4,7 @@ #include "qemu-aio.h" #include "qemu-common.h" #include "qemu-option.h" +#include "qemu-coroutine.h" #include "qobject.h" /* block.c */ @@ -120,6 +121,12 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); void bdrv_aio_cancel(BlockDriverAIOCB *acb); +/* block I/O for coroutines */ +int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *iov, int nb_sectors); +int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *iov, int nb_sectors); + typedef struct BlockRequest { /* Fields to be filled by multiwrite caller */ int64_t sector; -- 1.7.2.3