From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:51242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RHJSO-0001zW-0f for qemu-devel@nongnu.org; Fri, 21 Oct 2011 14:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RHJSL-0004cB-15 for qemu-devel@nongnu.org; Fri, 21 Oct 2011 14:04:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RHJSK-0004bw-MX for qemu-devel@nongnu.org; Fri, 21 Oct 2011 14:04:32 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9LI4U5x006208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Oct 2011 14:04:31 -0400 From: Kevin Wolf Date: Fri, 21 Oct 2011 19:08:31 +0200 Message-Id: <1319216912-26964-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1319216912-26964-1-git-send-email-kwolf@redhat.com> References: <1319216912-26964-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] raw-posix: Convert to bdrv_co_flush List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, avi@redhat.com The next patch will introduce an early return. Using a bottom half to invoke the AIO callback wouldn't be much less code, so let's go with the native block layer interface. Signed-off-by: Kevin Wolf --- block/raw-posix.c | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 40 insertions(+), 13 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index a3de373..dcae88a 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -357,15 +357,42 @@ static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs, cb, opaque, QEMU_AIO_WRITE); } -static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs, - BlockDriverCompletionFunc *cb, void *opaque) +typedef struct CoroutineIOCompletion { + Coroutine *coroutine; + int ret; +} CoroutineIOCompletion; + +static void raw_aio_flush_cb(void *opaque, int ret) +{ + CoroutineIOCompletion *co = opaque; + + co->ret = ret; + qemu_coroutine_enter(co->coroutine, NULL); +} + +static int raw_co_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; + BlockDriverAIOCB *acb; + int ret; - if (fd_open(bs) < 0) - return NULL; + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; - return paio_submit(bs, s->fd, 0, NULL, 0, cb, opaque, QEMU_AIO_FLUSH); + ret = fd_open(bs); + if (ret < 0) { + return ret; + } + + acb = paio_submit(bs, s->fd, 0, NULL, 0, raw_aio_flush_cb, &co, QEMU_AIO_FLUSH); + if (acb == NULL) { + return -EIO; + } + + qemu_coroutine_yield(); + + return co.ret; } static void raw_close(BlockDriverState *bs) @@ -635,9 +662,9 @@ static BlockDriver bdrv_file = { .bdrv_create = raw_create, .bdrv_co_discard = raw_co_discard, - .bdrv_aio_readv = raw_aio_readv, + .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, - .bdrv_aio_flush = raw_aio_flush, + .bdrv_co_flush = raw_co_flush, .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, @@ -903,9 +930,9 @@ static BlockDriver bdrv_host_device = { .create_options = raw_create_options, .bdrv_has_zero_init = hdev_has_zero_init, - .bdrv_aio_readv = raw_aio_readv, - .bdrv_aio_writev = raw_aio_writev, - .bdrv_aio_flush = raw_aio_flush, + .bdrv_aio_readv = raw_aio_readv, + .bdrv_aio_writev = raw_aio_writev, + .bdrv_co_flush = raw_co_flush, .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, @@ -1024,7 +1051,7 @@ static BlockDriver bdrv_host_floppy = { .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, - .bdrv_aio_flush = raw_aio_flush, + .bdrv_co_flush = raw_co_flush, .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, @@ -1123,7 +1150,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, - .bdrv_aio_flush = raw_aio_flush, + .bdrv_co_flush = raw_co_flush, .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, @@ -1242,7 +1269,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, - .bdrv_aio_flush = raw_aio_flush, + .bdrv_co_flush = raw_co_flush, .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, -- 1.7.6.4