summaryrefslogtreecommitdiffstats
path: root/iothread.c
diff options
context:
space:
mode:
authorFam Zheng2016-09-08 11:28:51 +0200
committerStefan Hajnoczi2016-09-13 12:00:57 +0200
commitdce8921b2baaf95974af8176406881872067adfa (patch)
treee5bbd415db55d1ceb20e5f1f7f8d55ff5dc8a194 /iothread.c
parenttests: fix qvirtqueue_kick (diff)
downloadqemu-dce8921b2baaf95974af8176406881872067adfa.tar.gz
qemu-dce8921b2baaf95974af8176406881872067adfa.tar.xz
qemu-dce8921b2baaf95974af8176406881872067adfa.zip
iothread: Stop threads before main() quits
Right after main_loop ends, we release various things but keep iothread alive. The latter is not prepared to the sudden change of resources. Specifically, after bdrv_close_all(), virtio-scsi dataplane get a surprise at the empty BlockBackend: (gdb) bt at /usr/src/debug/qemu-2.6.0/hw/scsi/virtio-scsi.c:543 at /usr/src/debug/qemu-2.6.0/hw/scsi/virtio-scsi.c:577 It is because the d->conf.blk->root is set to NULL, then blk_get_aio_context() returns qemu_aio_context, whereas s->ctx is still pointing to the iothread: hw/scsi/virtio-scsi.c:543: if (s->dataplane_started) { assert(blk_get_aio_context(d->conf.blk) == s->ctx); } To fix this, let's stop iothreads before doing bdrv_close_all(). Cc: qemu-stable@nongnu.org Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1473326931-9699-1-git-send-email-famz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'iothread.c')
-rw-r--r--iothread.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/iothread.c b/iothread.c
index f183d380e6..fb08a60b4b 100644
--- a/iothread.c
+++ b/iothread.c
@@ -54,16 +54,25 @@ static void *iothread_run(void *opaque)
return NULL;
}
-static void iothread_instance_finalize(Object *obj)
+static int iothread_stop(Object *object, void *opaque)
{
- IOThread *iothread = IOTHREAD(obj);
+ IOThread *iothread;
- if (!iothread->ctx) {
- return;
+ iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD);
+ if (!iothread || !iothread->ctx) {
+ return 0;
}
iothread->stopping = true;
aio_notify(iothread->ctx);
qemu_thread_join(&iothread->thread);
+ return 0;
+}
+
+static void iothread_instance_finalize(Object *obj)
+{
+ IOThread *iothread = IOTHREAD(obj);
+
+ iothread_stop(obj, NULL);
qemu_cond_destroy(&iothread->init_done_cond);
qemu_mutex_destroy(&iothread->init_done_lock);
aio_context_unref(iothread->ctx);
@@ -174,3 +183,10 @@ IOThreadInfoList *qmp_query_iothreads(Error **errp)
object_child_foreach(container, query_one_iothread, &prev);
return head;
}
+
+void iothread_stop_all(void)
+{
+ Object *container = object_get_objects_root();
+
+ object_child_foreach(container, iothread_stop, NULL);
+}