aboutsummaryrefslogtreecommitdiff
path: root/aio.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2009-10-22 17:54:36 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-27 12:28:59 -0500
commit8febfa26846e75d38848255028dfe2d06e5ba941 (patch)
treea1f01f36d5dfcf3b437b323540bb844fd9825f16 /aio.c
parent59c7b155aa6e1cbfe8a92e2322ea59ab31965c10 (diff)
downloadqemu-8febfa26846e75d38848255028dfe2d06e5ba941.zip
qemu-8febfa26846e75d38848255028dfe2d06e5ba941.tar.gz
qemu-8febfa26846e75d38848255028dfe2d06e5ba941.tar.bz2
Add qemu_aio_process_queue()
We'll leave some AIO completions unhandled when we can't call the callback. qemu_aio_process_queue() is used later to run any callbacks that are left and can be run then. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'aio.c')
-rw-r--r--aio.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/aio.c b/aio.c
index da18443..f164a47 100644
--- a/aio.c
+++ b/aio.c
@@ -33,6 +33,7 @@ struct AioHandler
IOHandler *io_read;
IOHandler *io_write;
AioFlushHandler *io_flush;
+ AioProcessQueue *io_process_queue;
int deleted;
void *opaque;
QLIST_ENTRY(AioHandler) node;
@@ -55,6 +56,7 @@ int qemu_aio_set_fd_handler(int fd,
IOHandler *io_read,
IOHandler *io_write,
AioFlushHandler *io_flush,
+ AioProcessQueue *io_process_queue,
void *opaque)
{
AioHandler *node;
@@ -87,6 +89,7 @@ int qemu_aio_set_fd_handler(int fd,
node->io_read = io_read;
node->io_write = io_write;
node->io_flush = io_flush;
+ node->io_process_queue = io_process_queue;
node->opaque = opaque;
}
@@ -115,6 +118,26 @@ void qemu_aio_flush(void)
} while (qemu_bh_poll() || ret > 0);
}
+int qemu_aio_process_queue(void)
+{
+ AioHandler *node;
+ int ret = 0;
+
+ walking_handlers = 1;
+
+ QLIST_FOREACH(node, &aio_handlers, node) {
+ if (node->io_process_queue) {
+ if (node->io_process_queue(node->opaque)) {
+ ret = 1;
+ }
+ }
+ }
+
+ walking_handlers = 0;
+
+ return ret;
+}
+
void qemu_aio_wait(void)
{
int ret;
@@ -122,6 +145,13 @@ void qemu_aio_wait(void)
if (qemu_bh_poll())
return;
+ /*
+ * If there are callbacks left that have been queued, we need to call then.
+ * Return afterwards to avoid waiting needlessly in select().
+ */
+ if (qemu_aio_process_queue())
+ return;
+
do {
AioHandler *node;
fd_set rdfds, wrfds;