From patchwork Thu Feb 4 20:10:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 44545 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 0C2B0B7D25 for ; Fri, 5 Feb 2010 07:16:20 +1100 (EST) Received: from localhost ([127.0.0.1]:56141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nd87U-0002DC-0H for incoming@patchwork.ozlabs.org; Thu, 04 Feb 2010 15:16:08 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nd823-00009y-VO for qemu-devel@nongnu.org; Thu, 04 Feb 2010 15:10:32 -0500 Received: from [199.232.76.173] (port=33046 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nd823-00009b-Cq for qemu-devel@nongnu.org; Thu, 04 Feb 2010 15:10:31 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nd821-0008HX-Nh for qemu-devel@nongnu.org; Thu, 04 Feb 2010 15:10:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20426) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nd821-0008HN-8r for qemu-devel@nongnu.org; Thu, 04 Feb 2010 15:10:29 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o14KASe1020497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Feb 2010 15:10:28 -0500 Received: from localhost (vpn-9-202.rdu.redhat.com [10.11.9.202]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o14KAQ1T030715; Thu, 4 Feb 2010 15:10:27 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 4 Feb 2010 18:10:06 -0200 Message-Id: <1265314207-6323-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1265314207-6323-1-git-send-email-lcapitulino@redhat.com> References: <1265314207-6323-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 3/4] QMP: Enforce capability negotiation rules 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 With this commit QMP will be started in Capabilities Negotiation mode, where the only command allowed to run is 'qmp_capabilities'. All other commands will return CommandNotFound error. Asynchronous messages are not delivered either. When 'qmp_capabilities' is successfully executed QMP enters in Command mode, where all commands (except 'qmp_capabilities') are allowed to run and asynchronous messages are delivered. Signed-off-by: Luiz Capitulino --- monitor.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 94fc685..a0ec7fc 100644 --- a/monitor.c +++ b/monitor.c @@ -153,6 +153,11 @@ Monitor *cur_mon = NULL; static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque); +static inline int qmp_cmd_mode(const Monitor *mon) +{ + return (mon->mc ? mon->mc->command_mode : 0); +} + /* Return true if in control mode, false otherwise */ static inline int monitor_ctrl_mode(const Monitor *mon) { @@ -403,7 +408,7 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) } QLIST_FOREACH(mon, &mon_list, entry) { - if (monitor_ctrl_mode(mon)) { + if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) { monitor_json_emitter(mon, QOBJECT(qmp)); } } @@ -4229,6 +4234,12 @@ static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args) return err; } +static int invalid_qmp_mode(const Monitor *mon, const char *cmd_name) +{ + int is_cap = compare_cmd(cmd_name, "qmp_capabilities"); + return (qmp_cmd_mode(mon) ? is_cap : !is_cap); +} + static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) { int err; @@ -4268,6 +4279,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) cmd_name = qstring_get_str(qobject_to_qstring(obj)); + if (invalid_qmp_mode(mon, cmd_name)) { + qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); + goto err_input; + } + /* * XXX: We need this special case until we get info handlers * converted into 'query-' commands