From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v2 19/39] aio: add I/O handlers to the AioContext interface
Date: Wed, 31 Oct 2012 16:30:36 +0100 [thread overview]
Message-ID: <1351697456-16107-20-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1351697456-16107-1-git-send-email-pbonzini@redhat.com>
With this patch, I/O handlers (including event notifier handlers) can be
attached to a single AioContext.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
aio.c | 68 ++++++++++++++++++++++++-------------------------------------
async.c | 6 ++++++
main-loop.c | 33 ++++++++++++++++++++++++++++++
qemu-aio.h | 42 +++++++++++++++++++++++++++++++-------
4 file modificati, 101 inserzioni(+), 48 rimozioni(-)
diff --git a/aio.c b/aio.c
index 7e3fe70..c89f1e9 100644
--- a/aio.c
+++ b/aio.c
@@ -18,15 +18,6 @@
#include "qemu-queue.h"
#include "qemu_socket.h"
-/* The list of registered AIO handlers */
-static QLIST_HEAD(, AioHandler) aio_handlers;
-
-/* This is a simple lock used to protect the aio_handlers list. Specifically,
- * it's used to ensure that no callbacks are removed while we're walking and
- * dispatching callbacks.
- */
-static int walking_handlers;
-
struct AioHandler
{
int fd;
@@ -38,11 +29,11 @@ struct AioHandler
QLIST_ENTRY(AioHandler) node;
};
-static AioHandler *find_aio_handler(int fd)
+static AioHandler *find_aio_handler(AioContext *ctx, int fd)
{
AioHandler *node;
- QLIST_FOREACH(node, &aio_handlers, node) {
+ QLIST_FOREACH(node, &ctx->aio_handlers, node) {
if (node->fd == fd)
if (!node->deleted)
return node;
@@ -51,21 +42,22 @@ static AioHandler *find_aio_handler(int fd)
return NULL;
}
-void qemu_aio_set_fd_handler(int fd,
- IOHandler *io_read,
- IOHandler *io_write,
- AioFlushHandler *io_flush,
- void *opaque)
+void aio_set_fd_handler(AioContext *ctx,
+ int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ AioFlushHandler *io_flush,
+ void *opaque)
{
AioHandler *node;
- node = find_aio_handler(fd);
+ node = find_aio_handler(ctx, fd);
/* Are we deleting the fd handler? */
if (!io_read && !io_write) {
if (node) {
/* If the lock is held, just mark the node as deleted */
- if (walking_handlers)
+ if (ctx->walking_handlers)
node->deleted = 1;
else {
/* Otherwise, delete it for real. We can't just mark it as
@@ -81,7 +73,7 @@ void qemu_aio_set_fd_handler(int fd,
/* Alloc and insert if it's not already there */
node = g_malloc0(sizeof(AioHandler));
node->fd = fd;
- QLIST_INSERT_HEAD(&aio_handlers, node, node);
+ QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);
}
/* Update handler with latest information */
node->io_read = io_read;
@@ -89,25 +81,19 @@ void qemu_aio_set_fd_handler(int fd,
node->io_flush = io_flush;
node->opaque = opaque;
}
-
- qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
-}
-
-void qemu_aio_set_event_notifier(EventNotifier *notifier,
- EventNotifierHandler *io_read,
- AioFlushEventNotifierHandler *io_flush)
-{
- qemu_aio_set_fd_handler(event_notifier_get_fd(notifier),
- (IOHandler *)io_read, NULL,
- (AioFlushHandler *)io_flush, notifier);
}
-void qemu_aio_flush(void)
+void aio_set_event_notifier(AioContext *ctx,
+ EventNotifier *notifier,
+ EventNotifierHandler *io_read,
+ AioFlushEventNotifierHandler *io_flush)
{
- while (qemu_aio_wait());
+ aio_set_fd_handler(ctx, event_notifier_get_fd(notifier),
+ (IOHandler *)io_read, NULL,
+ (AioFlushHandler *)io_flush, notifier);
}
-bool qemu_aio_wait(void)
+bool aio_wait(AioContext *ctx)
{
AioHandler *node;
fd_set rdfds, wrfds;
@@ -120,18 +106,18 @@ bool qemu_aio_wait(void)
* 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 (qemu_bh_poll()) {
+ if (aio_bh_poll(ctx)) {
return true;
}
- walking_handlers++;
+ ctx->walking_handlers++;
FD_ZERO(&rdfds);
FD_ZERO(&wrfds);
/* fill fd sets */
busy = false;
- QLIST_FOREACH(node, &aio_handlers, node) {
+ QLIST_FOREACH(node, &ctx->aio_handlers, node) {
/* If there aren't pending AIO operations, don't invoke callbacks.
* Otherwise, if there are no AIO requests, qemu_aio_wait() would
* wait indefinitely.
@@ -152,7 +138,7 @@ bool qemu_aio_wait(void)
}
}
- walking_handlers--;
+ ctx->walking_handlers--;
/* No AIO operations? Get us out of here */
if (!busy) {
@@ -166,11 +152,11 @@ bool qemu_aio_wait(void)
if (ret > 0) {
/* we have to walk very carefully in case
* qemu_aio_set_fd_handler is called while we're walking */
- node = QLIST_FIRST(&aio_handlers);
+ node = QLIST_FIRST(&ctx->aio_handlers);
while (node) {
AioHandler *tmp;
- walking_handlers++;
+ ctx->walking_handlers++;
if (!node->deleted &&
FD_ISSET(node->fd, &rdfds) &&
@@ -186,9 +172,9 @@ bool qemu_aio_wait(void)
tmp = node;
node = QLIST_NEXT(node, node);
- walking_handlers--;
+ ctx->walking_handlers--;
- if (!walking_handlers && tmp->deleted) {
+ if (!ctx->walking_handlers && tmp->deleted) {
QLIST_REMOVE(tmp, node);
g_free(tmp);
}
diff --git a/async.c b/async.c
index 189ee1b..c99db79 100644
--- a/async.c
+++ b/async.c
@@ -136,7 +136,13 @@ void aio_bh_update_timeout(AioContext *ctx, uint32_t *timeout)
}
}
+
AioContext *aio_context_new(void)
{
return g_new0(AioContext, 1);
}
+
+void aio_flush(AioContext *ctx)
+{
+ while (aio_wait(ctx));
+}
diff --git a/main-loop.c b/main-loop.c
index 40fdbd3..8f0117e 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -526,3 +526,36 @@ int qemu_bh_poll(void)
{
return aio_bh_poll(qemu_aio_context);
}
+
+void qemu_aio_flush(void)
+{
+ aio_flush(qemu_aio_context);
+}
+
+bool qemu_aio_wait(void)
+{
+ return aio_wait(qemu_aio_context);
+}
+
+void qemu_aio_set_fd_handler(int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ AioFlushHandler *io_flush,
+ void *opaque)
+{
+ aio_set_fd_handler(qemu_aio_context, fd, io_read, io_write, io_flush,
+ opaque);
+
+ qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
+}
+
+#ifdef CONFIG_POSIX
+void qemu_aio_set_event_notifier(EventNotifier *notifier,
+ EventNotifierHandler *io_read,
+ AioFlushEventNotifierHandler *io_flush)
+{
+ qemu_aio_set_fd_handler(event_notifier_get_fd(notifier),
+ (IOHandler *)io_read, NULL,
+ (AioFlushHandler *)io_flush, notifier);
+}
+#endif
diff --git a/qemu-aio.h b/qemu-aio.h
index 2ed6ad3..f8a93d8 100644
--- a/qemu-aio.h
+++ b/qemu-aio.h
@@ -15,6 +15,7 @@
#define QEMU_AIO_H
#include "qemu-common.h"
+#include "qemu-queue.h"
#include "event_notifier.h"
typedef struct BlockDriverAIOCB BlockDriverAIOCB;
@@ -43,6 +44,15 @@ typedef void QEMUBHFunc(void *opaque);
typedef void IOHandler(void *opaque);
typedef struct AioContext {
+ /* The list of registered AIO handlers */
+ QLIST_HEAD(, AioHandler) aio_handlers;
+
+ /* This is a simple lock used to protect the aio_handlers list.
+ * Specifically, it's used to ensure that no callbacks are removed while
+ * we're walking and dispatching callbacks.
+ */
+ int walking_handlers;
+
/* Anchor of the list of Bottom Halves belonging to the context */
struct QEMUBH *first_bh;
@@ -121,7 +131,7 @@ void qemu_bh_delete(QEMUBH *bh);
/* Flush any pending AIO operation. This function will block until all
* outstanding AIO operations have been completed or cancelled. */
-void qemu_aio_flush(void);
+void aio_flush(AioContext *ctx);
/* Wait for a single AIO completion to occur. This function will wait
* until a single AIO event has completed and it will ensure something
@@ -129,7 +139,7 @@ void qemu_aio_flush(void);
* result of executing I/O completion or bh callbacks.
*
* Return whether there is still any pending AIO operation. */
-bool qemu_aio_wait(void);
+bool aio_wait(AioContext *ctx);
#ifdef CONFIG_POSIX
/* Returns 1 if there are still outstanding AIO requests; 0 otherwise */
@@ -142,11 +152,12 @@ typedef int (AioFlushHandler)(void *opaque);
* Code that invokes AIO completion functions should rely on this function
* instead of qemu_set_fd_handler[2].
*/
-void qemu_aio_set_fd_handler(int fd,
- IOHandler *io_read,
- IOHandler *io_write,
- AioFlushHandler *io_flush,
- void *opaque);
+void aio_set_fd_handler(AioContext *ctx,
+ int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ AioFlushHandler *io_flush,
+ void *opaque);
#endif
/* Register an event notifier and associated callbacks. Behaves very similarly
@@ -156,8 +167,25 @@ void qemu_aio_set_fd_handler(int fd,
* Code that invokes AIO completion functions should rely on this function
* instead of event_notifier_set_handler.
*/
+void aio_set_event_notifier(AioContext *ctx,
+ EventNotifier *notifier,
+ EventNotifierHandler *io_read,
+ AioFlushEventNotifierHandler *io_flush);
+
+/* Functions to operate on the main QEMU AioContext. */
+
+void qemu_aio_flush(void);
+bool qemu_aio_wait(void);
void qemu_aio_set_event_notifier(EventNotifier *notifier,
EventNotifierHandler *io_read,
AioFlushEventNotifierHandler *io_flush);
+#ifdef CONFIG_POSIX
+void qemu_aio_set_fd_handler(int fd,
+ IOHandler *io_read,
+ IOHandler *io_write,
+ AioFlushHandler *io_flush,
+ void *opaque);
+#endif
+
#endif
--
1.7.12.1
next prev parent reply other threads:[~2012-10-31 15:32 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 15:30 [Qemu-devel] [PULL v2 00/39] AioContext, thread pool, Win32 AIO Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 01/39] janitor: move iovector functions out of cutils.c Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 02/39] build: move cutils.o and qemu-timer-common.o to oslib-obj-y Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 03/39] compiler: use weak aliases to provide default definitions Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 04/39] sockets: use weak aliases instead of qemu-tool.c Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 05/39] fdsets: use weak aliases instead of qemu-tool.c/qemu-user.c Paolo Bonzini
2012-11-15 18:01 ` Stefan Weil
2012-11-15 20:52 ` Paolo Bonzini
2012-11-15 22:18 ` Stefan Weil
2012-11-16 9:35 ` Paolo Bonzini
2012-11-16 17:15 ` Stefan Weil
2012-11-16 17:39 ` Paolo Bonzini
2012-11-16 17:52 ` Peter Maydell
2012-11-16 17:55 ` Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 06/39] iohandler: add weak alias in qemu-sockets.c, for qemu-ga Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 07/39] win32: add weak version of qemu_fd_register Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 08/39] qemu-timer: make initialization functions idempotent Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 09/39] main-loop: unify qemu_init_main_loop between QEMU and tools Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 10/39] qemu-tool: do not depend on qemu-timer.c Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 11/39] build: opts-visitor is not really part of QAPI Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 12/39] build: do not include main loop where it is not actually used Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 13/39] event_notifier: add Win32 implementation Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 14/39] event_notifier: enable it to use pipes Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 15/39] vl: init main loop earlier Paolo Bonzini
2012-11-02 7:26 ` Jan Kiszka
2012-11-02 9:55 ` Paolo Bonzini
2012-11-02 10:32 ` Jan Kiszka
2012-11-02 11:04 ` Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 16/39] aio: change qemu_aio_set_fd_handler to return void Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 17/39] aio: provide platform-independent API Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 18/39] aio: introduce AioContext, move bottom halves there Paolo Bonzini
2012-10-31 15:30 ` Paolo Bonzini [this message]
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 20/39] aio: test node->deleted before calling io_flush Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 21/39] aio: add non-blocking variant of aio_wait Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 22/39] aio: prepare for introducing GSource-based dispatch Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 23/39] aio: add Win32 implementation Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 24/39] aio: make AioContexts GSources Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 25/39] aio: add aio_notify Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 26/39] aio: call aio_notify after setting I/O handlers Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 27/39] main-loop: use GSource to poll AIO file descriptors Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 28/39] main-loop: use aio_notify for qemu_notify_event Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 29/39] aio: clean up now-unused functions Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 30/39] linux-aio: use event notifiers Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 31/39] qemu-thread: add QemuSemaphore Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 32/39] aio: add generic thread-pool facility Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 33/39] threadpool: do not take lock in event_notifier_ready Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 34/39] block: switch posix-aio-compat to threadpool Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 35/39] raw: merge posix-aio-compat.c into block/raw-posix.c Paolo Bonzini
2012-11-02 15:00 ` Peter Maydell
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 36/39] raw-posix: rename raw-posix-aio.h, hide unavailable prototypes Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 37/39] raw-win32: add emulated AIO support Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 38/39] raw-posix: move linux-aio.c to block/ Paolo Bonzini
2012-10-31 15:30 ` [Qemu-devel] [PATCH v2 39/39] raw-win32: implement native asynchronous I/O Paolo Bonzini
2012-11-21 13:20 ` Jan Kiszka
2012-11-21 13:25 ` Paolo Bonzini
2012-11-21 13:27 ` Jan Kiszka
2012-11-21 13:33 ` Paolo Bonzini
2012-11-21 13:38 ` Jan Kiszka
2012-11-22 13:34 ` Jan Kiszka
2012-11-22 15:16 ` Paolo Bonzini
2012-11-22 15:53 ` Jan Kiszka
2012-11-01 19:33 ` [Qemu-devel] [PULL v2 00/39] AioContext, thread pool, Win32 AIO Anthony Liguori
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=1351697456-16107-20-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).