From patchwork Mon Nov 28 18:11:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 128040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 29875B6F68 for ; Tue, 29 Nov 2011 05:13:10 +1100 (EST) Received: from localhost ([::1]:41553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RV5hT-0005Z9-7T for incoming@patchwork.ozlabs.org; Mon, 28 Nov 2011 13:13:07 -0500 Received: from eggs.gnu.org ([140.186.70.92]:55418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RV5gp-0004Qn-5t for qemu-devel@nongnu.org; Mon, 28 Nov 2011 13:12:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RV5gh-0008Oi-Ca for qemu-devel@nongnu.org; Mon, 28 Nov 2011 13:12:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RV5gg-0008OQ-KV for qemu-devel@nongnu.org; Mon, 28 Nov 2011 13:12:19 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pASIBtlG011518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Nov 2011 13:11:55 -0500 Received: from localhost (ovpn-113-91.phx2.redhat.com [10.3.113.91]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pASIBstW017239; Mon, 28 Nov 2011 13:11:54 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 28 Nov 2011 16:11:22 -0200 Message-Id: <1322503885-5913-14-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1322503885-5913-1-git-send-email-lcapitulino@redhat.com> References: <1322503885-5913-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 13/16] qapi: Convert human-monitor-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 Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- monitor.c | 23 ++++++++++++++--------- qapi-schema.json | 28 ++++++++++++++++++++++++++++ qmp-commands.hx | 5 +---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/monitor.c b/monitor.c index 62b1747..7334401 100644 --- a/monitor.c +++ b/monitor.c @@ -513,10 +513,10 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params, static void handle_user_command(Monitor *mon, const char *cmdline); -static int do_hmp_passthrough(Monitor *mon, const QDict *params, - QObject **ret_data) +char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, + int64_t cpu_index, Error **errp) { - int ret = 0; + char *output = NULL; Monitor *old_mon, hmp; CharDriverState mchar; @@ -527,25 +527,30 @@ static int do_hmp_passthrough(Monitor *mon, const QDict *params, old_mon = cur_mon; cur_mon = &hmp; - if (qdict_haskey(params, "cpu-index")) { - ret = monitor_set_cpu(qdict_get_int(params, "cpu-index")); + if (has_cpu_index) { + int ret = monitor_set_cpu(cpu_index); if (ret < 0) { cur_mon = old_mon; - qerror_report(QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); goto out; } } - handle_user_command(&hmp, qdict_get_str(params, "command-line")); + handle_user_command(&hmp, command_line); cur_mon = old_mon; if (qemu_chr_mem_osize(hmp.chr) > 0) { - *ret_data = QOBJECT(qemu_chr_mem_to_qs(hmp.chr)); + QString *str = qemu_chr_mem_to_qs(hmp.chr); + output = g_strdup(qstring_get_str(str)); + QDECREF(str); + } else { + output = g_strdup(""); } out: qemu_chr_close_mem(hmp.chr); - return ret; + return output; } static int compare_cmd(const char *name, const char *list) diff --git a/qapi-schema.json b/qapi-schema.json index da40c13..a762d2e 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1085,3 +1085,31 @@ ## { 'command': 'blockdev-snapshot-sync', 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } } + +## +# @human-monitor-command: +# +# Execute a command on the human monitor and return the output. +# +# @command-line: the command to execute in the human monitor +# +# @cpu-index: #optional The CPU to use for commands that require an implicit CPU +# +# Returns: the output of the command as a string +# +# Since: 0.14.0 +# +# Notes: This command only exists as a stop-gap. It's use is highly +# discouraged. The semantics of this command are not guaranteed. +# +# Known limitations: +# +# o This command is stateless, this means that commands that depend +# on state information (such as getfd) might not work +# +# o Commands that prompt the user for data (eg. 'cont' when the block +# device is encrypted) don't currently work +## +{ 'command': 'human-monitor-command', + 'data': {'command-line': 'str', '*cpu-index': 'int'}, + 'returns': 'str' } diff --git a/qmp-commands.hx b/qmp-commands.hx index 8edf99b..0c41eae 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -932,10 +932,7 @@ EQMP { .name = "human-monitor-command", .args_type = "command-line:s,cpu-index:i?", - .params = "", - .help = "", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_hmp_passthrough, + .mhandler.cmd_new = qmp_marshal_input_human_monitor_command, }, SQMP