From nobody Tue Nov 4 18:42: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 1530608882796509.00309230464416; Tue, 3 Jul 2018 02:08:02 -0700 (PDT) Received: from localhost ([::1]:38986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faHHy-0004cL-4p for importer@patchew.org; Tue, 03 Jul 2018 05:07:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faH4Z-0001SJ-Ky for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faH4W-0007FO-F3 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51092 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 1faH4W-0007EW-AF for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:04 -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 C55EBF68B2; Tue, 3 Jul 2018 08:54:03 +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 7F151202704B; Tue, 3 Jul 2018 08:54:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E9E761132BC2; Tue, 3 Jul 2018 10:53:58 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 10:53:50 +0200 Message-Id: <20180703085358.13941-25-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.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 03 Jul 2018 08:54:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 03 Jul 2018 08:54:03 +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] [PATCH 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: , 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" 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 --- monitor.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/monitor.c b/monitor.c index 0f7a96213f..399ad6b4e0 100644 --- a/monitor.c +++ b/monitor.c @@ -502,9 +502,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= ) : @@ -517,7 +517,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) { /* @@ -527,8 +527,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 { @@ -536,7 +535,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 @@ -562,7 +561,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); } } @@ -594,7 +593,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); } } @@ -621,7 +620,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); } } } @@ -4117,7 +4116,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); @@ -4417,7 +4416,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