diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2018-08-22 19:19:42 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2018-10-03 14:45:05 +0400 |
commit | 95e30b2a131ed1f94ab7a64326243943317aa18a (patch) | |
tree | 13e15791ee1e7b0f8095a3165710716043bb3527 /chardev/char.c | |
parent | 5662576ad020c8eabdc1a84e9ee1f9ce85578bbb (diff) |
chardev: mark the calls that allow an implicit mux monitor
This is mostly for readability of the code. Let's make it clear which
callers can create an implicit monitor when the chardev is muxed.
This will also enforce a safer behaviour, as we don't really support
creating monitor anywhere/anytime at the moment. Add an assert() to
make sure the programmer explicitely wanted that behaviour.
There are documented cases, such as: -serial/-parallel/-virtioconsole
and to less extent -debugcon.
Less obvious and questionable ones are -gdb, SLIRP -guestfwd and Xen
console. Add a FIXME note for those, but keep the support for now.
Other qemu_chr_new() callers either have a fixed parameter/filename
string or do not need it, such as -qtest:
* qtest.c: qtest_init()
Afaik, only used by tests/libqtest.c, without mux. I don't think we
support it outside of qemu testing: drop support for implicit mux
monitor (qemu_chr_new() call: no implicit mux now).
* hw/
All with literal @filename argument that doesn't enable mux monitor.
* tests/
All with @filename argument that doesn't enable mux monitor.
On a related note, the list of monitor creation places:
- the chardev creators listed above: all from command line (except
perhaps Xen console?)
- -gdb & hmp gdbserver will create a "GDB monitor command" chardev
that is wired to an HMP monitor.
- -mon command line option
From this short study, I would like to think that a monitor may only
be created in the main thread today, though I remain skeptical :)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'chardev/char.c')
-rw-r--r-- | chardev/char.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/chardev/char.c b/chardev/char.c index 76d866e6fe..e115166995 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -329,7 +329,8 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp) return 0; } -QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename, + bool permit_mux_mon) { char host[65], port[33], width[8], height[8]; int pos; @@ -344,6 +345,10 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) } if (strstart(filename, "mon:", &p)) { + if (!permit_mux_mon) { + error_report("mon: isn't supported in this context"); + return NULL; + } filename = p; qemu_opt_set(opts, "mux", "on", &error_abort); if (strcmp(filename, "stdio") == 0) { @@ -683,7 +688,8 @@ out: return chr; } -Chardev *qemu_chr_new_noreplay(const char *label, const char *filename) +Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, + bool permit_mux_mon) { const char *p; Chardev *chr; @@ -694,25 +700,32 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename) return qemu_chr_find(p); } - opts = qemu_chr_parse_compat(label, filename); + opts = qemu_chr_parse_compat(label, filename, permit_mux_mon); if (!opts) return NULL; chr = qemu_chr_new_from_opts(opts, &err); - if (err) { + if (!chr) { error_report_err(err); + goto out; } - if (chr && qemu_opt_get_bool(opts, "mux", 0)) { + + if (qemu_opt_get_bool(opts, "mux", 0)) { + assert(permit_mux_mon); monitor_init(chr, MONITOR_USE_READLINE); } + +out: qemu_opts_del(opts); return chr; } -Chardev *qemu_chr_new(const char *label, const char *filename) +static Chardev *qemu_chr_new_permit_mux_mon(const char *label, + const char *filename, + bool permit_mux_mon) { Chardev *chr; - chr = qemu_chr_new_noreplay(label, filename); + chr = qemu_chr_new_noreplay(label, filename, permit_mux_mon); if (chr) { if (replay_mode != REPLAY_MODE_NONE) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_REPLAY); @@ -726,6 +739,16 @@ Chardev *qemu_chr_new(const char *label, const char *filename) return chr; } +Chardev *qemu_chr_new(const char *label, const char *filename) +{ + return qemu_chr_new_permit_mux_mon(label, filename, false); +} + +Chardev *qemu_chr_new_mux_mon(const char *label, const char *filename) +{ + return qemu_chr_new_permit_mux_mon(label, filename, true); +} + static int qmp_query_chardev_foreach(Object *obj, void *data) { Chardev *chr = CHARDEV(obj); |