aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2018-03-09 16:59:50 +0800
committerEric Blake <eblake@redhat.com>2018-03-19 14:58:36 -0500
commit6adf08dd42929542426b055a4b66a5bc0b8e20ba (patch)
treeee702a801d4f4ac7066994fe8d8f33354dda32c7
parent227a07552f3aff3cefe7eb9f8993c04a420ed962 (diff)
downloadqemu-6adf08dd42929542426b055a4b66a5bc0b8e20ba.zip
qemu-6adf08dd42929542426b055a4b66a5bc0b8e20ba.tar.gz
qemu-6adf08dd42929542426b055a4b66a5bc0b8e20ba.tar.bz2
monitor: unify global init
There are many places where the monitor initializes its globals: - monitor_init_qmp_commands() at the very beginning - single function to init monitor_lock - in the first entry of monitor_init() using "is_first_init" Unify them a bit. monitor_lock is not used before monitor_init() (as confirmed by code analysis and gdb watchpoints); so we are safe delaying what was a constructor-time initialization of the mutex into the later first call to monitor_init(). Reviewed-by: Fam Zheng <famz@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20180309090006.10018-8-peterx@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r--include/monitor/monitor.h2
-rw-r--r--monitor.c25
-rw-r--r--vl.c7
3 files changed, 17 insertions, 17 deletions
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index d1024d4..0cb0538 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -16,7 +16,7 @@ extern Monitor *cur_mon;
bool monitor_cur_is_qmp(void);
-void monitor_init_qmp_commands(void);
+void monitor_init_globals(void);
void monitor_init(Chardev *chr, int flags);
void monitor_cleanup(void);
diff --git a/monitor.c b/monitor.c
index 861803c..0749dc5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1006,7 +1006,7 @@ static void qmp_unregister_commands_hack(void)
#endif
}
-void monitor_init_qmp_commands(void)
+static void monitor_init_qmp_commands(void)
{
/*
* Two command lists:
@@ -3988,6 +3988,14 @@ static void sortcmdlist(void)
qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd);
}
+void monitor_init_globals(void)
+{
+ monitor_init_qmp_commands();
+ monitor_qapi_event_init();
+ sortcmdlist();
+ qemu_mutex_init(&monitor_lock);
+}
+
/* These functions just adapt the readline interface in a typesafe way. We
* could cast function pointers but that discards compiler checks.
*/
@@ -4028,23 +4036,10 @@ void error_vprintf_unless_qmp(const char *fmt, va_list ap)
}
}
-static void __attribute__((constructor)) monitor_lock_init(void)
-{
- qemu_mutex_init(&monitor_lock);
-}
-
void monitor_init(Chardev *chr, int flags)
{
- static int is_first_init = 1;
- Monitor *mon;
-
- if (is_first_init) {
- monitor_qapi_event_init();
- sortcmdlist();
- is_first_init = 0;
- }
+ Monitor *mon = g_malloc(sizeof(*mon));
- mon = g_malloc(sizeof(*mon));
monitor_data_init(mon, false);
qemu_chr_fe_init(&mon->chr, chr, &error_abort);
diff --git a/vl.c b/vl.c
index 19340a3..518ba43 100644
--- a/vl.c
+++ b/vl.c
@@ -3066,7 +3066,6 @@ int main(int argc, char **argv, char **envp)
qemu_init_exec_dir(argv[0]);
module_call_init(MODULE_INIT_QOM);
- monitor_init_qmp_commands();
qemu_add_opts(&qemu_drive_opts);
qemu_add_drive_opts(&qemu_legacy_drive_opts);
@@ -4537,6 +4536,12 @@ int main(int argc, char **argv, char **envp)
default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
+ /*
+ * Note: qtest_enabled() (which is used in monitor_qapi_event_init())
+ * depends on configure_accelerator() above.
+ */
+ monitor_init_globals();
+
if (qemu_opts_foreach(qemu_find_opts("mon"),
mon_init_func, NULL, NULL)) {
exit(1);