From patchwork Mon Oct 25 20:06:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 69138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 75782B70AF for ; Tue, 26 Oct 2010 07:10:27 +1100 (EST) Received: from localhost ([127.0.0.1]:56875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PATNA-0006KC-I3 for incoming@patchwork.ozlabs.org; Mon, 25 Oct 2010 16:10:24 -0400 Received: from [140.186.70.92] (port=36764 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PATJr-0004wf-FC for qemu-devel@nongnu.org; Mon, 25 Oct 2010 16:07:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PATJq-0004w8-1m for qemu-devel@nongnu.org; Mon, 25 Oct 2010 16:06:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PATJp-0004w0-Od for qemu-devel@nongnu.org; Mon, 25 Oct 2010 16:06:58 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9PK6uWI017900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Oct 2010 16:06:57 -0400 Received: from localhost (ovpn-113-92.phx2.redhat.com [10.3.113.92]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9PK6tRQ016150; Mon, 25 Oct 2010 16:06:56 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 25 Oct 2010 18:06:44 -0200 Message-Id: <1288037204-27768-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1288037204-27768-1-git-send-email-lcapitulino@redhat.com> References: <1288037204-27768-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 2/2] QMP: Introduce Human Monitor passthrough command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This command allows QMP clients to execute HMP commands, please check its documentation in the hmp-commands.hx file for usage information. Please, also note that not all HMP commands can be executed this way, in special commands that: o need to store monitor related data (eg. getfd) o read data from the user (eg. cont when the block device is encrypted) TODO: Create a blacklist for those bad commands or just let them fail? (assuming they won't blowup, of course) TODO: Maybe a command like 'cpu' requires a blacklist Signed-off-by: Luiz Capitulino --- monitor.c | 34 ++++++++++++++++++++++++++++++++++ qmp-commands.hx | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index 260cc02..a0df098 100644 --- a/monitor.c +++ b/monitor.c @@ -490,6 +490,40 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params, return 0; } +static void handle_user_command(Monitor *mon, const char *cmdline); + +static void hmp_call(Monitor *mon, const char *cmdline) +{ + Monitor *old_mon = cur_mon; + + cur_mon = mon; + handle_user_command(mon, cmdline); + cur_mon = old_mon; +} + +static int do_hmp_passthrough(Monitor *mon, const QDict *params, + QObject **ret_data) +{ + QString *qs; + Monitor hmp; + CharDriverState bufchr; + + memset(&hmp, 0, sizeof(hmp)); + hmp.chr = &bufchr; + qemu_chr_init_buffered(hmp.chr); + + hmp_call(&hmp, qdict_get_str(params, "command-line")); + + qs = qemu_chr_buffered_to_qs(hmp.chr); + if (qs) { + *ret_data = QOBJECT(qs); + } + + qemu_chr_close_buffered(hmp.chr); + + return 0; +} + static int compare_cmd(const char *name, const char *list) { const char *p, *pstart; diff --git a/qmp-commands.hx b/qmp-commands.hx index 793cf1c..29a6048 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -761,6 +761,38 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info version" } } +<- { "return": "0.13.50\r\n" } + +Note: The Human Monitor is NOT a stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command. + 3. Query Commands =================