From patchwork Wed Dec 19 10:17:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 207305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 20DAE2C009A for ; Wed, 19 Dec 2012 21:22:03 +1100 (EST) Received: from localhost ([::1]:39863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlGmn-0005W8-8S for incoming@patchwork.ozlabs.org; Wed, 19 Dec 2012 05:22:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlGmf-0005Vk-Jq for qemu-devel@nongnu.org; Wed, 19 Dec 2012 05:21:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlGmd-00015j-LU for qemu-devel@nongnu.org; Wed, 19 Dec 2012 05:21:53 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:48842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlGmc-00015T-PN for qemu-devel@nongnu.org; Wed, 19 Dec 2012 05:21:51 -0500 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Dec 2012 20:16:44 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 19 Dec 2012 20:16:42 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 7CEE12CE804D for ; Wed, 19 Dec 2012 21:21:46 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qBJALkXl56295674 for ; Wed, 19 Dec 2012 21:21:46 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qBJALjjx009243 for ; Wed, 19 Dec 2012 21:21:46 +1100 Received: from RedHat62GAWSWenchao ([9.77.178.138]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qBJAHLkH003655; Wed, 19 Dec 2012 21:19:29 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Wed, 19 Dec 2012 18:17:09 +0800 Message-Id: <1355912230-25132-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1355912230-25132-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1355912230-25132-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12121910-3568-0000-0000-000002ED3C80 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.142 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH 2/3] HMP: pass in parameter for info sub command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch enable sub info command handler getting meaningful parameter. Signed-off-by: Wenchao Xia --- hmp-commands.hx | 2 +- monitor.c | 79 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 010b8c9..667fab8 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1486,7 +1486,7 @@ ETEXI { .name = "info", - .args_type = "item:s?", + .args_type = "item:S?", .params = "[subcommand]", .help = "show various information about the system state", .mhandler.cmd = do_info, diff --git a/monitor.c b/monitor.c index 797680f..ce0e74d 100644 --- a/monitor.c +++ b/monitor.c @@ -464,6 +464,11 @@ QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX) MonitorEventState monitor_event_state[QEVENT_MAX]; QemuMutex monitor_event_state_lock; +static const mon_cmd_t *monitor_parse_command(Monitor *mon, + const char *cmdline, + const mon_cmd_t *table, + QDict *qdict); + /* * Emits the event to every monitor instance */ @@ -809,26 +814,29 @@ static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, static void do_info(Monitor *mon, const QDict *qdict) { const mon_cmd_t *cmd; + QDict *qdict_info; const char *item = qdict_get_try_str(qdict, "item"); if (!item) { goto help; } - for (cmd = info_cmds; cmd->name != NULL; cmd++) { - if (compare_cmd(item, cmd->name)) - break; - } + qdict_info = qdict_new(); - if (cmd->name == NULL) { - goto help; + cmd = monitor_parse_command(mon, item, info_cmds, qdict_info); + if (!cmd) { + QDECREF(qdict_info); + /* don't help here, to avoid error message got ignored */ + return; } - cmd->mhandler.info(mon, NULL); + cmd->mhandler.info(mon, qdict_info); + QDECREF(qdict_info); return; help: help_cmd(mon, "info"); + return; } CommandInfoList *qmp_query_commands(Error **errp) @@ -3534,18 +3542,15 @@ static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table, return NULL; } -static const mon_cmd_t *monitor_find_command(const char *cmdname) +static const mon_cmd_t *monitor_find_command(const char *cmdname, + const mon_cmd_t *table) { - return search_dispatch_table(mon_cmds, cmdname); -} - -static const mon_cmd_t *qmp_find_cmd(const char *cmdname) -{ - return search_dispatch_table(qmp_cmds, cmdname); + return search_dispatch_table(table, cmdname); } static const mon_cmd_t *monitor_parse_command(Monitor *mon, const char *cmdline, + const mon_cmd_t *table, QDict *qdict) { const char *p, *typestr; @@ -3564,7 +3569,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, if (!p) return NULL; - cmd = monitor_find_command(cmdname); + cmd = monitor_find_command(cmdname, table); if (!cmd) { monitor_printf(mon, "unknown command: '%s'\n", cmdname); return NULL; @@ -3872,6 +3877,31 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } } break; + case 'S': + { + /* package all remaining string */ + int len; + + while (qemu_isspace(*p)) { + p++; + } + if (*typestr == '?') { + typestr++; + if (*p == '\0') { + /* no remaining string: NULL argument */ + break; + } + } + len = strlen(p); + if (len <= 0) { + monitor_printf(mon, "%s: string expected\n", + cmdname); + break; + } + qdict_put(qdict, key, qstring_from_str(p)); + p += len; + } + break; default: bad_type: monitor_printf(mon, "%s: unknown type '%c'\n", cmdname, c); @@ -3925,7 +3955,7 @@ static void handle_user_command(Monitor *mon, const char *cmdline) qdict = qdict_new(); - cmd = monitor_parse_command(mon, cmdline, qdict); + cmd = monitor_parse_command(mon, cmdline, mon_cmds, qdict); if (!cmd) goto out; @@ -4144,12 +4174,7 @@ static void monitor_find_completion(const char *cmdline) break; case 's': /* XXX: more generic ? */ - if (!strcmp(cmd->name, "info")) { - readline_set_completion_index(cur_mon->rs, strlen(str)); - for(cmd = info_cmds; cmd->name != NULL; cmd++) { - cmd_completion(str, cmd->name); - } - } else if (!strcmp(cmd->name, "sendkey")) { + if (!strcmp(cmd->name, "sendkey")) { char *sep = strrchr(str, '-'); if (sep) str = sep + 1; @@ -4163,6 +4188,14 @@ static void monitor_find_completion(const char *cmdline) cmd_completion(str, cmd->name); } } + case 'S': + /* generic string packaged */ + if (!strcmp(cmd->name, "info")) { + readline_set_completion_index(cur_mon->rs, strlen(str)); + for (cmd = info_cmds; cmd->name != NULL; cmd++) { + cmd_completion(str, cmd->name); + } + } break; default: break; @@ -4483,7 +4516,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) goto err_out; } - cmd = qmp_find_cmd(cmd_name); + cmd = monitor_find_command(cmd_name, qmp_cmds); if (!cmd) { qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name); goto err_out;