From patchwork Thu Jan 21 21:09:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 43461 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 72641B7D26 for ; Fri, 22 Jan 2010 08:35:30 +1100 (EST) Received: from localhost ([127.0.0.1]:51780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY4fR-0006g3-84 for incoming@patchwork.ozlabs.org; Thu, 21 Jan 2010 16:34:17 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NY4Ic-0001EL-Tp for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NY4IY-00016K-2w for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:42 -0500 Received: from [199.232.76.173] (port=43496 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY4IX-000166-G0 for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53973) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NY4IW-00034Z-W6 for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:37 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0LLAZFb027032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Jan 2010 16:10:36 -0500 Received: from localhost (vpn-9-176.rdu.redhat.com [10.11.9.176]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0LLAXl7008691; Thu, 21 Jan 2010 16:10:34 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org, armbru@redhat.com, aliguori@us.ibm.com, avi@redhat.com Date: Thu, 21 Jan 2010 19:09:40 -0200 Message-Id: <1264108180-3666-12-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1264108180-3666-1-git-send-email-lcapitulino@redhat.com> References: <1264108180-3666-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 11/11] QMP: Enable feature negotiation support 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 is done by enforcing the following mode-oriented rules: - QMP is started in handshake mode - In handshake mode all protocol capabilities are disabled and (apart of a few exceptions) only commands which query/enable/disable them are allowed - Asynchronous messages are now considered a capability - Clients can change to the operational mode (where capabilities' changes take effect and most commands are allowed) at any time - Each QMP Monitor has its own set of capabilities, changes made to one of them don't affect the others Also note that all these changes should have no effect in the user Monitor. Signed-off-by: Luiz Capitulino --- monitor.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 34df1cc..0ca0941 100644 --- a/monitor.c +++ b/monitor.c @@ -410,7 +410,8 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) QLIST_FOREACH(mon, &mon_list, entry) { if (monitor_ctrl_mode(mon) && - qevent_enabled(mon, event)) { + qevent_enabled(mon, event) && + mon->mc->mode == QMODE_OPERATIONAL) { monitor_json_emitter(mon, QOBJECT(qmp)); } } @@ -4166,12 +4167,38 @@ static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args) return err; } +static int qmp_mode_invalid(const Monitor *mon, unsigned int cmd_flags) +{ + switch (mon->mc->mode) { + case QMODE_OPERATIONAL: + if (cmd_flags & HANDLER_HANDSHAKE_ONLY) { + goto mode_error; + } + break; + case QMODE_HANDSHAKE: + if (!((cmd_flags & HANDLER_HANDSHAKE) || + (cmd_flags & HANDLER_HANDSHAKE_ONLY))) { + goto mode_error; + } + break; + default: + abort(); + } + + return 0; + +mode_error: + qemu_error_new(QERR_QMP_INVALID_MODE_COMMAND); + return 1; +} + static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) { int err; QObject *obj; QDict *input, *args; const mon_cmd_t *cmd; + unsigned int cmd_flags; Monitor *mon = cur_mon; const char *cmd_name, *info_item; @@ -4213,6 +4240,15 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); goto err_input; } else if (strstart(cmd_name, "query-", &info_item)) { + /* check it exists and get its flags */ + cmd = monitor_find_info_command(info_item); + if (!cmd) { + qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); + goto err_input; + } + cmd_flags = cmd->flags; + + /* setup 'info' to call it */ cmd = monitor_find_command("info"); qdict_put_obj(input, "arguments", qobject_from_jsonf("{ 'item': %s }", info_item)); @@ -4222,6 +4258,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) qemu_error_new(QERR_COMMAND_NOT_FOUND, cmd_name); goto err_input; } + cmd_flags = cmd->flags; + } + + if (qmp_mode_invalid(mon, cmd_flags)) { + goto err_input; } obj = qdict_get(input, "arguments");