From nobody Tue Nov 4 18:40:42 2025 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 1530608504038513.9571557381723; Tue, 3 Jul 2018 02:01:44 -0700 (PDT) Received: from localhost ([::1]:38955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faHBt-0007kd-EK for importer@patchew.org; Tue, 03 Jul 2018 05:01:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faH4X-0001Re-Ax for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faH4V-0007Dq-90 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51392 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 1faH4V-0007D9-3z for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:03 -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 A045F40267A1; Tue, 3 Jul 2018 08:54:02 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-126.ams2.redhat.com [10.36.116.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5841D215688A; Tue, 3 Jul 2018 08:54:02 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CAD631132D3F; Tue, 3 Jul 2018 10:53:58 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 10:53:41 +0200 Message-Id: <20180703085358.13941-16-armbru@redhat.com> In-Reply-To: <20180703085358.13941-1-armbru@redhat.com> References: <20180703085358.13941-1-armbru@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.6]); Tue, 03 Jul 2018 08:54:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Jul 2018 08:54:02 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@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] [PATCH v2 15/32] qmp: Simplify code around monitor_qmp_dispatch_one() 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: mdroth@linux.vnet.ibm.com, stefanha@redhat.com, peterx@redhat.com, dgilbert@redhat.com 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" Change monitor_qmp_dispatch_one() to take its parameters unwrapped, move monitor_resume() to the one caller that needs it, rename the function to monitor_qmp_dispatch(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 58 +++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/monitor.c b/monitor.c index 94f5660c3c..51ba1485ad 100644 --- a/monitor.c +++ b/monitor.c @@ -4166,20 +4166,10 @@ static void monitor_qmp_respond(Monitor *mon, QObje= ct *rsp, qobject_unref(rsp); } =20 -/* - * Dispatch one single QMP request. The function will free the req_obj - * and objects inside it before return. - */ -static void monitor_qmp_dispatch_one(QMPRequest *req_obj) +static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id) { - Monitor *mon, *old_mon; - QObject *req, *rsp =3D NULL, *id; - bool need_resume; - - req =3D req_obj->req; - mon =3D req_obj->mon; - id =3D req_obj->id; - need_resume =3D req_obj->need_resume; + Monitor *old_mon; + QObject *rsp; =20 old_mon =3D cur_mon; cur_mon =3D mon; @@ -4188,15 +4178,7 @@ static void monitor_qmp_dispatch_one(QMPRequest *req= _obj) =20 cur_mon =3D old_mon; =20 - /* Respond if necessary */ monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id)); - - /* This pairs with the monitor_suspend() in handle_qmp_command(). */ - if (need_resume) { - monitor_resume(mon); - } - - qmp_request_free(req_obj); } =20 /* @@ -4240,12 +4222,20 @@ static void monitor_qmp_bh_dispatcher(void *data) { QMPRequest *req_obj =3D monitor_qmp_requests_pop_any(); =20 - if (req_obj) { - trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: = ""); - monitor_qmp_dispatch_one(req_obj); - /* Reschedule instead of looping so the main loop stays responsive= */ - qemu_bh_schedule(mon_global.qmp_dispatcher_bh); + if (!req_obj) { + return; } + + trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: ""); + monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); + if (req_obj->need_resume) { + /* Pairs with the monitor_suspend() in handle_qmp_command() */ + monitor_resume(req_obj->mon); + } + qmp_request_free(req_obj); + + /* Reschedule instead of looping so the main loop stays responsive */ + qemu_bh_schedule(mon_global.qmp_dispatcher_bh); } =20 #define QMP_REQ_QUEUE_LEN_MAX (8) @@ -4291,20 +4281,20 @@ static void handle_qmp_command(JSONMessageParser *p= arser, GQueue *tokens) goto err; } =20 + if (qmp_is_oob(qdict)) { + /* Out-of-band (OOB) requests are executed directly in parser. */ + trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) + ?: ""); + monitor_qmp_dispatch(mon, req, id); + return; + } + req_obj =3D g_new0(QMPRequest, 1); req_obj->mon =3D mon; req_obj->id =3D id; req_obj->req =3D req; req_obj->need_resume =3D false; =20 - if (qmp_is_oob(qdict)) { - /* Out-of-band (OOB) requests are executed directly in parser. */ - trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(req_obj->id) - ?: ""); - monitor_qmp_dispatch_one(req_obj); - return; - } - /* Protect qmp_requests and fetching its length. */ qemu_mutex_lock(&mon->qmp.qmp_queue_lock); =20 --=20 2.17.1