From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Greg Kurz <groug@kaod.org>, Markus Armbruster <armbru@redhat.com>,
qemu-ppc@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/5] monitor: allow register hmp commands
Date: Tue, 22 Jun 2021 14:49:11 +0200 [thread overview]
Message-ID: <20210622124915.261060-2-kraxel@redhat.com> (raw)
In-Reply-To: <20210622124915.261060-1-kraxel@redhat.com>
Allow commands having a NULL cmd pointer, add a function to set the
pointer later. Use case: allow modules implement hmp commands.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
include/monitor/monitor.h | 3 +++
monitor/hmp.c | 7 +++++++
monitor/misc.c | 15 +++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1211d6e6d69f..1a8a369b50b2 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -51,4 +51,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
void monitor_fdset_dup_fd_remove(int dup_fd);
int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_register_hmp(const char *name, bool info,
+ void (*cmd)(Monitor *mon, const QDict *qdict));
+
#endif /* MONITOR_H */
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 6c0b33a0b19d..d50c3124e1e1 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1089,6 +1089,13 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
return;
}
+ if (!cmd->cmd) {
+ /* FIXME: is it useful to try autoload modules here ??? */
+ monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n",
+ (int)(cmdline - cmd_start), cmd_start);
+ return;
+ }
+
qdict = monitor_parse_arguments(&mon->common, &cmdline, cmd);
if (!qdict) {
while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
diff --git a/monitor/misc.c b/monitor/misc.c
index 1539e18557f0..672267008b02 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -1974,6 +1974,21 @@ static void sortcmdlist(void)
compare_mon_cmd);
}
+void monitor_register_hmp(const char *name, bool info,
+ void (*cmd)(Monitor *mon, const QDict *qdict))
+{
+ HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;
+
+ while (table->name != NULL) {
+ if (strcmp(table->name, name) == 0) {
+ table->cmd = cmd;
+ return;
+ }
+ table++;
+ }
+ g_assert_not_reached();
+}
+
void monitor_init_globals(void)
{
monitor_init_globals_core();
--
2.31.1
next prev parent reply other threads:[~2021-06-22 12:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
2021-06-22 12:49 ` Gerd Hoffmann [this message]
2021-06-22 13:13 ` [PATCH 1/5] monitor: allow register hmp commands Greg Kurz
2021-06-22 12:49 ` [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook Gerd Hoffmann
2021-06-23 1:51 ` David Gibson
2021-06-22 12:49 ` [PATCH 3/5] monitor/usb: register 'info usbhost' dynamically Gerd Hoffmann
2021-06-22 12:49 ` [PATCH 4/5] usb: build usb-host as module Gerd Hoffmann
2021-06-22 12:49 ` [PATCH 5/5] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically Gerd Hoffmann
2021-08-07 10:36 ` [PATCH 0/5] [RfC] monitor/hmp: command register support Markus Armbruster
2021-08-09 9:16 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210622124915.261060-2-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=armbru@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=dgilbert@redhat.com \
--cc=groug@kaod.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).