Blame SOURCES/kvm-iothread-delay-the-context-release-to-finalize.patch

4a2fec
From 38a2a92899b4f351cb7f4c002428a064819a565a Mon Sep 17 00:00:00 2001
4a2fec
From: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Date: Fri, 22 Dec 2017 11:08:47 +0100
4a2fec
Subject: [PATCH 29/42] iothread: delay the context release to finalize
4a2fec
4a2fec
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Message-id: <20171222110900.24813-8-stefanha@redhat.com>
4a2fec
Patchwork-id: 78489
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 07/20] iothread: delay the context release to finalize
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
When gcontext is used with iothread, the context will be destroyed
4a2fec
during iothread_stop().  That's not good since sometimes we would like
4a2fec
to keep the resources until iothread is destroyed, but we may want to
4a2fec
stop the thread before that point.
4a2fec
4a2fec
Delay the destruction of gcontext to iothread finalize.  Then we can do:
4a2fec
4a2fec
  iothread_stop(thread);
4a2fec
  some_cleanup_on_resources();
4a2fec
  iothread_destroy(thread);
4a2fec
4a2fec
We may need this patch if we want to run chardev IOs in iothreads and
4a2fec
hopefully clean them up correctly.  For more specific information,
4a2fec
please see 2b316774f6 ("qemu-char: do not operate on sources from
4a2fec
finalize callbacks").
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-5-peterx@redhat.com
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
(cherry picked from commit 5b3ac23fee97fc1a79ad2bb1cf3a1ce518d27905)
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 iothread.c | 6 ++++--
4a2fec
 1 file changed, 4 insertions(+), 2 deletions(-)
4a2fec
4a2fec
diff --git a/iothread.c b/iothread.c
4a2fec
index b3c092b..27a4288 100644
4a2fec
--- a/iothread.c
4a2fec
+++ b/iothread.c
4a2fec
@@ -71,8 +71,6 @@ static void *iothread_run(void *opaque)
4a2fec
             g_main_loop_unref(loop);
4a2fec
 
4a2fec
             g_main_context_pop_thread_default(iothread->worker_context);
4a2fec
-            g_main_context_unref(iothread->worker_context);
4a2fec
-            iothread->worker_context = NULL;
4a2fec
         }
4a2fec
     }
4a2fec
 
4a2fec
@@ -117,6 +115,10 @@ static void iothread_instance_finalize(Object *obj)
4a2fec
     IOThread *iothread = IOTHREAD(obj);
4a2fec
 
4a2fec
     iothread_stop(iothread);
4a2fec
+    if (iothread->worker_context) {
4a2fec
+        g_main_context_unref(iothread->worker_context);
4a2fec
+        iothread->worker_context = NULL;
4a2fec
+    }
4a2fec
     qemu_cond_destroy(&iothread->init_done_cond);
4a2fec
     qemu_mutex_destroy(&iothread->init_done_lock);
4a2fec
     if (!iothread->ctx) {
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec