QMP: Don't use do_info()

Since its inception, QMP has been using HMP's do_info() function
to run query commands.

This was a bad choice, as it made do_info() more complex and
contributed to couple QMP and HMP.

This commit fixes that by doing the following changes:

  1. Introduce qmp_find_query_cmd() and use it to directly lookup
     the info_cmds table

  2. Introduce qmp_call_query_cmd() so that QMP code is able
     to call query handlers without using do_info()

  3. Drop do_info() usage (via monitor_find_command("info"))

We need all the three changes in one shot so that we don't break
the calling of query commands in QMP.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
Luiz Capitulino 2010-09-10 16:03:38 -03:00
parent 0fb88582e6
commit 030db6e89d

View file

@ -3390,6 +3390,11 @@ static const mon_cmd_t *monitor_find_command(const char *cmdname)
return search_dispatch_table(mon_cmds, cmdname);
}
static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
{
return search_dispatch_table(info_cmds, info_item);
}
static const mon_cmd_t *monitor_parse_command(Monitor *mon,
const char *cmdline,
QDict *qdict)
@ -4329,6 +4334,24 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
return input_dict;
}
static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd)
{
QObject *ret_data = NULL;
if (monitor_handler_is_async(cmd)) {
qmp_async_info_handler(mon, cmd);
if (monitor_has_error(mon)) {
monitor_protocol_emitter(mon, NULL);
}
} else {
cmd->mhandler.info_new(mon, &ret_data);
if (ret_data) {
monitor_protocol_emitter(mon, ret_data);
qobject_decref(ret_data);
}
}
}
static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
{
int err;
@ -4336,8 +4359,9 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
QDict *input, *args;
const mon_cmd_t *cmd;
Monitor *mon = cur_mon;
const char *cmd_name, *info_item;
const char *cmd_name, *query_cmd;
query_cmd = NULL;
args = input = NULL;
obj = json_parser_parse(tokens, NULL);
@ -4363,16 +4387,13 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
}
/*
* XXX: We need this special case until we get info handlers
* converted into 'query-' commands
* XXX: We need this special case until QMP has its own dispatch table
*/
if (compare_cmd(cmd_name, "info")) {
qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
goto err_out;
} else if (strstart(cmd_name, "query-", &info_item)) {
cmd = monitor_find_command("info");
qdict_put_obj(input, "arguments",
qobject_from_jsonf("{ 'item': %s }", info_item));
} else if (strstart(cmd_name, "query-", &query_cmd)) {
cmd = qmp_find_query_cmd(query_cmd);
} else {
cmd = monitor_find_command(cmd_name);
}
@ -4395,7 +4416,9 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
goto err_out;
}
if (monitor_handler_is_async(cmd)) {
if (query_cmd) {
qmp_call_query_cmd(mon, cmd);
} else if (monitor_handler_is_async(cmd)) {
err = qmp_async_cmd_handler(mon, cmd, args);
if (err) {
/* emit the error response */