From 317c52cc6aa0d7b47fa156eb84857a339d0b4406 Mon Sep 17 00:00:00 2001 From: Collin Walling Date: Mon, 7 May 2018 10:30:54 -0400 Subject: monitor: report entirety of hmp command on error When a user incorrectly provides an hmp command, an error response will be printed that prompts the user to try "help ". However, when the command contains multiple parts e.g. "info uuid xyz", only the last whitespace delimited string will be reported (in this example "info" will be dropped and the message will read "Try "help uuid" for more information", which is incorrect). Let's correct this by capturing the entirety of the command from the command line -- excluding any extraneous characters. Reported-by: Mikhail Fokin Signed-off-by: Collin Walling Message-Id: Reviewed-by: Eric Blake Signed-off-by: Dr. David Alan Gilbert --- monitor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index 885e000f9b..2a8187f5d7 100644 --- a/monitor.c +++ b/monitor.c @@ -3431,6 +3431,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline) { QDict *qdict; const mon_cmd_t *cmd; + const char *cmd_start = cmdline; trace_handle_hmp_command(mon, cmdline); @@ -3447,8 +3448,11 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline) qdict = monitor_parse_arguments(mon, &cmdline, cmd); if (!qdict) { - monitor_printf(mon, "Try \"help %s\" for more information\n", - cmd->name); + while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) { + cmdline--; + } + monitor_printf(mon, "Try \"help %.*s\" for more information\n", + (int)(cmdline - cmd_start), cmd_start); return; } -- cgit v1.2.3 From c3120f715db9dc351bde89b8a9d992cfeccb4680 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 20 Jun 2018 16:39:41 +0100 Subject: hmp: Add flag for preconfig commands Add a flag to command definitions to allow them to be used in preconfig and check it. If users try to use commands that aren't available, tell them to use the exit_preconfig comand we're adding in a few patches. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster Reviewed-by: Igor Mammedov Message-Id: <20180620153947.30834-2-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- monitor.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index 2a8187f5d7..ff26d863db 100644 --- a/monitor.c +++ b/monitor.c @@ -128,6 +128,7 @@ typedef struct mon_cmd_t { const char *args_type; const char *params; const char *help; + const char *flags; /* p=preconfig */ void (*cmd)(Monitor *mon, const QDict *qdict); /* @sub_table is a list of 2nd level of commands. If it does not exist, * cmd should be used. If it exists, sub_table[?].cmd should be @@ -958,6 +959,19 @@ static int parse_cmdline(const char *cmdline, return -1; } +/* + * Returns true if the command can be executed in preconfig mode + * i.e. it has the 'p' flag. + */ +static bool cmd_can_preconfig(const mon_cmd_t *cmd) +{ + if (!cmd->flags) { + return false; + } + + return strchr(cmd->flags, 'p'); +} + static void help_cmd_dump_one(Monitor *mon, const mon_cmd_t *cmd, char **prefix_args, @@ -3041,6 +3055,12 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, (int)(p - cmdp_start), cmdp_start); return NULL; } + if (runstate_check(RUN_STATE_PRECONFIG) && !cmd_can_preconfig(cmd)) { + monitor_printf(mon, "Command '%.*s' not available with -preconfig " + "until after exit_preconfig.\n", + (int)(p - cmdp_start), cmdp_start); + return NULL; + } /* filter out following useless space */ while (qemu_isspace(*p)) { -- cgit v1.2.3 From 31785f1b030b62ec84e1c852eaeeabbae1232345 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 20 Jun 2018 16:39:42 +0100 Subject: hmp: Allow help on preconfig commands Allow the 'help' command in preconfig state but make it only list the preconfig commands. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Igor Mammedov Message-Id: <20180620153947.30834-3-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- monitor.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index ff26d863db..18c2207e6d 100644 --- a/monitor.c +++ b/monitor.c @@ -979,6 +979,10 @@ static void help_cmd_dump_one(Monitor *mon, { int i; + if (runstate_check(RUN_STATE_PRECONFIG) && !cmd_can_preconfig(cmd)) { + return; + } + for (i = 0; i < prefix_args_nb; i++) { monitor_printf(mon, "%s ", prefix_args[i]); } @@ -1001,7 +1005,9 @@ static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, /* Find one entry to dump */ for (cmd = cmds; cmd->name != NULL; cmd++) { - if (compare_cmd(args[arg_index], cmd->name)) { + if (compare_cmd(args[arg_index], cmd->name) && + ((!runstate_check(RUN_STATE_PRECONFIG) || + cmd_can_preconfig(cmd)))) { if (cmd->sub_table) { /* continue with next arg */ help_cmd_dump(mon, cmd->sub_table, -- cgit v1.2.3 From 6d9f7839b7e6c364536d22beb2ca1277772813a6 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 20 Jun 2018 16:39:43 +0100 Subject: hmp: Restrict auto-complete in preconfig Don't show the commands that aren't available. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Igor Mammedov Message-Id: <20180620153947.30834-4-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- monitor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index 18c2207e6d..068c094a9a 100644 --- a/monitor.c +++ b/monitor.c @@ -4020,12 +4020,17 @@ static void monitor_find_completion_by_table(Monitor *mon, cmdname = args[0]; readline_set_completion_index(mon->rs, strlen(cmdname)); for (cmd = cmd_table; cmd->name != NULL; cmd++) { - cmd_completion(mon, cmdname, cmd->name); + if (!runstate_check(RUN_STATE_PRECONFIG) || + cmd_can_preconfig(cmd)) { + cmd_completion(mon, cmdname, cmd->name); + } } } else { /* find the command */ for (cmd = cmd_table; cmd->name != NULL; cmd++) { - if (compare_cmd(args[0], cmd->name)) { + if (compare_cmd(args[0], cmd->name) && + (!runstate_check(RUN_STATE_PRECONFIG) || + cmd_can_preconfig(cmd))) { break; } } -- cgit v1.2.3 From 13163a93b729b9ec4b49501d03d3f50af4b05758 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 20 Jun 2018 16:39:47 +0100 Subject: hmp: Allow HMP in preconfig state again Now we can cope with preconfig in HMP, reenable by reverting commit 71dc578e116599ea73c8a2a4e693134702ec0e83. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Igor Mammedov Message-Id: <20180620153947.30834-8-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- monitor.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index 068c094a9a..0730a27172 100644 --- a/monitor.c +++ b/monitor.c @@ -3461,12 +3461,6 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline) trace_handle_hmp_command(mon, cmdline); - if (runstate_check(RUN_STATE_PRECONFIG)) { - monitor_printf(mon, "HMP not available in preconfig state, " - "use QMP instead\n"); - return; - } - cmd = monitor_parse_command(mon, cmdline, &cmdline, mon->cmd_table); if (!cmd) { return; -- cgit v1.2.3