aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2019-06-13 17:34:04 +0200
committerMarkus Armbruster <armbru@redhat.com>2019-06-18 08:14:17 +0200
commitfbfc29e3bf145581e84c12ffc432ab56ce1dea0d (patch)
tree2922c5fadb07f55fb45b816bdd1806c4cfcaed46
parent920824165c49bfbd1e0e9e07fd92e0bbbf32aea3 (diff)
monitor: Replace monitor_init() with monitor_init_{hmp, qmp}()
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 <kwolf@redhat.com> Message-Id: <20190613153405.24769-15-kwolf@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r--chardev/char.c2
-rw-r--r--gdbstub.c2
-rw-r--r--include/monitor/monitor.h9
-rw-r--r--monitor/hmp.c4
-rw-r--r--monitor/monitor-internal.h3
-rw-r--r--monitor/monitor.c9
-rw-r--r--monitor/qmp.c7
-rw-r--r--stubs/monitor.c6
-rw-r--r--tests/test-util-sockets.c3
-rw-r--r--vl.c18
10 files changed, 27 insertions, 36 deletions
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 d614a1f3c0..8618e34311 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -3344,7 +3344,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/include/monitor/monitor.h b/include/monitor/monitor.h
index 44ac43df34..a81eeff5f8 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/hmp.c b/monitor/hmp.c
index 379e366984..5223661e82 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1395,14 +1395,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_new0(MonitorHMP, 1);
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-internal.h b/monitor/monitor-internal.h
index 03ea0239ef..7760b22ba3 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -163,9 +163,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/monitor/monitor.c b/monitor/monitor.c
index 3f4808240a..3ef28171c0 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -551,15 +551,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 940649f688..e1b196217d 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -364,18 +364,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_new0(MonitorQMP, 1);
- /* 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;
}