[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v3 14/15] monitor: Replace monitor_init() with monit
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v3 14/15] monitor: Replace monitor_init() with monitor_init_{hmp, qmp}() |
Date: |
Thu, 13 Jun 2019 17:34:04 +0200 |
Most callers know which monitor type they want to have. Instead of
calling monitor_init() with flags that can describe both types of
monitors, make monitor_init_{hmp,qmp}() public interfaces that take
specific bools instead of flags and call these functions directly.
Signed-off-by: Kevin Wolf <address@hidden>
---
include/monitor/monitor.h | 9 ++-------
monitor/monitor-internal.h | 3 ---
chardev/char.c | 2 +-
gdbstub.c | 2 +-
monitor/hmp.c | 4 ++--
monitor/monitor.c | 9 ---------
monitor/qmp.c | 7 ++-----
stubs/monitor.c | 6 +++++-
tests/test-util-sockets.c | 3 ++-
vl.c | 18 ++++++++++++------
10 files changed, 27 insertions(+), 36 deletions(-)
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index af5ddbe785..6e64f062db 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -8,19 +8,14 @@
extern __thread Monitor *cur_mon;
typedef struct MonitorHMP MonitorHMP;
-/* flags for monitor_init */
-/* 0x01 unused */
-#define MONITOR_USE_READLINE 0x02
-#define MONITOR_USE_CONTROL 0x04
-#define MONITOR_USE_PRETTY 0x08
-
#define QMP_REQ_QUEUE_LEN_MAX 8
bool monitor_cur_is_qmp(void);
void monitor_init_globals(void);
void monitor_init_globals_core(void);
-void monitor_init(Chardev *chr, int flags);
+void monitor_init_qmp(Chardev *chr, bool pretty);
+void monitor_init_hmp(Chardev *chr, bool use_readline);
void monitor_cleanup(void);
int monitor_suspend(Monitor *mon);
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index 260725e51b..333ebf89e4 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -167,9 +167,6 @@ extern int mon_refcount;
extern HMPCommand hmp_cmds[];
-void monitor_init_qmp(Chardev *chr, int flags);
-void monitor_init_hmp(Chardev *chr, int flags);
-
int monitor_puts(Monitor *mon, const char *str);
void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
bool use_io_thread);
diff --git a/chardev/char.c b/chardev/char.c
index e4887bcc82..7b6b2cb123 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -731,7 +731,7 @@ Chardev *qemu_chr_new_noreplay(const char *label, const
char *filename,
if (qemu_opt_get_bool(opts, "mux", 0)) {
assert(permit_mux_mon);
- monitor_init(chr, MONITOR_USE_READLINE);
+ monitor_init_hmp(chr, true);
}
out:
diff --git a/gdbstub.c b/gdbstub.c
index 17dcd9186d..939134eec9 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2565,7 +2565,7 @@ int gdbserver_start(const char *device)
/* Initialize a monitor terminal for gdb */
mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
NULL, NULL, &error_abort);
- monitor_init(mon_chr, 0);
+ monitor_init_hmp(mon_chr, false);
} else {
qemu_chr_fe_deinit(&s->chr, true);
mon_chr = s->mon_chr;
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 5ba8b6e8d5..43185a7445 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1393,14 +1393,14 @@ static void monitor_readline_flush(void *opaque)
monitor_flush(&mon->common);
}
-void monitor_init_hmp(Chardev *chr, int flags)
+void monitor_init_hmp(Chardev *chr, bool use_readline)
{
MonitorHMP *mon = g_malloc0(sizeof(*mon));
monitor_data_init(&mon->common, false, false, false);
qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
- mon->use_readline = flags & MONITOR_USE_READLINE;
+ mon->use_readline = use_readline;
if (mon->use_readline) {
mon->rs = readline_init(monitor_readline_printf,
monitor_readline_flush,
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 7325e4362b..01d8fb5d30 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -555,15 +555,6 @@ void monitor_data_destroy(Monitor *mon)
qemu_mutex_destroy(&mon->mon_lock);
}
-void monitor_init(Chardev *chr, int flags)
-{
- if (flags & MONITOR_USE_CONTROL) {
- monitor_init_qmp(chr, flags);
- } else {
- monitor_init_hmp(chr, flags);
- }
-}
-
void monitor_cleanup(void)
{
/*
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 3abc718ca3..7258f2b088 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -363,18 +363,15 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
monitor_list_append(&mon->common);
}
-void monitor_init_qmp(Chardev *chr, int flags)
+void monitor_init_qmp(Chardev *chr, bool pretty)
{
MonitorQMP *mon = g_malloc0(sizeof(*mon));
- /* Only HMP supports readline */
- assert(!(flags & MONITOR_USE_READLINE));
-
/* Note: we run QMP monitor in I/O thread when @chr supports that */
monitor_data_init(&mon->common, true, false,
qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
- mon->pretty = flags & MONITOR_USE_PRETTY;
+ mon->pretty = pretty;
qemu_mutex_init(&mon->qmp_queue_lock);
mon->qmp_requests = g_queue_new();
diff --git a/stubs/monitor.c b/stubs/monitor.c
index cdbf5c5f9a..c3e9a2e4dc 100644
--- a/stubs/monitor.c
+++ b/stubs/monitor.c
@@ -16,7 +16,11 @@ int monitor_get_fd(Monitor *mon, const char *name, Error
**errp)
return -1;
}
-void monitor_init(Chardev *chr, int flags)
+void monitor_init_qmp(Chardev *chr, bool pretty)
+{
+}
+
+void monitor_init_hmp(Chardev *chr, bool use_readline)
{
}
diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c
index fd1ced058c..f1ebffee5a 100644
--- a/tests/test-util-sockets.c
+++ b/tests/test-util-sockets.c
@@ -71,7 +71,8 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error
**errp)
*/
__thread Monitor *cur_mon;
int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
-void monitor_init(Chardev *chr, int flags) {}
+void monitor_init_qmp(Chardev *chr, bool pretty) {}
+void monitor_init_hmp(Chardev *chr, bool use_readline) {}
static void test_socket_fd_pass_name_good(void)
diff --git a/vl.c b/vl.c
index 005468cbfb..32daa434eb 100644
--- a/vl.c
+++ b/vl.c
@@ -2299,25 +2299,27 @@ static int fsdev_init_func(void *opaque, QemuOpts
*opts, Error **errp)
static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
Chardev *chr;
+ bool qmp;
+ bool pretty = false;
const char *chardev;
const char *mode;
- int flags;
mode = qemu_opt_get(opts, "mode");
if (mode == NULL) {
mode = "readline";
}
if (strcmp(mode, "readline") == 0) {
- flags = MONITOR_USE_READLINE;
+ qmp = false;
} else if (strcmp(mode, "control") == 0) {
- flags = MONITOR_USE_CONTROL;
+ qmp = true;
} else {
error_setg(errp, "unknown monitor mode \"%s\"", mode);
return -1;
}
- if (qemu_opt_get_bool(opts, "pretty", 0))
- flags |= MONITOR_USE_PRETTY;
+ if (qemu_opt_get_bool(opts, "pretty", 0)) {
+ pretty = true;
+ }
chardev = qemu_opt_get(opts, "chardev");
if (!chardev) {
@@ -2330,7 +2332,11 @@ static int mon_init_func(void *opaque, QemuOpts *opts,
Error **errp)
return -1;
}
- monitor_init(chr, flags);
+ if (qmp) {
+ monitor_init_qmp(chr, pretty);
+ } else {
+ monitor_init_hmp(chr, true);
+ }
return 0;
}
--
2.20.1
- Re: [Qemu-block] [Qemu-devel] [PATCH v3 07/15] Move monitor.c to monitor/misc.c, (continued)
- [Qemu-block] [PATCH v3 09/15] monitor: Create monitor-internal.h with common definitions, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 08/15] monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 04/15] monitor: Create MonitorHMP with readline state, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 10/15] monitor: Split out monitor/qmp.c, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 14/15] monitor: Replace monitor_init() with monitor_init_{hmp, qmp}(),
Kevin Wolf <=
- [Qemu-block] [PATCH v3 13/15] monitor: Split Monitor.flags into separate bools, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 12/15] monitor: Split out monitor/monitor.c, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 15/15] vl: Deprecate -mon pretty=... for HMP monitors, Kevin Wolf, 2019/06/13
- [Qemu-block] [PATCH v3 11/15] monitor: Split out monitor/hmp.c, Kevin Wolf, 2019/06/13