From patchwork Thu Jan 21 21:09:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 43456 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 1BB2DB7CDA for ; Fri, 22 Jan 2010 08:28:24 +1100 (EST) Received: from localhost ([127.0.0.1]:44077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY4ZF-00083X-09 for incoming@patchwork.ozlabs.org; Thu, 21 Jan 2010 16:27:53 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NY4IQ-0000w9-7v for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:30 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NY4IL-0000pv-5F for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:29 -0500 Received: from [199.232.76.173] (port=43489 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY4IK-0000ph-Re for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42708) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NY4IK-00030L-8G for qemu-devel@nongnu.org; Thu, 21 Jan 2010 16:10:24 -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 o0LLANWr005101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Jan 2010 16:10:23 -0500 Received: from localhost (vpn-9-176.rdu.redhat.com [10.11.9.176]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0LLAL8Z027615; Thu, 21 Jan 2010 16:10:22 -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:37 -0200 Message-Id: <1264108180-3666-9-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.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 08/11] QMP: Asynchronous messages enable/disable 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 commit disables asynchronous messages by default and introduces two new QMP commands: async_msg_enable and async_msg_disable. Each QMP Monitor has its own set of asynchronous messages, so for example, if QEMU is run with two QMP Monitors async messages setup in one of them doesn't affect the other. To implement this design a bitmap is introduced to the Monitor struct, each async message is represented by one bit. Signed-off-by: Luiz Capitulino --- monitor.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- qemu-monitor.hx | 30 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 61c0273..321bc3a 100644 --- a/monitor.c +++ b/monitor.c @@ -108,11 +108,14 @@ typedef enum QMPMode { QMODE_HANDSHAKE, } QMPMode; +#define EVENTS_BITMAP_SIZE (QEVENT_MAX / 8) + typedef struct MonitorControl { QObject *id; QMPMode mode; int print_enabled; JSONMessageParser parser; + uint8_t events_bitmap[EVENTS_BITMAP_SIZE]; } MonitorControl; struct Monitor { @@ -318,6 +321,23 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data) QDECREF(qmp); } +static void qevent_set(const Monitor *mon, int64_t event) +{ + assert(event >= 0 && event < QEVENT_MAX); + mon->mc->events_bitmap[event / 8] |= (1 << (event % 8)); +} + +static void qevent_unset(const Monitor *mon, int64_t event) +{ + assert(event >= 0 && event < QEVENT_MAX); + mon->mc->events_bitmap[event / 8] &= ~(1 << (event % 8)); +} + +static int qevent_enabled(const Monitor *mon, int64_t event) +{ + return (mon->mc->events_bitmap[event / 8] & (1 << (event % 8))); +} + static void timestamp_put(QDict *qdict) { int err; @@ -389,7 +409,8 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) } QLIST_FOREACH(mon, &mon_list, entry) { - if (monitor_ctrl_mode(mon)) { + if (monitor_ctrl_mode(mon) && + qevent_enabled(mon, event)) { monitor_json_emitter(mon, QOBJECT(qmp)); } } @@ -465,6 +486,32 @@ static void do_commit(Monitor *mon, const QDict *qdict) } } +static void qevent_set_value(Monitor *mon, const QDict *qdict, int value) +{ + int i; + const char *name = qdict_get_str(qdict, "name"); + + for (i = 0; monitor_events_names[i].name != NULL; i++) { + if (!strcmp(monitor_events_names[i].name, name)) { + return (value ? qevent_set(mon, i) : qevent_unset(mon, i)); + } + } + + qemu_error_new(QERR_ASYNC_MSG_NOT_FOUND, name); +} + +static void do_async_msg_enable(Monitor *mon, const QDict *qdict, + QObject **ret_data) +{ + qevent_set_value(mon, qdict, 1); +} + +static void do_async_msg_disable(Monitor *mon, const QDict *qdict, + QObject **ret_data) +{ + qevent_set_value(mon, qdict, 0); +} + static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data) { const mon_cmd_t *cmd; diff --git a/qemu-monitor.hx b/qemu-monitor.hx index eebea09..0f3dfde 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -1077,6 +1077,36 @@ STEXI Switch QMP to @var{mode} ETEXI + { + .name = "async_msg_enable", + .args_type = "name:s", + .params = "async_msg_enable name", + .help = "enable an asynchronous message", + .flags = HANDLER_HANDSHAKE_ONLY, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_async_msg_enable, + }, + +STEXI +@item async_msg_enable @var{name} +Enable the asynchronous message @var{name} +ETEXI + + { + .name = "async_msg_disable", + .args_type = "name:s", + .params = "async_msg_disable name", + .help = "disable an asynchronous message", + .flags = HANDLER_HANDSHAKE_ONLY, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_async_msg_disable, + }, + +STEXI +@item async_msg_disable @var{name} +Disable the asynchronous message @var{name} +ETEXI + STEXI @end table ETEXI