|
|
9bac43 |
From 903416521c130289b769af87a70e19c2bbbff3aa Mon Sep 17 00:00:00 2001
|
|
|
9bac43 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
Date: Fri, 22 Dec 2017 11:08:46 +0100
|
|
|
9bac43 |
Subject: [PATCH 28/42] iothread: export iothread_stop()
|
|
|
9bac43 |
|
|
|
9bac43 |
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
Message-id: <20171222110900.24813-7-stefanha@redhat.com>
|
|
|
9bac43 |
Patchwork-id: 78488
|
|
|
9bac43 |
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 06/20] iothread: export iothread_stop()
|
|
|
9bac43 |
Bugzilla: 1519721
|
|
|
9bac43 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
From: Peter Xu <peterx@redhat.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
So that internal iothread users can explicitly stop one iothread without
|
|
|
9bac43 |
destroying it.
|
|
|
9bac43 |
|
|
|
9bac43 |
Since at it, fix iothread_stop() to allow it to be called multiple
|
|
|
9bac43 |
times. Before this patch we may call iothread_stop() more than once on
|
|
|
9bac43 |
single iothread, while that may not be correct since qemu_thread_join()
|
|
|
9bac43 |
is not allowed to run twice. From manual of pthread_join():
|
|
|
9bac43 |
|
|
|
9bac43 |
Joining with a thread that has previously been joined results in
|
|
|
9bac43 |
undefined behavior.
|
|
|
9bac43 |
|
|
|
9bac43 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
9bac43 |
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Peter Xu <peterx@redhat.com>
|
|
|
9bac43 |
Message-id: 20170928025958.1420-4-peterx@redhat.com
|
|
|
9bac43 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
(cherry picked from commit 82d90705fe203cc6e150c10bd61f0dbe6979e8f4)
|
|
|
9bac43 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
---
|
|
|
9bac43 |
include/sysemu/iothread.h | 1 +
|
|
|
9bac43 |
iothread.c | 24 ++++++++++++++++--------
|
|
|
9bac43 |
2 files changed, 17 insertions(+), 8 deletions(-)
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h
|
|
|
9bac43 |
index b07663f..110329b 100644
|
|
|
9bac43 |
--- a/include/sysemu/iothread.h
|
|
|
9bac43 |
+++ b/include/sysemu/iothread.h
|
|
|
9bac43 |
@@ -52,6 +52,7 @@ GMainContext *iothread_get_g_main_context(IOThread *iothread);
|
|
|
9bac43 |
* "query-iothreads".
|
|
|
9bac43 |
*/
|
|
|
9bac43 |
IOThread *iothread_create(const char *id, Error **errp);
|
|
|
9bac43 |
+void iothread_stop(IOThread *iothread);
|
|
|
9bac43 |
void iothread_destroy(IOThread *iothread);
|
|
|
9bac43 |
|
|
|
9bac43 |
#endif /* IOTHREAD_H */
|
|
|
9bac43 |
diff --git a/iothread.c b/iothread.c
|
|
|
9bac43 |
index 0672a91..b3c092b 100644
|
|
|
9bac43 |
--- a/iothread.c
|
|
|
9bac43 |
+++ b/iothread.c
|
|
|
9bac43 |
@@ -80,13 +80,10 @@ static void *iothread_run(void *opaque)
|
|
|
9bac43 |
return NULL;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
-static int iothread_stop(Object *object, void *opaque)
|
|
|
9bac43 |
+void iothread_stop(IOThread *iothread)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
- IOThread *iothread;
|
|
|
9bac43 |
-
|
|
|
9bac43 |
- iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD);
|
|
|
9bac43 |
- if (!iothread || !iothread->ctx || iothread->stopping) {
|
|
|
9bac43 |
- return 0;
|
|
|
9bac43 |
+ if (!iothread->ctx || iothread->stopping) {
|
|
|
9bac43 |
+ return;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
iothread->stopping = true;
|
|
|
9bac43 |
aio_notify(iothread->ctx);
|
|
|
9bac43 |
@@ -94,6 +91,17 @@ static int iothread_stop(Object *object, void *opaque)
|
|
|
9bac43 |
g_main_loop_quit(iothread->main_loop);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
qemu_thread_join(&iothread->thread);
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static int iothread_stop_iter(Object *object, void *opaque)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ IOThread *iothread;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD);
|
|
|
9bac43 |
+ if (!iothread) {
|
|
|
9bac43 |
+ return 0;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ iothread_stop(iothread);
|
|
|
9bac43 |
return 0;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
@@ -108,7 +116,7 @@ static void iothread_instance_finalize(Object *obj)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
IOThread *iothread = IOTHREAD(obj);
|
|
|
9bac43 |
|
|
|
9bac43 |
- iothread_stop(obj, NULL);
|
|
|
9bac43 |
+ iothread_stop(iothread);
|
|
|
9bac43 |
qemu_cond_destroy(&iothread->init_done_cond);
|
|
|
9bac43 |
qemu_mutex_destroy(&iothread->init_done_lock);
|
|
|
9bac43 |
if (!iothread->ctx) {
|
|
|
9bac43 |
@@ -328,7 +336,7 @@ void iothread_stop_all(void)
|
|
|
9bac43 |
aio_context_release(ctx);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
- object_child_foreach(container, iothread_stop, NULL);
|
|
|
9bac43 |
+ object_child_foreach(container, iothread_stop_iter, NULL);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
static gpointer iothread_g_main_context_init(gpointer opaque)
|
|
|
9bac43 |
--
|
|
|
9bac43 |
1.8.3.1
|
|
|
9bac43 |
|