From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, avi@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] raw-posix: Convert to bdrv_co_flush
Date: Fri, 21 Oct 2011 19:08:31 +0200 [thread overview]
Message-ID: <1319216912-26964-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1319216912-26964-1-git-send-email-kwolf@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 <kwolf@redhat.com>
---
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
next prev parent reply other threads:[~2011-10-21 18:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-21 17:08 [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe Kevin Wolf
2011-10-21 17:08 ` Kevin Wolf [this message]
2011-10-21 17:08 ` [Qemu-devel] [PATCH 2/2] block: Handle cache=unsafe only in raw-posix/win32 Kevin Wolf
2011-10-21 18:44 ` [Qemu-devel] [PATCH 0/2] block: Write out internal caches even with cache=unsafe Paolo Bonzini
2011-10-22 15:07 ` Alexander Graf
2011-10-23 14:33 ` Paolo Bonzini
2011-10-24 8:05 ` Kevin Wolf
2011-10-24 7:37 ` Kevin Wolf
2011-10-24 7:53 ` Paolo Bonzini
2011-10-24 8:17 ` Kevin Wolf
2011-10-24 8:47 ` Paolo Bonzini
2011-10-24 8:54 ` Kevin Wolf
2011-10-24 9:26 ` Paolo Bonzini
2011-10-24 9:36 ` Kevin Wolf
2011-10-24 9:40 ` Paolo Bonzini
2011-10-24 9:53 ` Kevin Wolf
2011-10-24 10:08 ` Paolo Bonzini
2011-10-24 9:09 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1319216912-26964-2-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.