From nobody Mon Feb 9 19:06:04 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520881603435225.4191679854796; Mon, 12 Mar 2018 12:06:43 -0700 (PDT) Received: from localhost ([::1]:34067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evSmQ-0004Bs-Hp for importer@patchew.org; Mon, 12 Mar 2018 15:06:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evSJV-0000ib-SM for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:36:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evSJU-0005yx-WC for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:36:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38332 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 1evSJU-0005yf-ST for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:36:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76CCE8D6D7 for ; Mon, 12 Mar 2018 18:36:48 +0000 (UTC) Received: from red.redhat.com (ovpn-121-135.rdu2.redhat.com [10.10.121.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E1FE215CDAC; Mon, 12 Mar 2018 18:36:47 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 12 Mar 2018 13:36:08 -0500 Message-Id: <20180312183628.394722-18-eblake@redhat.com> In-Reply-To: <20180312183628.394722-1-eblake@redhat.com> References: <20180312183628.394722-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 12 Mar 2018 18:36:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 12 Mar 2018 18:36:48 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/36] 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: "Dr. David Alan Gilbert" , Peter Xu , Markus Armbruster 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" From: Peter Xu 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 Message-Id: <20180309090006.10018-7-peterx@redhat.com> [eblake: rebase context of qobject_to() macro] Signed-off-by: Eric Blake --- monitor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/monitor.c b/monitor.c index b5acc92b735..83e98741b4c 100644 --- a/monitor.c +++ b/monitor.c @@ -3762,7 +3762,9 @@ 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; + MonitorQMP *mon_qmp =3D container_of(parser, MonitorQMP, parser); + Monitor *old_mon, *mon =3D container_of(mon_qmp, Monitor, qmp); + Error *err =3D NULL; req =3D json_parser_parse_err(tokens, NULL, &err); @@ -3787,8 +3789,13 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) QDECREF(req_json); } + old_mon =3D cur_mon; + cur_mon =3D mon; + rsp =3D qmp_dispatch(cur_mon->qmp.commands, req); + 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 @@ -3825,13 +3832,9 @@ err_out: static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { - Monitor *old_mon =3D cur_mon; + Monitor *mon =3D opaque; - cur_mon =3D opaque; - - json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, siz= e); - - cur_mon =3D 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) --=20 2.14.3