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>
This commit is contained in:
parent
920824165c
commit
fbfc29e3bf
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
/*
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
18
vl.c
18
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user