From nobody Tue Nov 4 18:32:08 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 1530654668628492.41883855694186; Tue, 3 Jul 2018 14:51:08 -0700 (PDT) Received: from localhost ([::1]:42935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faTCV-0003NN-W3 for importer@patchew.org; Tue, 03 Jul 2018 17:51:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faSxw-000879-N4 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 17:36:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faSxt-0006Ca-2r for qemu-devel@nongnu.org; Tue, 03 Jul 2018 17:36:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48968 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 1faSxs-0006Al-Nw for qemu-devel@nongnu.org; Tue, 03 Jul 2018 17:36:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 157A7701EA for ; Tue, 3 Jul 2018 21:36:00 +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 CAF0F20290AB for ; Tue, 3 Jul 2018 21:35:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F2DF41132BC2; Tue, 3 Jul 2018 23:35:56 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 23:35:48 +0200 Message-Id: <20180703213556.20619-25-armbru@redhat.com> In-Reply-To: <20180703213556.20619-1-armbru@redhat.com> References: <20180703213556.20619-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 03 Jul 2018 21:36:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 03 Jul 2018 21:36:00 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] [PULL v2 24/32] qmp: Replace monitor_json_emitter{, raw}() by qmp_{queue, send}_response() 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: , 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" monitor_json_emitter() and monitor_json_emitter_raw() are unnecessarily general: they can send arbitrary JSON values, even though we only ever use them for QMP, which may send only JSON objects. Specialize the argument from QObject * to QDict *, and rename to qmp_queue_response(), qmp_send_response(). All callers but one lose an upcast. The lone exception gains a downcast; the next commit will get rid of it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180703085358.13941-25-armbru@redhat.com> --- monitor.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/monitor.c b/monitor.c index 8237b1c916..50dc57c82e 100644 --- a/monitor.c +++ b/monitor.c @@ -503,9 +503,9 @@ int monitor_fprintf(FILE *stream, const char *fmt, ...) return 0; } =20 -static void monitor_json_emitter_raw(Monitor *mon, - QObject *data) +static void qmp_send_response(Monitor *mon, QDict *rsp) { + QObject *data =3D QOBJECT(rsp); QString *json; =20 json =3D mon->flags & MONITOR_USE_PRETTY ? qobject_to_json_pretty(data= ) : @@ -518,7 +518,7 @@ static void monitor_json_emitter_raw(Monitor *mon, qobject_unref(json); } =20 -static void monitor_json_emitter(Monitor *mon, QObject *data) +static void qmp_queue_response(Monitor *mon, QDict *rsp) { if (mon->use_io_thread) { /* @@ -528,8 +528,7 @@ static void monitor_json_emitter(Monitor *mon, QObject = *data) * responder thread). */ qemu_mutex_lock(&mon->qmp.qmp_queue_lock); - g_queue_push_tail(mon->qmp.qmp_responses, - qobject_ref(qobject_to(QDict, data))); + g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(rsp)); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); qemu_bh_schedule(qmp_respond_bh); } else { @@ -537,7 +536,7 @@ static void monitor_json_emitter(Monitor *mon, QObject = *data) * If not using monitor I/O thread, then we are in main thread. * Do the emission right away. */ - monitor_json_emitter_raw(mon, data); + qmp_send_response(mon, rsp); } } =20 @@ -563,7 +562,7 @@ static void monitor_qmp_response_flush(Monitor *mon) QDict *data; =20 while ((data =3D monitor_qmp_response_pop_one(mon))) { - monitor_json_emitter_raw(mon, QOBJECT(data)); + qmp_send_response(mon, data); qobject_unref(data); } } @@ -595,7 +594,7 @@ static void monitor_qmp_bh_responder(void *opaque) QMPResponse response; =20 while (monitor_qmp_response_pop_any(&response)) { - monitor_json_emitter_raw(response.mon, QOBJECT(response.data)); + qmp_send_response(response.mon, response.data); qobject_unref(response.data); } } @@ -622,7 +621,7 @@ static void monitor_qapi_event_emit(QAPIEvent event, QD= ict *qdict) QTAILQ_FOREACH(mon, &mon_list, entry) { if (monitor_is_qmp(mon) && mon->qmp.commands !=3D &qmp_cap_negotiation_commands) { - monitor_json_emitter(mon, QOBJECT(qdict)); + qmp_queue_response(mon, qdict); } } } @@ -4118,7 +4117,7 @@ static void monitor_qmp_respond(Monitor *mon, QDict *= rsp, qdict_put_obj(rsp, "id", qobject_ref(id)); } =20 - monitor_json_emitter(mon, QOBJECT(rsp)); + qmp_queue_response(mon, rsp); } =20 qobject_unref(id); @@ -4418,7 +4417,7 @@ static void monitor_qmp_event(void *opaque, int event) mon->qmp.commands =3D &qmp_cap_negotiation_commands; monitor_qmp_caps_reset(mon); data =3D get_qmp_greeting(mon); - monitor_json_emitter(mon, data); + qmp_queue_response(mon, qobject_to(QDict, data)); qobject_unref(data); mon_refcount++; break; --=20 2.17.1