Blame SOURCES/kvm-iothread-export-iothread_stop.patch

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