From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIxcz-0007rU-Mj for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:29:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIxcv-0007oD-B3 for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:29:01 -0400 Received: from [199.232.76.173] (port=35674 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIxcv-0007o9-0N for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:28:57 -0400 Received: from mx2.redhat.com ([66.187.237.31]:32797) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MIxcu-000390-Fr for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:28:56 -0400 Date: Tue, 23 Jun 2009 01:28:49 -0300 From: Luiz Capitulino Message-ID: <20090623012849.3150a245@doriath> In-Reply-To: References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 04/11] QMP: Make monitor_handle_command() QMP aware List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, ehabkost@redhat.com, jan.kiszka@siemens.com, dlaor@redhat.com, avi@redhat.com Two changes are needed in monitor_handle_command() so that it knows how to work in control mode. First, it has to know whether a given command is part of the protocol or not. Second, it has to print the correct server response when a command execution finishes. A good approach to do this would be: 1. Add a new member to struct mon_cmd_t, which will tell if the command is already part of the protocol. 2. Change handler_* functions to return exit status, so that monitor_handle_command() can print "+ OK" or "- ERR" accordling. However, to make the prototype simpler I have chosen a quick & dirty approach, which is: 1. Introduce valid_control_cmd(). This function has a listing of commands that have already been ported and thus are part of the protocol. 2. Always print "+ OK", as current commands will probably not print "- ERR" :). This requires enabling monitor_print_ok() compilation. Signed-off-by: Luiz Capitulino --- monitor.c | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index dfa777d..6d40b9b 100644 --- a/monitor.c +++ b/monitor.c @@ -217,7 +217,6 @@ void monitor_printf_bad(Monitor *mon, const char *fmt, ...) } } -#if 0 /* OK command completion, 'info' commands are special */ static void monitor_print_ok(Monitor *mon, const char *cmd, const char *arg) { @@ -229,7 +228,6 @@ static void monitor_print_ok(Monitor *mon, const char *cmd, const char *arg) monitor_printf(mon, " %s", arg); monitor_puts(mon, " completed\n"); } -#endif static void monitor_ctrl_pprintf(Monitor *mon, const char *prefix, const char *fmt, va_list ap) @@ -2476,6 +2474,35 @@ static const char *get_command_name(const char *cmdline, return p; } +/* When in control mode, return true if 'cmd' is part of the protocol, + * return false otherwise */ +static int valid_control_cmd(Monitor *mon, const char *cmd, + const char *cmdline) +{ + int i; + const char *valid_cmds[] = { NULL }; + const char *valid_infos[] = { NULL }; + + if (!monitor_ctrl_mode(mon)) { + /* all commands are valid in user-mode mode */ + return 1; + } + + for (i = 0; valid_cmds[i]; i++) + if (compare_cmd(valid_cmds[i], cmd)) + return 1; + + /* info is special */ + if (compare_cmd(cmd, "info")) { + for (i = 0; valid_infos[i]; i++) + if (strstr(cmdline, valid_infos[i])) + return 1; + } + + monitor_printf_bad(mon, "unknown command\n"); + return 0; +} + static int default_fmt_format = 'x'; static int default_fmt_size = 4; @@ -2512,6 +2539,9 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline) if (!p) return; + if (valid_control_cmd(mon, cmdname, cmdline) == 0) + return; + /* find the command */ for(cmd = mon_cmds; cmd->name != NULL; cmd++) { if (compare_cmd(cmdname, cmd->name)) @@ -2794,6 +2824,7 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline) monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args); goto fail; } + monitor_print_ok(mon, cmdname, args[0]); fail: for(i = 0; i < MAX_ARGS; i++) qemu_free(str_allocated[i]); -- 1.6.3.GIT