[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 05/11] vl: Demonstrate (bad) CLI wrapped around QMP
From: |
Markus Armbruster |
Subject: |
[PATCH RFC 05/11] vl: Demonstrate (bad) CLI wrapped around QMP |
Date: |
Thu, 2 Dec 2021 08:04:44 +0100 |
To ensure you can do everything with QMP, the CLI should wrap around
QMP, like HMP should.
This commit does that in the stupidest way I can think of: each CLI
argument is parsed as QMP command, and fed to the QMP machinery.
Errors are reported, return values thrown away.
This is of course *bad* CLI. To get decent CLI, we'll want to
translate from CLI syntax to QMP. We may want to target QMP's C
interface instead of parse trees.
Note that this CLI processing code is cleanly separated from other
startup code, unlike the old CLI code I axed.
Only QMP commands with 'allow-preconfig': true work at this time.
This is because CLI is processed early in startup. The remainder of
the series is about letting the user interleave CLI and then QMP with
startup. This will make arbitrary QMP commands available in the CLI.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
softmmu/vl.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 07be92d5c0..916cba35b7 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -129,6 +129,7 @@
#include "config-host.h"
+#include "monitor/monitor-internal.h"
#include "qapi/qapi-commands-char.h"
#include "qapi/qapi-types-control.h"
@@ -1011,6 +1012,31 @@ void qemu_init(int argc, char **argv, char **envp)
qemu_init_subsystems();
+ /*
+ * HACK to demonstrate feeding CLI to QMP
+ * Missing: translate CLI to QMP. Instead, each CLI argument is
+ * parsed as a QMP command.
+ */
+ {
+ int i;
+ QObject *req;
+ QDict *resp, *error;
+
+ for (i = 1; argv[i]; i++) {
+ loc_set_cmdline(argv, i, 1);
+ req = qobject_from_json(argv[i], &error_fatal);
+ resp = qmp_dispatch(&qmp_commands, req, false, NULL);
+ error = qdict_get_qdict(resp, "error");
+ if (error) {
+ error_report("%s", qdict_get_str(error, "desc"));
+ exit(1);
+ }
+ /* TODO do something with the command's return valud? */
+ qobject_unref(resp);
+ qobject_unref(req);
+ }
+ }
+
qemu_process_early_options();
qemu_maybe_daemonize(pid_file);
--
2.31.1
- [PATCH RFC 00/11] vl: Explore redesign of startup, Markus Armbruster, 2021/12/02
- [PATCH RFC 02/11] vl: Drop x-exit-preconfig, Markus Armbruster, 2021/12/02
- [PATCH RFC 10/11] vl: Disregard lack of 'allow-preconfig': true, Markus Armbruster, 2021/12/02
- [PATCH RFC 06/11] vl: Factor qemu_until_phase() out of qemu_init(), Markus Armbruster, 2021/12/02
- [PATCH RFC 07/11] vl: Implement qemu_until_phase() running from arbitrary phase, Markus Armbruster, 2021/12/02
- [PATCH RFC 03/11] vl: Hardcode a QMP monitor on stdio for now, Markus Armbruster, 2021/12/02
- [PATCH RFC 08/11] vl: Implement qemu_until_phase() running to arbitrary phase, Markus Armbruster, 2021/12/02
- [PATCH RFC 11/11] vl: Enter main loop in phase @machine-initialized, Markus Armbruster, 2021/12/02
- [PATCH RFC 05/11] vl: Demonstrate (bad) CLI wrapped around QMP,
Markus Armbruster <=
- [PATCH RFC 04/11] vl: Hardcode a VGA device for now, Markus Armbruster, 2021/12/02
- [PATCH RFC 09/11] vl: New QMP command until-phase, Markus Armbruster, 2021/12/02
- [PATCH RFC 01/11] vl: Cut off the CLI with an axe, Markus Armbruster, 2021/12/02
- Re: [PATCH RFC 00/11] vl: Explore redesign of startup, Markus Armbruster, 2021/12/02
- Re: [PATCH RFC 00/11] vl: Explore redesign of startup, Damien Hedde, 2021/12/07