]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
monitor: allow register hmp commands
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 24 Jun 2021 10:38:32 +0000 (12:38 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 9 Jul 2021 16:21:33 +0000 (18:21 +0200)
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>
Reviewed-by: Jose R. Ziviani <jziviani@suse.de>
Message-Id: <20210624103836.2382472-31-kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/monitor/monitor.h
monitor/hmp.c
monitor/misc.c

index 1211d6e6d69f276cf7c0af2e9dea0e2028a1c3ec..1a8a369b50b2a5d1d35c9ce3721a695bd0ee62a9 100644 (file)
@@ -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 */
index 6c0b33a0b19dff4e31802392ac512914b194e493..d50c3124e1e16aed6fe0988ee64ecc35cddca9ba 100644 (file)
@@ -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])) {
index 1539e18557f0f90a7043d7390a67b801b9d5c425..ad476c6e51ea45311aef03a863900fca68596609 100644 (file)
@@ -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();