From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euDtY-0007rA-6N for qemu-devel@nongnu.org; Fri, 09 Mar 2018 04:01:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euDtS-0007wx-Il for qemu-devel@nongnu.org; Fri, 09 Mar 2018 04:00:56 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58842 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1euDtS-0007wg-ER for qemu-devel@nongnu.org; Fri, 09 Mar 2018 04:00:50 -0500 From: Peter Xu Date: Fri, 9 Mar 2018 16:59:49 +0800 Message-Id: <20180309090006.10018-7-peterx@redhat.com> In-Reply-To: <20180309090006.10018-1-peterx@redhat.com> References: <20180309090006.10018-1-peterx@redhat.com> Subject: [Qemu-devel] [PATCH v8 06/23] monitor: move the cur_mon hack deeper for QMP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Daniel P . Berrange" , Paolo Bonzini , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Eric Blake , Laurent Vivier , Markus Armbruster , marcandre.lureau@redhat.com, "Dr . David Alan Gilbert" In monitor_qmp_read(), we have the hack to temporarily replace the cur_mon pointer. Now we move this hack deeper inside the QMP dispatcher routine since the Monitor pointer can be actually obtained using container_of() upon the parser object, just like most of the other JSON parser users do. This does not make much sense as a single patch. However, this will be a big step for the next patch, when the QMP dispatcher routine will be split from the QMP parser. Reviewed-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Peter Xu --- monitor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/monitor.c b/monitor.c index 48645e0e91..2b70294772 100644 --- a/monitor.c +++ b/monitor.c @@ -3762,7 +3762,9 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) { QObject *req, *rsp = NULL, *id = NULL; QDict *qdict = NULL; - Monitor *mon = cur_mon; + MonitorQMP *mon_qmp = container_of(parser, MonitorQMP, parser); + Monitor *old_mon, *mon = container_of(mon_qmp, Monitor, qmp); + Error *err = NULL; req = json_parser_parse_err(tokens, NULL, &err); @@ -3787,8 +3789,13 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) QDECREF(req_json); } + old_mon = cur_mon; + cur_mon = mon; + rsp = qmp_dispatch(cur_mon->qmp.commands, req); + cur_mon = old_mon; + if (mon->qmp.commands == &qmp_cap_negotiation_commands) { qdict = qdict_get_qdict(qobject_to_qdict(rsp), "error"); if (qdict @@ -3825,13 +3832,9 @@ err_out: static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { - Monitor *old_mon = cur_mon; - - cur_mon = opaque; - - json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, size); + Monitor *mon = opaque; - cur_mon = old_mon; + json_message_parser_feed(&mon->qmp.parser, (const char *) buf, size); } static void monitor_read(void *opaque, const uint8_t *buf, int size) -- 2.14.3