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

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