[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 30/34] monitor: allow register hmp commands
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [PATCH v4 30/34] monitor: allow register hmp commands |
Date: |
Thu, 24 Jun 2021 15:55:29 +0100 |
User-agent: |
Mutt/2.0.7 (2021-05-04) |
* Gerd Hoffmann (kraxel@redhat.com) wrote:
> 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>
So this is OK, so
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
however, I can imagine:
a) Auto load as you suggest
b) Making the error better 'Command ... needs module ....'
c) Don't actually define the command in the tables at all; make
the module actually add the command to the table.
Dave
> ---
> include/monitor/monitor.h | 3 +++
> monitor/hmp.c | 7 +++++++
> monitor/misc.c | 16 ++++++++++++++++
> 3 files changed, 26 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..ad476c6e51ea 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -1974,6 +1974,22 @@ 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) {
> + g_assert(table->cmd == NULL);
> + table->cmd = cmd;
> + return;
> + }
> + table++;
> + }
> + g_assert_not_reached();
> +}
> +
> void monitor_init_globals(void)
> {
> monitor_init_globals_core();
> --
> 2.31.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
- [PATCH v4 21/34] modules: add documentation for module sourcesets, (continued)
- [PATCH v4 21/34] modules: add documentation for module sourcesets, Gerd Hoffmann, 2021/06/24
- [PATCH v4 22/34] modules: add module_obj() note to QOM docs, Gerd Hoffmann, 2021/06/24
- [PATCH v4 24/34] modules: hook up modules.h to docs build, Gerd Hoffmann, 2021/06/24
- [PATCH v4 25/34] accel: autoload modules, Gerd Hoffmann, 2021/06/24
- [PATCH v4 26/34] accel: add qtest module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 27/34] accel: build qtest modular, Gerd Hoffmann, 2021/06/24
- [PATCH v4 29/34] accel: build tcg modular, Gerd Hoffmann, 2021/06/24
- [PATCH v4 28/34] accel: add tcg module annotations, Gerd Hoffmann, 2021/06/24
- [PATCH v4 31/34] usb: drop usb_host_dev_is_scsi_storage hook, Gerd Hoffmann, 2021/06/24
- [PATCH v4 30/34] monitor: allow register hmp commands, Gerd Hoffmann, 2021/06/24
- Re: [PATCH v4 30/34] monitor: allow register hmp commands,
Dr. David Alan Gilbert <=
- [PATCH v4 33/34] usb: build usb-host as module, Gerd Hoffmann, 2021/06/24
- [PATCH v4 32/34] monitor/usb: register 'info usbhost' dynamically, Gerd Hoffmann, 2021/06/24
- [PATCH v4 34/34] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically, Gerd Hoffmann, 2021/06/24
- Re: [PATCH v4 00/34] modules: add meta-data database, Dr. David Alan Gilbert, 2021/06/24
- Re: [PATCH v4 00/34] modules: add meta-data database, Jose R. Ziviani, 2021/06/24