From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Fabien Chouteau <chouteau@adacore.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Amos Kong <akong@redhat.com>
Subject: [Qemu-devel] [PATCH v2 7/9] aio: extract aio_dispatch() from aio_poll()
Date: Fri, 1 Feb 2013 14:53:26 +0100 [thread overview]
Message-ID: <1359726808-11728-8-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1359726808-11728-1-git-send-email-stefanha@redhat.com>
We will need to loop over AioHandlers calling ->io_read()/->io_write()
when aio_poll() is converted from select(2) to g_poll(2).
Luckily the code for this already exists, extract it into the new
aio_dispatch() function.
Two small changes:
* aio_poll() checks !node->deleted to avoid calling handlers that have
been deleted.
* Fix typo 'then' -> 'them' in aio_poll() comment.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
aio-posix.c | 57 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 22 deletions(-)
diff --git a/aio-posix.c b/aio-posix.c
index fe4dbb4..35131a3 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -129,30 +129,12 @@ bool aio_pending(AioContext *ctx)
return false;
}
-bool aio_poll(AioContext *ctx, bool blocking)
+static bool aio_dispatch(AioContext *ctx)
{
- static struct timeval tv0;
AioHandler *node;
- fd_set rdfds, wrfds;
- int max_fd = -1;
- int ret;
- bool busy, progress;
-
- progress = false;
-
- /*
- * If there are callbacks left that have been queued, we need to call then.
- * Do not call select in this case, because it is possible that the caller
- * does not need a complete flush (as is the case for qemu_aio_wait loops).
- */
- if (aio_bh_poll(ctx)) {
- blocking = false;
- progress = true;
- }
+ bool progress = false;
/*
- * Then dispatch any pending callbacks from the GSource.
- *
* We have to walk very carefully in case qemu_aio_set_fd_handler is
* called while we're walking.
*/
@@ -167,11 +149,15 @@ bool aio_poll(AioContext *ctx, bool blocking)
node->pfd.revents = 0;
/* See comment in aio_pending. */
- if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR) && node->io_read) {
+ if (!node->deleted &&
+ (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) &&
+ node->io_read) {
node->io_read(node->opaque);
progress = true;
}
- if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write) {
+ if (!node->deleted &&
+ (revents & (G_IO_OUT | G_IO_ERR)) &&
+ node->io_write) {
node->io_write(node->opaque);
progress = true;
}
@@ -186,6 +172,33 @@ bool aio_poll(AioContext *ctx, bool blocking)
g_free(tmp);
}
}
+ return progress;
+}
+
+bool aio_poll(AioContext *ctx, bool blocking)
+{
+ static struct timeval tv0;
+ AioHandler *node;
+ fd_set rdfds, wrfds;
+ int max_fd = -1;
+ int ret;
+ bool busy, progress;
+
+ progress = false;
+
+ /*
+ * If there are callbacks left that have been queued, we need to call them.
+ * Do not call select in this case, because it is possible that the caller
+ * does not need a complete flush (as is the case for qemu_aio_wait loops).
+ */
+ if (aio_bh_poll(ctx)) {
+ blocking = false;
+ progress = true;
+ }
+
+ if (aio_dispatch(ctx)) {
+ progress = true;
+ }
if (progress && !blocking) {
return true;
--
1.8.1
next prev parent reply other threads:[~2013-02-01 13:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 13:53 [Qemu-devel] [PATCH v2 0/9] main-loop: switch to g_poll(3) on POSIX hosts Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 1/9] main-loop: fix select_ret uninitialized variable warning Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 2/9] main-loop: switch to g_poll() on POSIX hosts Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 3/9] main-loop: switch POSIX glib integration to GPollFD Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 4/9] slirp: switch " Stefan Hajnoczi
2013-02-02 12:46 ` Blue Swirl
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 5/9] iohandler: " Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 6/9] main-loop: drop rfds/wfds/xfds for good Stefan Hajnoczi
2013-02-01 13:53 ` Stefan Hajnoczi [this message]
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 8/9] aio: convert aio_poll() to g_poll(3) Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 9/9] aio: support G_IO_HUP and G_IO_ERR Stefan Hajnoczi
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=1359726808-11728-8-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=akong@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=chouteau@adacore.com \
--cc=jan.kiszka@siemens.com \
--cc=pbonzini@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).