[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 18/36] monitor: unify global init
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 18/36] monitor: unify global init |
Date: |
Mon, 12 Mar 2018 13:36:09 -0500 |
From: Peter Xu <address@hidden>
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 <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
---
include/monitor/monitor.h | 2 +-
vl.c | 7 ++++++-
monitor.c | 25 ++++++++++---------------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index d1024d4bdc3..0cb0538a315 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/vl.c b/vl.c
index 3ef04ce991f..2e4fac7e4a0 100644
--- a/vl.c
+++ b/vl.c
@@ -3065,7 +3065,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);
@@ -4535,6 +4534,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);
diff --git a/monitor.c b/monitor.c
index 83e98741b4c..71d53be1ddd 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1003,7 +1003,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:
@@ -3985,6 +3985,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.
*/
@@ -4025,23 +4033,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;
+ Monitor *mon = g_malloc(sizeof(*mon));
- if (is_first_init) {
- monitor_qapi_event_init();
- sortcmdlist();
- is_first_init = 0;
- }
-
- mon = g_malloc(sizeof(*mon));
monitor_data_init(mon, false);
qemu_chr_fe_init(&mon->chr, chr, &error_abort);
--
2.14.3
- [Qemu-devel] [PULL 00/36] QAPI patches for 2018-03-12, 2.12 softfreeze, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 02/36] qlit: use QType instead of int, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 05/36] compiler: Add QEMU_BUILD_BUG_MSG() macro, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 08/36] qapi: Remove qobject_to_X() functions, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 06/36] qapi: Add qobject_to(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 03/36] qlit: add qobject_from_qlit(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 09/36] qapi: Make more of qobject_to(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 04/36] qapi: generate a literal qobject for introspection, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 16/36] monitor: move skip_flush into monitor_data_init, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 18/36] monitor: unify global init,
Eric Blake <=
- [Qemu-devel] [PULL 11/36] block: Deprecate "backing": "", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 17/36] monitor: move the cur_mon hack deeper for QMP, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 10/36] block: Handle null backing link, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 13/36] qobject: introduce qstring_get_try_str(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 26/36] qmp: add new event "command-dropped", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 19/36] monitor: let mon_list be tail queue, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 01/36] qapi2texi: minor python code simplification, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 12/36] docs: update QMP documents for OOB commands, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 14/36] qobject: introduce qobject_get_try_str(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 22/36] monitor: introduce monitor_qmp_respond(), Eric Blake, 2018/03/12