diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2020-03-06 17:15:35 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2020-03-06 17:15:36 +0000 |
| commit | 67f17e23baca5dd545fe98b01169cc351a70fe35 (patch) | |
| tree | faab89fb46541f6d2d79d27e95fa9ce1720091a3 /monitor/monitor.c | |
| parent | c2058285790fd305c06847b1bb9685c4302a0aec (diff) | |
| parent | 1de6b45fb5c1489b450df7d1a4c692bba9678ce6 (diff) | |
| download | focaccia-qemu-67f17e23baca5dd545fe98b01169cc351a70fe35.tar.gz focaccia-qemu-67f17e23baca5dd545fe98b01169cc351a70fe35.zip | |
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches: - Add qemu-storage-daemon (still experimental) - rbd: Add support for ceph namespaces - Fix bdrv_reopen() with backing file in different AioContext - qcow2: Fix read-write reopen with persistent dirty bitmaps - qcow2: Fix alloc_cluster_abort() for pre-existing clusters # gpg: Signature made Fri 06 Mar 2020 17:12:31 GMT # gpg: using RSA key 7F09B272C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: (29 commits) block: bdrv_reopen() with backing file in different AioContext iotests: Refactor blockdev-reopen test for iothreads block/rbd: Add support for ceph namespaces qemu-storage-daemon: Add --monitor option monitor: Add allow_hmp parameter to monitor_init() hmp: Fail gracefully if chardev is already in use qmp: Fail gracefully if chardev is already in use monitor: Create QAPIfied monitor_init() qapi: Create 'pragma' module stubs: Update monitor stubs for qemu-storage-daemon qemu-storage-daemon: Add --chardev option qemu-storage-daemon: Add main loop qemu-storage-daemon: Add --export option blockdev-nbd: Boxed argument type for nbd-server-add qemu-storage-daemon: Add --nbd-server option qemu-storage-daemon: Add --object option qapi: Flatten object-add qemu-storage-daemon: Add --blockdev option block: Move sysemu QMP commands to QAPI block module block: Move common QMP commands to block-core QAPI module ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'monitor/monitor.c')
| -rw-r--r-- | monitor/monitor.c | 86 |
1 files changed, 53 insertions, 33 deletions
diff --git a/monitor/monitor.c b/monitor/monitor.c index c1a6c4460f..125494410a 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -25,7 +25,9 @@ #include "qemu/osdep.h" #include "monitor-internal.h" #include "qapi/error.h" +#include "qapi/opts-visitor.h" #include "qapi/qapi-emit-events.h" +#include "qapi/qapi-visit-control.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" #include "qemu/error-report.h" @@ -609,50 +611,68 @@ void monitor_init_globals_core(void) NULL); } -int monitor_init_opts(QemuOpts *opts, Error **errp) +int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp) { Chardev *chr; - bool qmp; - bool pretty = false; - const char *chardev; - const char *mode; - - mode = qemu_opt_get(opts, "mode"); - if (mode == NULL) { - mode = "readline"; - } - if (strcmp(mode, "readline") == 0) { - qmp = false; - } else if (strcmp(mode, "control") == 0) { - qmp = true; - } else { - error_setg(errp, "unknown monitor mode \"%s\"", mode); + Error *local_err = NULL; + + chr = qemu_chr_find(opts->chardev); + if (chr == NULL) { + error_setg(errp, "chardev \"%s\" not found", opts->chardev); return -1; } - if (!qmp && qemu_opt_get(opts, "pretty")) { - warn_report("'pretty' is deprecated for HMP monitors, it has no effect " - "and will be removed in future versions"); - } - if (qemu_opt_get_bool(opts, "pretty", 0)) { - pretty = true; + if (!opts->has_mode) { + opts->mode = allow_hmp ? MONITOR_MODE_READLINE : MONITOR_MODE_CONTROL; } - chardev = qemu_opt_get(opts, "chardev"); - if (!chardev) { - error_report("chardev is required"); - exit(1); + switch (opts->mode) { + case MONITOR_MODE_CONTROL: + monitor_init_qmp(chr, opts->pretty, &local_err); + break; + case MONITOR_MODE_READLINE: + if (!allow_hmp) { + error_setg(errp, "Only QMP is supported"); + return -1; + } + if (opts->pretty) { + warn_report("'pretty' is deprecated for HMP monitors, it has no " + "effect and will be removed in future versions"); + } + monitor_init_hmp(chr, true, &local_err); + break; + default: + g_assert_not_reached(); } - chr = qemu_chr_find(chardev); - if (chr == NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev); + + if (local_err) { + error_propagate(errp, local_err); return -1; } + return 0; +} + +int monitor_init_opts(QemuOpts *opts, Error **errp) +{ + Visitor *v; + MonitorOptions *options; + Error *local_err = NULL; + + v = opts_visitor_new(opts); + visit_type_MonitorOptions(v, NULL, &options, &local_err); + visit_free(v); + + if (local_err) { + goto out; + } - if (qmp) { - monitor_init_qmp(chr, pretty); - } else { - monitor_init_hmp(chr, true); + monitor_init(options, true, &local_err); + qapi_free_MonitorOptions(options); + +out: + if (local_err) { + error_propagate(errp, local_err); + return -1; } return 0; } |