From nobody Mon Feb 9 06:01:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509962148269258.0326803754309; Mon, 6 Nov 2017 01:55:48 -0800 (PST) Received: from localhost ([::1]:47212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBe83-0001zS-MZ for importer@patchew.org; Mon, 06 Nov 2017 04:55:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBe1C-0004Xl-38 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 04:48:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBe1B-0004ET-4d for qemu-devel@nongnu.org; Mon, 06 Nov 2017 04:48:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57244) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBe1A-0004E7-Rt for qemu-devel@nongnu.org; Mon, 06 Nov 2017 04:48:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE159883A0; Mon, 6 Nov 2017 09:48:31 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-165.pek2.redhat.com [10.72.12.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id D74076A02D; Mon, 6 Nov 2017 09:48:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE159883A0 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 6 Nov 2017 17:46:23 +0800 Message-Id: <20171106094643.14881-8-peterx@redhat.com> In-Reply-To: <20171106094643.14881-1-peterx@redhat.com> References: <20171106094643.14881-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 06 Nov 2017 09:48:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v3 07/27] monitor: move the cur_mon hack deeper for QMP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , Jiri Denemark , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 passed in to that using the new JSON Parser opaque field now. 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: Eric Blake Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- monitor.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index ab80d32c70..322dfb5f31 100644 --- a/monitor.c +++ b/monitor.c @@ -3813,7 +3813,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens, { QObject *req, *rsp =3D NULL, *id =3D NULL; QDict *qdict =3D NULL; - Monitor *mon =3D cur_mon; + Monitor *mon =3D opaque, *old_mon; Error *err =3D NULL; =20 req =3D json_parser_parse_err(tokens, NULL, &err); @@ -3838,8 +3838,13 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens, QDECREF(req_json); } =20 + old_mon =3D cur_mon; + cur_mon =3D mon; + rsp =3D qmp_dispatch(cur_mon->qmp.commands, req); =20 + cur_mon =3D old_mon; + if (mon->qmp.commands =3D=3D &qmp_cap_negotiation_commands) { qdict =3D qdict_get_qdict(qobject_to_qdict(rsp), "error"); if (qdict @@ -3876,13 +3881,9 @@ err_out: =20 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { - Monitor *old_mon =3D cur_mon; - - cur_mon =3D opaque; - - json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, siz= e); + Monitor *mon =3D opaque; =20 - cur_mon =3D old_mon; + json_message_parser_feed(&mon->qmp.parser, (const char *) buf, size); } =20 static void monitor_read(void *opaque, const uint8_t *buf, int size) @@ -3956,7 +3957,7 @@ static void monitor_qmp_event(void *opaque, int event) break; case CHR_EVENT_CLOSED: json_message_parser_destroy(&mon->qmp.parser); - json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NUL= L); + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon= ); mon_refcount--; monitor_fdsets_cleanup(); break; @@ -4106,7 +4107,7 @@ void monitor_init(Chardev *chr, int flags) qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, monitor_qmp_event, NULL, mon, NULL, true); qemu_chr_fe_set_echo(&mon->chr, true); - json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NUL= L); + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon= ); } else { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read, monitor_event, NULL, mon, NULL, true); --=20 2.13.5