[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/2] raw-posix: Convert to bdrv_co_flush
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 1/2] raw-posix: Convert to bdrv_co_flush |
Date: |
Fri, 21 Oct 2011 19:08:31 +0200 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 2/2] block: Handle cache=unsafe only in raw-posix/win32, Kevin Wolf, 2011/10/21
- [Qemu-devel] [PATCH 1/2] raw-posix: Convert to bdrv_co_flush,
Kevin Wolf <=
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Paolo Bonzini, 2011/10/21
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Kevin Wolf, 2011/10/24
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Paolo Bonzini, 2011/10/24
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Kevin Wolf, 2011/10/24
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Paolo Bonzini, 2011/10/24
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Kevin Wolf, 2011/10/24
- Re: [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe, Paolo Bonzini, 2011/10/24