[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/11] QMP: Make monitor_handle_command() QMP aware
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 04/11] QMP: Make monitor_handle_command() QMP aware |
Date: |
Tue, 23 Jun 2009 01:28:49 -0300 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH 04/11] QMP: Make monitor_handle_command() QMP aware,
Luiz Capitulino <=