]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/extra/0002-monitor-delay-monitor-iothread-creation.patch
update qemu submodule to v4.0.0
[pve-qemu.git] / debian / patches / extra / 0002-monitor-delay-monitor-iothread-creation.patch
CommitLineData
0775f12b
WB
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3Date: Tue, 25 Sep 2018 10:15:07 +0200
4Subject: [PATCH] monitor: delay monitor iothread creation
5
6Commit d32749deb615 moved the call to monitor_init_globals()
7to before os_daemonize(), making it an unsuitable place to
8spawn the monitor iothread as it won't be inherited over the
9fork() in os_daemonize().
10
11We now spawn the thread the first time we instantiate a
12monitor which actually has use_io_thread == true.
13Instantiation of monitors happens only after os_daemonize().
14We still need to create the qmp_dispatcher_bh when not using
15iothreads, so this now still happens in
16monitor_init_globals().
17
18Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
19Fixes: d32749deb615 ("monitor: move init global earlier")
20Message-Id: <20180925081507.11873-3-w.bumiller@proxmox.com>
21Reviewed-by: Eric Blake <eblake@redhat.com>
22Reviewed-by: Peter Xu <peterx@redhat.com>
23Tested-by: Peter Xu <peterx@redhat.com>
24[This fixes a crash on shutdown with --daemonize]
25Signed-off-by: Markus Armbruster <armbru@redhat.com>
26---
27 monitor.c | 36 ++++++++++++++++++++++--------------
28 1 file changed, 22 insertions(+), 14 deletions(-)
29
30diff --git a/monitor.c b/monitor.c
31index 836c0bbdaa..c7eae64fd9 100644
32--- a/monitor.c
33+++ b/monitor.c
34@@ -807,9 +807,14 @@ static void monitor_qapi_event_init(void)
35
36 static void handle_hmp_command(Monitor *mon, const char *cmdline);
37
38+static void monitor_iothread_init(void);
39+
40 static void monitor_data_init(Monitor *mon, bool skip_flush,
41 bool use_io_thread)
42 {
43+ if (use_io_thread && !mon_iothread) {
44+ monitor_iothread_init();
45+ }
46 memset(mon, 0, sizeof(Monitor));
47 qemu_mutex_init(&mon->mon_lock);
48 qemu_mutex_init(&mon->qmp.qmp_queue_lock);
49@@ -4544,6 +4549,15 @@ static AioContext *monitor_get_aio_context(void)
50 static void monitor_iothread_init(void)
51 {
52 mon_iothread = iothread_create("mon_iothread", &error_abort);
53+}
54+
55+void monitor_init_globals(void)
56+{
57+ monitor_init_qmp_commands();
58+ monitor_qapi_event_init();
59+ sortcmdlist();
60+ qemu_mutex_init(&monitor_lock);
61+ qemu_mutex_init(&mon_fdsets_lock);
62
63 /*
64 * The dispatcher BH must run in the main loop thread, since we
65@@ -4559,21 +4573,11 @@ static void monitor_iothread_init(void)
66 * monitors that are using the I/O thread have their output
67 * written by the I/O thread.
68 */
69- qmp_respond_bh = aio_bh_new(monitor_get_aio_context(),
70+ qmp_respond_bh = aio_bh_new(iohandler_get_aio_context(),
71 monitor_qmp_bh_responder,
72 NULL);
73 }
74
75-void monitor_init_globals(void)
76-{
77- monitor_init_qmp_commands();
78- monitor_qapi_event_init();
79- sortcmdlist();
80- qemu_mutex_init(&monitor_lock);
81- qemu_mutex_init(&mon_fdsets_lock);
82- monitor_iothread_init();
83-}
84-
85 /* These functions just adapt the readline interface in a typesafe way. We
86 * could cast function pointers but that discards compiler checks.
87 */
88@@ -4711,7 +4715,9 @@ void monitor_cleanup(void)
89 * we need to unregister from chardev below in
90 * monitor_data_destroy(), and chardev is not thread-safe yet
91 */
92- iothread_stop(mon_iothread);
93+ if (mon_iothread) {
94+ iothread_stop(mon_iothread);
95+ }
96
97 /*
98 * Flush all response queues. Note that even after this flush,
99@@ -4735,8 +4741,10 @@ void monitor_cleanup(void)
100 qemu_bh_delete(qmp_respond_bh);
101 qmp_respond_bh = NULL;
102
103- iothread_destroy(mon_iothread);
104- mon_iothread = NULL;
105+ if (mon_iothread) {
106+ iothread_destroy(mon_iothread);
107+ mon_iothread = NULL;
108+ }
109 }
110
111 QemuOptsList qemu_mon_opts = {
112--
1132.11.0
114