@@ -33,6 +33,7 @@ struct IOThread {
bool stopping; /* has iothread_stop() been called? */
bool running; /* should iothread_run() continue? */
int thread_id;
+ char *g_source_name;
/* AioContext poll parameters */
int64_t poll_max_ns;
@@ -67,7 +67,14 @@ static void *iothread_run(void *opaque)
* changed in previous aio_poll()
*/
if (iothread->running && qatomic_read(&iothread->run_gcontext)) {
+ GSource *source = aio_get_g_source(iothread->ctx);
+
+ g_source_set_name(source, iothread->g_source_name);
+ g_source_attach(source, iothread->worker_context);
+ g_source_unref(source);
+
g_main_loop_run(iothread->main_loop);
+ assert(!iothread->running);
}
}
@@ -136,18 +143,14 @@ static void iothread_instance_finalize(Object *obj)
iothread->main_loop = NULL;
}
qemu_sem_destroy(&iothread->init_done_sem);
+
+ g_free(iothread->g_source_name);
+ iothread->g_source_name = NULL;
}
-static void iothread_init_gcontext(IOThread *iothread, const char *thread_name)
+static void iothread_init_gcontext(IOThread *iothread)
{
- GSource *source;
- g_autofree char *name = g_strdup_printf("%s aio-context", thread_name);
-
iothread->worker_context = g_main_context_new();
- source = aio_get_g_source(iothread_get_aio_context(iothread));
- g_source_set_name(source, name);
- g_source_attach(source, iothread->worker_context);
- g_source_unref(source);
iothread->main_loop = g_main_loop_new(iothread->worker_context, TRUE);
}
@@ -192,12 +195,13 @@ static void iothread_init(EventLoopBase *base, Error **errp)
thread_name = g_strdup_printf("IO %s",
object_get_canonical_path_component(OBJECT(base)));
+ iothread->g_source_name = g_strdup_printf("%s aio-context", thread_name);
/*
* Init one GMainContext for the iothread unconditionally, even if
* it's not used
*/
- iothread_init_gcontext(iothread, thread_name);
+ iothread_init_gcontext(iothread);
iothread_set_aio_context_params(base, &local_error);
if (local_error) {
Getting the GSource for the AioContext stops fdmon-io_uring from working because it is not compatible with the glib event loop. Defer the GSource code until the glib event loop is actually used. For typical IOThreads this may never be the case and we can use fdmon-io_uring. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> --- include/system/iothread.h | 1 + iothread.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-)