From nobody Tue Nov 4 15:26:29 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 1530549947840102.63848950474755; Mon, 2 Jul 2018 09:45:47 -0700 (PDT) Received: from localhost ([::1]:34212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1xP-0005Fj-Jg for importer@patchew.org; Mon, 02 Jul 2018 12:45:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004TA-MQ for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006ec-0i for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54116 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 1fa1aq-0006dA-O1 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37E33402315B for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E5D6111CA1A; Mon, 2 Jul 2018 16:22:19 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 65B3D1138529; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:47 +0200 Message-Id: <20180702162218.13678-2-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 01/32] qmp: Say "out-of-band" instead of "Out-Of-Band" 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: 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" Affects documentation and a few error messages. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 2 +- docs/interop/qmp-spec.txt | 2 +- monitor.c | 14 +++++++------- qapi/misc.json | 2 +- tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qmp-test.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 94a7e8f4d0..9625798d16 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -641,7 +641,7 @@ possible, the command expression should include the opt= ional key 'success-response' with boolean value false. So far, only QGA makes use of this member. =20 -A command can be declared to support Out-Of-Band (OOB) execution. By +A command can be declared to support out-of-band (OOB) execution. By default, commands do not support OOB. To declare a command that supports it, the schema includes an extra 'allow-oob' field. For example: diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt index 6fa193a80b..2bb492d1ea 100644 --- a/docs/interop/qmp-spec.txt +++ b/docs/interop/qmp-spec.txt @@ -85,7 +85,7 @@ The greeting message format is: =20 Currently supported capabilities are: =20 -- "oob": the QMP server supports "Out-Of-Band" (OOB) command +- "oob": the QMP server supports "out-of-band" (OOB) command execution. For more details, please see the "run-oob" parameter in the "Issuing Commands" section below. Not all commands allow this "oob" execution. The "query-qmp-schema" command can be used to diff --git a/monitor.c b/monitor.c index 567668a0e7..f5f20e36e3 100644 --- a/monitor.c +++ b/monitor.c @@ -1267,11 +1267,11 @@ static void qmp_caps_check(Monitor *mon, QMPCapabil= ityList *list, case QMP_CAPABILITY_OOB: if (!mon->use_io_thr) { /* - * Out-Of-Band only works with monitors that are + * Out-of-band only works with monitors that are * running on dedicated IOThread. */ error_setg(errp, "This monitor does not support " - "Out-Of-Band (OOB)"); + "out-of-band (OOB)"); return; } break; @@ -1319,7 +1319,7 @@ static bool qmp_cmd_oob_check(Monitor *mon, QDict *re= q, Error **errp) =20 if (qmp_is_oob(req)) { if (!qmp_oob_enabled(mon)) { - error_setg(errp, "Please enable Out-Of-Band first " + error_setg(errp, "Please enable out-of-band first " "for the session during capabilities negotiation"); return false; } @@ -4293,7 +4293,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) =20 /* When OOB is enabled, the "id" field is mandatory. */ if (qmp_oob_enabled(mon) && !id) { - error_setg(&err, "Out-Of-Band capability requires that " + error_setg(&err, "Out-of-band capability requires that " "every command contains an 'id' field"); goto err; } @@ -4307,7 +4307,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) qdict_del(qdict, "id"); =20 if (qmp_is_oob(qdict)) { - /* Out-Of-Band (OOB) requests are executed directly in parser. */ + /* 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); @@ -4683,12 +4683,12 @@ void monitor_init(Chardev *chr, int flags) =20 if (use_oob) { if (CHARDEV_IS_MUX(chr)) { - error_report("Monitor Out-Of-Band is not supported with " + error_report("Monitor out-of-band is not supported with " "MUX typed chardev backend"); exit(1); } if (use_readline) { - error_report("Monitor Out-Of-band is only supported by QMP"); + error_report("Monitor out-of-band is only supported by QMP"); exit(1); } } diff --git a/qapi/misc.json b/qapi/misc.json index 29da7856e3..0446c3e48e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -46,7 +46,7 @@ # Enumeration of capabilities to be advertised during initial client # connection, used for agreeing on particular QMP extension behaviors. # -# @oob: QMP ability to support Out-Of-Band requests. +# @oob: QMP ability to support out-of-band requests. # (Please refer to qmp-spec.txt for more information on OOB) # # Since: 2.12 diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 7b59817f04..e9e401c01f 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -141,7 +141,7 @@ { 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } { 'command': 'boxed-union', 'data': 'UserDefNativeListUnion', 'boxed': tru= e } =20 -# Smoke test on Out-Of-Band and allow-preconfig-test +# Smoke test on out-of-band and allow-preconfig-test { 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': t= rue } =20 # For testing integer range flattening in opts-visitor. The following sche= ma diff --git a/tests/qmp-test.c b/tests/qmp-test.c index a49cbc6fde..5206b14ca6 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -135,7 +135,7 @@ static void test_qmp_protocol(void) qtest_quit(qts); } =20 -/* Tests for Out-Of-Band support. */ +/* Tests for out-of-band support. */ static void test_qmp_oob(void) { QTestState *qts; --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549779875744.9338658525046; Mon, 2 Jul 2018 09:42:59 -0700 (PDT) Received: from localhost ([::1]:34196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1uh-0002wC-1Y for importer@patchew.org; Mon, 02 Jul 2018 12:42:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004Sm-Et for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006eM-01 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47588 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 1fa1aq-0006d3-M7 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 356FB7D84D for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E65F111AF34; Mon, 2 Jul 2018 16:22:19 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 695281132F3C; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:48 +0200 Message-Id: <20180702162218.13678-3-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 02/32] monitor: Spell "I/O thread" consistently in comments 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: 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/monitor.c b/monitor.c index f5f20e36e3..3fb05d50aa 100644 --- a/monitor.c +++ b/monitor.c @@ -242,7 +242,7 @@ struct Monitor { /* Let's add monitor global variables to this struct. */ static struct { IOThread *mon_iothread; - /* Bottom half to dispatch the requests received from IO thread */ + /* Bottom half to dispatch the requests received from I/O thread */ QEMUBH *qmp_dispatcher_bh; /* Bottom half to deliver the responses back to clients */ QEMUBH *qmp_respond_bh; @@ -517,7 +517,7 @@ static void monitor_json_emitter(Monitor *mon, QObject = *data) { if (mon->use_io_thr) { /* - * If using IO thread, we need to queue the item so that IO + * If using I/O thread, we need to queue the item so that I/O * thread will do the rest for us. Take refcount so that * caller won't free the data (which will be finally freed in * responder thread). @@ -528,7 +528,7 @@ static void monitor_json_emitter(Monitor *mon, QObject = *data) qemu_bh_schedule(mon_global.qmp_respond_bh); } else { /* - * If not using monitor IO thread, then we are in main thread. + * If not using monitor I/O thread, then we are in main thread. * Do the emission right away. */ monitor_json_emitter_raw(mon, data); @@ -1268,7 +1268,7 @@ static void qmp_caps_check(Monitor *mon, QMPCapabilit= yList *list, if (!mon->use_io_thr) { /* * Out-of-band only works with monitors that are - * running on dedicated IOThread. + * running on dedicated I/O thread. */ error_setg(errp, "This monitor does not support " "out-of-band (OOB)"); @@ -4402,7 +4402,7 @@ int monitor_suspend(Monitor *mon) =20 if (monitor_is_qmp(mon)) { /* - * Kick iothread to make sure this takes effect. It'll be + * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ aio_notify(iothread_get_aio_context(mon_global.mon_iothread)); @@ -4421,7 +4421,7 @@ void monitor_resume(Monitor *mon) if (atomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { if (monitor_is_qmp(mon)) { /* - * For QMP monitors that are running in IOThread, let's + * For QMP monitors that are running in I/O thread, let's * kick the thread in case it's sleeping. */ if (mon->use_io_thr) { @@ -4445,7 +4445,7 @@ static QObject *get_qmp_greeting(Monitor *mon) =20 for (cap =3D 0; cap < QMP_CAPABILITY__MAX; cap++) { if (!mon->use_io_thr && cap =3D=3D QMP_CAPABILITY_OOB) { - /* Monitors that are not using IOThread won't support OOB */ + /* Monitors that are not using I/O thread won't support OOB */ continue; } qlist_append_str(cap_list, QMPCapability_str(cap)); @@ -4586,9 +4586,9 @@ static void monitor_iothread_init(void) NULL); =20 /* - * Unlike the dispatcher BH, this must be run on the monitor IO - * thread, so that monitors that are using IO thread will make - * sure read/write operations are all done on the IO thread. + * Unlike the dispatcher BH, this must be run on the monitor I/O + * thread, so that monitors that are using I/O thread will make + * sure read/write operations are all done on the I/O thread. */ mon_global.qmp_respond_bh =3D aio_bh_new(monitor_get_aio_context(), monitor_qmp_bh_responder, @@ -4660,7 +4660,7 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) if (mon->use_io_thr) { /* * When use_io_thr is set, we use the global shared dedicated - * IO thread for this monitor to handle input/output. + * I/O thread for this monitor to handle input/output. */ context =3D monitor_get_io_context(); /* We should have inited globals before reaching here. */ @@ -4717,7 +4717,7 @@ void monitor_init(Chardev *chr, int flags) /* * We can't call qemu_chr_fe_set_handlers() directly here * since during the procedure the chardev will be active - * and running in monitor iothread, while we'll still do + * and running in monitor I/O thread, while we'll still do * something before returning from it, which is a possible * race too. To avoid that, we just create a BH to setup * the handlers. @@ -4744,16 +4744,16 @@ void monitor_cleanup(void) Monitor *mon, *next; =20 /* - * We need to explicitly stop the iothread (but not destroy it), - * cleanup the monitor resources, then destroy the iothread since + * We need to explicitly stop the I/O thread (but not destroy it), + * cleanup the monitor resources, then destroy the I/O thread since * we need to unregister from chardev below in * monitor_data_destroy(), and chardev is not thread-safe yet */ iothread_stop(mon_global.mon_iothread); =20 /* - * After we have IOThread to send responses, it's possible that - * when we stop the IOThread there are still replies queued in the + * After we have I/O thread to send responses, it's possible that + * when we stop the I/O thread there are still replies queued in the * responder queue. Flush all of them. Note that even after this * flush it's still possible that out buffer is not flushed. * It'll be done in below monitor_flush() as the last resort. @@ -4769,7 +4769,7 @@ void monitor_cleanup(void) } qemu_mutex_unlock(&monitor_lock); =20 - /* QEMUBHs needs to be deleted before destroying the IOThread. */ + /* QEMUBHs needs to be deleted before destroying the I/O thread */ qemu_bh_delete(mon_global.qmp_dispatcher_bh); mon_global.qmp_dispatcher_bh =3D NULL; qemu_bh_delete(mon_global.qmp_respond_bh); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549422658229.68529888247895; Mon, 2 Jul 2018 09:37:02 -0700 (PDT) Received: from localhost ([::1]:34165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ox-0006iP-Fa for importer@patchew.org; Mon, 02 Jul 2018 12:36:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1at-0004RQ-5P for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ap-0006c8-NL for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47584 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 1fa1ap-0006bo-IB for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F9427CBBA for ; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E3781C5A7; Mon, 2 Jul 2018 16:22:19 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6CD481132DA0; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:49 +0200 Message-Id: <20180702162218.13678-4-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:23 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 03/32] docs/interop/qmp: Improve OOB documentation 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: 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" OOB documentation is spread over qmp-spec.txt sections 2.2.1 Capabilities and 2.3 Issuing Commands. The amount of detail is a bit distracting there. Move the meat of the matter to new section 2.3.1 Out of band execution. Throw in a few other improvements while there: * 2.2 Server Greetung: Drop advice to search entire capabilities array; should be obvious. * 3. QMP Examples - 3.1 Server Greeting: Update greeting to current one. Now shows capability "oob". Update qmp-intro.txt likewise. - 3.2 Capabilities negotiation: Show client accepting capability "oob". - 3.7 Out-of-band execution: New. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/interop/qmp-intro.txt | 13 +++---- docs/interop/qmp-spec.txt | 74 +++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/docs/interop/qmp-intro.txt b/docs/interop/qmp-intro.txt index 900d69d612..3dafa35ea6 100644 --- a/docs/interop/qmp-intro.txt +++ b/docs/interop/qmp-intro.txt @@ -52,13 +52,14 @@ Escape character is '^]'. "QMP": { "version": { "qemu": { - "micro": 50,=20 - "minor": 6,=20 - "major": 1 - },=20 - "package": "" - },=20 + "micro": 50, + "minor": 12, + "major": 2 + }, + "package": "v2.12.0-1763-g4e022f5ccd" + }, "capabilities": [ + "oob" ] } } diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt index 2bb492d1ea..e5f8116c54 100644 --- a/docs/interop/qmp-spec.txt +++ b/docs/interop/qmp-spec.txt @@ -77,8 +77,7 @@ The greeting message format is: is the same of the query-version command) - The "capabilities" member specify the availability of features beyond the baseline specification; the order of elements in this array has no - particular significance, so a client must search the entire array - when looking for a particular capability + particular significance. =20 2.2.1 Capabilities ------------------ @@ -86,16 +85,7 @@ The greeting message format is: Currently supported capabilities are: =20 - "oob": the QMP server supports "out-of-band" (OOB) command - execution. For more details, please see the "run-oob" parameter in - the "Issuing Commands" section below. Not all commands allow this - "oob" execution. The "query-qmp-schema" command can be used to - inspect which commands support "oob" execution. - -QMP clients can get a list of supported QMP capabilities of the QMP -server in the greeting message mentioned above. By default, all the -capabilities are off. To enable any QMP capabilities, the QMP client -needs to send the "qmp_capabilities" command with an extra parameter -for the requested capabilities. + execution, as described in section "2.3.1 Out-of-band execution". =20 2.3 Issuing Commands -------------------- @@ -115,14 +105,38 @@ The format for command execution is: - The "id" member is a transaction identification associated with the command execution. It is required for all commands if the OOB - capability was enabled at startup, and optional otherwise. The same - "id" field will be part of the response if provided. The "id" member - can be any json-value, although most clients merely use a - json-number incremented for each successive command -- The "control" member is optional, and currently only used for - out-of-band execution. The handling or response of an "oob" command - can overtake prior in-band commands. To enable "oob" handling of a - particular command, just provide a control field with: { "control": - { "run-oob": true } } + "id" field will be part of the response if provided. The "id" + member can be any json-value. A json-number incremented for each + successive command works fine. +- The optional "control" member further specifies how the command is + to be executed. Currently, its only member is optional "run-oob". + See section "2.3.1 Out-of-band execution" for details. + + +2.3.1 Out-of-band execution +--------------------------- + +The server normally reads, executes and responds to one command after +the other. The client therefore receives command respones in issue +order. + +With out-of-band execution enabled via capability negotiation (section +4.), the server reads and queues commands as they arrive. It executes +commands from the queue one after the other. Commands executed +out-of-band jump the queue: they command get executed right away, +possibly overtaking prior in-band commands. The client may therefore +receive such a command's response before responses from prior in-band +commands. + +To execute a command out-of-band, the client puts "run-oob": true into +execute's member "control". + +If the client sends in-band commands faster than the server can +execute them, the server will eventually drop commands to limit the +queue length. The sever sends event COMMAND_DROPPED then. + +Only a few commands support out-of-band execution. The ones that do +have "allow-oob": true in output of query-qmp-schema. =20 2.4 Commands Responses ---------------------- @@ -223,12 +237,13 @@ This section provides some examples of real QMP usage= , in all of them 3.1 Server greeting ------------------- =20 -S: { "QMP": { "version": { "qemu": { "micro": 50, "minor": 6, "major": 1 }, - "package": ""}, "capabilities": []}} +S: { "QMP": {"version": {"qemu": {"micro": 50, "minor": 12, "major": 2}, + "package": "v2.12.0-1763-g4e022f5ccd"}, "capabilities": ["oob"] } } =20 -3.2 Client QMP negotiation --------------------------- -C: { "execute": "qmp_capabilities" } +3.2 Capabilities negotiation +---------------------------- + +C: { "execute": "qmp_capabilities", "arguments": { "enable": ["oob"] } } S: { "return": {}} =20 3.3 Simple 'stop' execution @@ -255,6 +270,15 @@ S: { "error": { "class": "GenericError", "desc": "Inva= lid JSON syntax" } } S: { "timestamp": { "seconds": 1258551470, "microseconds": 802384 }, "event": "POWERDOWN" } =20 +3.7 Out-of-band execution +------------------------- + +C: { "execute": "migrate-pause", "id": 42, "control": { "run-oob": true } } +S: { "id": 42, + "error": { "class": "GenericError", + "desc": "migrate-pause is currently only supported during postcopy-a= ctive state" } } + + 4. Capabilities Negotiation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =20 --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549027621506.9440752738608; Mon, 2 Jul 2018 09:30:27 -0700 (PDT) Received: from localhost ([::1]:34129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1iY-0001we-HK for importer@patchew.org; Mon, 02 Jul 2018 12:30:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004R1-VV for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ap-0006c0-J5 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54930 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 1fa1ap-0006bk-Dm for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14E3540250FF for ; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E3351C5A5; Mon, 2 Jul 2018 16:22:19 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 703311132D6A; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:50 +0200 Message-Id: <20180702162218.13678-5-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:23 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 04/32] qmp: Document COMMAND_DROPPED design flaw 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: 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" Events are broadcast to all monitors. If another monitor's client has a command with the same ID in flight, the event will incorrectly claim that command was dropped. This must be fixed before out-of-band execution can graduate from "experimental". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 6 ++++++ qapi/misc.json | 3 +++ 2 files changed, 9 insertions(+) diff --git a/monitor.c b/monitor.c index 3fb05d50aa..96e87d8664 100644 --- a/monitor.c +++ b/monitor.c @@ -4330,6 +4330,12 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) /* Drop the request if queue is full. */ if (mon->qmp.qmp_requests->length >=3D QMP_REQ_QUEUE_LEN_MAX) { qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); + /* + * FIXME @id's scope is just @mon, and broadcasting it is + * wrong. If another monitor's client has a command with + * the same ID in flight, the event will incorrectly claim + * that command was dropped. + */ qapi_event_send_command_dropped(id, COMMAND_DROP_REASON_QUEUE_FULL, &error_abort); diff --git a/qapi/misc.json b/qapi/misc.json index 0446c3e48e..74cd97f237 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3454,6 +3454,9 @@ # only be dropped when the oob capability is enabled. # # @id: The dropped command's "id" field. +# FIXME Broken by design. Events are broadcast to all monitors. If +# another monitor's client has a command with the same ID in flight, +# the event will incorrectly claim that command was dropped. # # @reason: The reason why the command is dropped. # --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153054922370198.2072771657705; Mon, 2 Jul 2018 09:33:43 -0700 (PDT) Received: from localhost ([::1]:34147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ll-0004IZ-Or for importer@patchew.org; Mon, 02 Jul 2018 12:33:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004Qu-5g for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ao-0006aw-0p for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54926 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 1fa1an-0006ad-SH for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:21 -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 802A6407048A for ; Mon, 2 Jul 2018 16:22:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7D282166B5D; Mon, 2 Jul 2018 16:22:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 73AE41132D6B; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:51 +0200 Message-Id: <20180702162218.13678-6-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:21 +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 05/32] qmp: Get rid of x-oob-test command 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: 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" tests/qmp-test tests an out-of-band command overtaking a slow in-band command. To do that, it needs: 1. An in-band command that *reliably* takes long enough to be overtaken. 2. An out-of-band command to do the overtaking. 3. To avoid delays, a way to make the in-band command complete quickly after it was overtaken. To satisfy these needs, commit 469638f9cb3 provides the rather peculiar oob-capable QMP command x-oob-test: * With "lock": true, it waits for a global semaphore. * With "lock": false, it signals the global semaphore. To satisfy 1., the test runs x-oob-test in-band with "lock": true. To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false. Note that waiting for a semaphore violates the rules for oob-capable commands. Running x-oob-test with "lock": true hangs the monitor until you run x-oob-test with "lock": false on another monitor (which you might not have set up). Having an externally visible QMP command that may hang the monitor is not nice. Let's apply a little more ingenuity to the problem. Idea: have an existing command block on reading a FIFO special file, unblock it by opening the FIFO for writing. For 1., use {"execute": "blockdev-add", "id": ID1, "arguments": { "driver": "blkdebug", "node-name": ID1, "config": FIFO, "image": { "driver": "null-co"}}} where ID1 is an arbitrary string, and FIFO is the name of the FIFO. For 2., use {"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}} where ID2 is a different arbitrary string. Since there's no migration to pause, the command will fail, but that's fine. For 3., open FIFO for writing. Drop QMP command x-oob-test. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/misc.json | 18 ---------- qmp.c | 16 --------- tests/qmp-test.c | 93 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 64 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index 74cd97f237..f1860418e8 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3472,24 +3472,6 @@ { 'event': 'COMMAND_DROPPED' , 'data': { 'id': 'any', 'reason': 'CommandDropReason' } } =20 -## -# @x-oob-test: -# -# Test OOB functionality. When sending this command with lock=3Dtrue, -# it'll try to hang the dispatcher. When sending it with lock=3Dfalse, -# it'll try to notify the locked thread to continue. Note: it should -# only be used by QMP test program rather than anything else. -# -# Since: 2.12 -# -# Example: -# -# { "execute": "x-oob-test", -# "arguments": { "lock": true } } -## -{ 'command': 'x-oob-test', 'data' : { 'lock': 'bool' }, - 'allow-oob': true } - ## # @set-numa-node: # diff --git a/qmp.c b/qmp.c index 73e46d795f..62325ac6aa 100644 --- a/qmp.c +++ b/qmp.c @@ -775,19 +775,3 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp) =20 return mem_info; } - -static QemuSemaphore x_oob_test_sem; - -static void __attribute__((constructor)) x_oob_test_init(void) -{ - qemu_sem_init(&x_oob_test_sem, 0); -} - -void qmp_x_oob_test(bool lock, Error **errp) -{ - if (lock) { - qemu_sem_wait(&x_oob_test_sem); - } else { - qemu_sem_post(&x_oob_test_sem); - } -} diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 5206b14ca6..b4e54e8970 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -135,16 +135,64 @@ static void test_qmp_protocol(void) qtest_quit(qts); } =20 -/* Tests for out-of-band support. */ +/* Out-of-band tests */ + +char tmpdir[] =3D "/tmp/qmp-test-XXXXXX"; +char *fifo_name; + +static void setup_blocking_cmd(void) +{ + if (!mkdtemp(tmpdir)) { + g_error("mkdtemp: %s", strerror(errno)); + } + fifo_name =3D g_strdup_printf("%s/fifo", tmpdir); + g_assert(!mkfifo(fifo_name, 0666)); +} + +static void cleanup_blocking_cmd(void) +{ + unlink(fifo_name); + rmdir(tmpdir); +} + +static void send_cmd_that_blocks(QTestState *s, const char *id) +{ + qtest_async_qmp(s, "{ 'execute': 'blockdev-add', 'id': %s," + " 'arguments': {" + " 'driver': 'blkdebug', 'node-name': %s," + " 'config': %s," + " 'image': { 'driver': 'null-co' } } }", + id, id, fifo_name); +} + +static void unblock_blocked_cmd(void) +{ + int fd =3D open(fifo_name, O_WRONLY); + g_assert(fd >=3D 0); + close(fd); +} + +static void send_oob_cmd(QTestState *s, const char *id) +{ + qtest_async_qmp(s, "{ 'execute': 'migrate-pause', 'id': %s," + " 'control': { 'run-oob': true } }", id); +} + +static void recv_cmd_id(QTestState *s, const char *id) +{ + QDict *resp =3D qtest_qmp_receive(s); + + g_assert_cmpstr(qdict_get_try_str(resp, "id"), =3D=3D, id); + qobject_unref(resp); +} + static void test_qmp_oob(void) { QTestState *qts; QDict *resp, *q; - int acks =3D 0; const QListEntry *entry; QList *capabilities; QString *qstr; - const char *cmd_id; =20 qts =3D qtest_init_without_qmp_handshake(true, common_args); =20 @@ -185,37 +233,20 @@ static void test_qmp_oob(void) g_assert(qdict_haskey(resp, "error")); qobject_unref(resp); =20 - /* - * First send the "x-oob-test" command with lock=3Dtrue and - * oob=3Dfalse, it should hang the dispatcher and main thread; - * later, we send another lock=3Dfalse with oob=3Dtrue to continue - * that thread processing. Finally we should receive replies from - * both commands. - */ - qtest_async_qmp(qts, - "{ 'execute': 'x-oob-test'," - " 'arguments': { 'lock': true }, " - " 'id': 'lock-cmd'}"); - qtest_async_qmp(qts, - "{ 'execute': 'x-oob-test', " - " 'arguments': { 'lock': false }, " - " 'control': { 'run-oob': true }, " - " 'id': 'unlock-cmd' }"); - - /* Ignore all events. Wait for 2 acks */ - while (acks < 2) { - resp =3D qtest_qmp_receive(qts); - cmd_id =3D qdict_get_str(resp, "id"); - if (!g_strcmp0(cmd_id, "lock-cmd") || - !g_strcmp0(cmd_id, "unlock-cmd")) { - acks++; - } - qobject_unref(resp); - } + /* OOB command overtakes slow in-band command */ + setup_blocking_cmd(); + send_cmd_that_blocks(qts, "ib-blocks-1"); + send_oob_cmd(qts, "oob-1"); + recv_cmd_id(qts, "oob-1"); + unblock_blocked_cmd(); + recv_cmd_id(qts, "ib-blocks-1"); + cleanup_blocking_cmd(); =20 qtest_quit(qts); } =20 +/* Query smoke tests */ + static int query_error_class(const char *cmd) { static struct { @@ -392,6 +423,8 @@ static void add_query_tests(QmpSchema *schema) } } =20 +/* Preconfig tests */ + static void test_qmp_preconfig(void) { QDict *rsp, *ret; --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530548857229719.3864661419786; Mon, 2 Jul 2018 09:27:37 -0700 (PDT) Received: from localhost ([::1]:34118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1fq-00086G-Is for importer@patchew.org; Mon, 02 Jul 2018 12:27:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004Qw-5a for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1an-0006ak-N4 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47578 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 1fa1an-0006ab-JB for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:21 -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 3724E7C6A9 for ; Mon, 2 Jul 2018 16:22:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E874A2156880; Mon, 2 Jul 2018 16:22:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 774FC1132D6C; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:52 +0200 Message-Id: <20180702162218.13678-7-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.2]); Mon, 02 Jul 2018 16:22:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:21 +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 06/32] tests/qmp-test: Test in-band command doesn't overtake 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: 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/qmp-test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index b4e54e8970..3932901146 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -236,10 +236,12 @@ static void test_qmp_oob(void) /* OOB command overtakes slow in-band command */ setup_blocking_cmd(); send_cmd_that_blocks(qts, "ib-blocks-1"); + qtest_async_qmp(qts, "{ 'execute': 'query-name', 'id': 'ib-quick-1' }"= ); send_oob_cmd(qts, "oob-1"); recv_cmd_id(qts, "oob-1"); unblock_blocked_cmd(); recv_cmd_id(qts, "ib-blocks-1"); + recv_cmd_id(qts, "ib-quick-1"); cleanup_blocking_cmd(); =20 qtest_quit(qts); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530548857160861.2875131126814; Mon, 2 Jul 2018 09:27:37 -0700 (PDT) Received: from localhost ([::1]:34117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1fq-00085q-Ed for importer@patchew.org; Mon, 02 Jul 2018 12:27:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004Qz-92 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ao-0006bL-Qf for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47580 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 1fa1ao-0006b4-Lo for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:22 -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 4FE487C6A9 for ; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2195C2026D5B; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7AAF51132D72; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:53 +0200 Message-Id: <20180702162218.13678-8-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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]); Mon, 02 Jul 2018 16:22:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:22 +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 07/32] qmp: Make "id" optional again even in "oob" monitors 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: 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" Commit cf869d53172 "qmp: support out-of-band (oob) execution" made "id" mandatory for all commands when the client accepted capability "oob". This is rather onerous when you play with QMP by hand, and unnecessarily so: only out-of-band commands need an ID for reliable matching of response to command. Revert that part of commit cf869d53172 for now. We may still make "id" mandatory for out-of-band commands. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/interop/qmp-spec.txt | 9 +++------ monitor.c | 7 ------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt index e5f8116c54..794c95838f 100644 --- a/docs/interop/qmp-spec.txt +++ b/docs/interop/qmp-spec.txt @@ -103,16 +103,13 @@ The format for command execution is: required. Each command documents what contents will be considered valid when handling the json-argument - The "id" member is a transaction identification associated with the - command execution. It is required for all commands if the OOB - - capability was enabled at startup, and optional otherwise. The same - "id" field will be part of the response if provided. The "id" - member can be any json-value. A json-number incremented for each - successive command works fine. + command execution, it is optional and will be part of the response + if provided. The "id" member can be any json-value. A json-number + incremented for each successive command works fine. - The optional "control" member further specifies how the command is to be executed. Currently, its only member is optional "run-oob". See section "2.3.1 Out-of-band execution" for details. =20 - 2.3.1 Out-of-band execution --------------------------- =20 diff --git a/monitor.c b/monitor.c index 96e87d8664..b7d74b01b4 100644 --- a/monitor.c +++ b/monitor.c @@ -4291,13 +4291,6 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) =20 id =3D qdict_get(qdict, "id"); =20 - /* When OOB is enabled, the "id" field is mandatory. */ - if (qmp_oob_enabled(mon) && !id) { - error_setg(&err, "Out-of-band capability requires that " - "every command contains an 'id' field"); - goto err; - } - req_obj =3D g_new0(QMPRequest, 1); req_obj->mon =3D mon; req_obj->id =3D qobject_ref(id); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549032946911.2322061230742; Mon, 2 Jul 2018 09:30:32 -0700 (PDT) Received: from localhost ([::1]:34130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1iZ-0001xC-4q for importer@patchew.org; Mon, 02 Jul 2018 12:30:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004Qy-7r for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ao-0006bG-Px for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40448 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 1fa1ao-0006b3-Lx for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:22 -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 4E83D805A530 for ; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23AF42026D6B; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7E27D1132D73; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:54 +0200 Message-Id: <20180702162218.13678-9-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.8]); Mon, 02 Jul 2018 16:22:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 16:22:22 +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 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id" 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: 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qga.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test-qga.c b/tests/test-qga.c index 30c9643257..4edd35535d 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -227,6 +227,22 @@ static void test_qga_ping(gconstpointer fix) qobject_unref(ret); } =20 +static void test_qga_invalid_id(gconstpointer fix) +{ + /* FIXME "id" is ignored; it should be rejected */ + const TestFixture *fixture =3D fix; + QDict *ret, *val; + + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + + val =3D qdict_get_qdict(ret, "return"); + g_assert(!qdict_haskey(val, "id")); + + qobject_unref(ret); +} + static void test_qga_invalid_args(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -934,6 +950,7 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops); g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write= _read); g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); + g_test_add_data_func("/qga/invalid-id", &fix, test_qga_invalid_id); g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args); g_test_add_data_func("/qga/fsfreeze-status", &fix, --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530548680175388.1562798934117; Mon, 2 Jul 2018 09:24:40 -0700 (PDT) Received: from localhost ([::1]:34099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1d0-0005h6-Sl for importer@patchew.org; Mon, 02 Jul 2018 12:24:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004R0-E8 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ap-0006bZ-2j for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47582 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 1fa1ao-0006bB-T7 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:23 -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 8ACD17CBBA for ; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EC942166B5D; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 818EC1132D75; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:55 +0200 Message-Id: <20180702162218.13678-10-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.2]); Mon, 02 Jul 2018 16:22:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:22 +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 09/32] qmp qemu-ga: Revert change that accidentally made qemu-ga accept "id" 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: 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" Commit cf869d53172 "qmp: support out-of-band (oob) execution" changed how we check "id": Note that in the patch I exported qmp_dispatch_check_obj() to be used to check the request earlier, and at the same time allowed "id" field to be there since actually we always allow that. The part after "and" is ill-advised: it makes qemu-ga accept and ignore "id". Revert. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 14 ++++++++------ qapi/qmp-dispatch.c | 2 -- tests/test-qga.c | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/monitor.c b/monitor.c index b7d74b01b4..4659399b55 100644 --- a/monitor.c +++ b/monitor.c @@ -4263,7 +4263,7 @@ static void monitor_qmp_bh_dispatcher(void *data) static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) { QObject *req, *id =3D NULL; - QDict *qdict =3D NULL; + QDict *qdict; MonitorQMP *mon_qmp =3D container_of(parser, MonitorQMP, parser); Monitor *mon =3D container_of(mon_qmp, Monitor, qmp); Error *err =3D NULL; @@ -4278,6 +4278,12 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) goto err; } =20 + qdict =3D qobject_to(QDict, req); + if (qdict) { + id =3D qobject_ref(qdict_get(qdict, "id")); + qdict_del(qdict, "id"); + } /* else will fail qmp_dispatch() */ + /* Check against the request in general layout */ qdict =3D qmp_dispatch_check_obj(req, &err); if (!qdict) { @@ -4289,16 +4295,12 @@ static void handle_qmp_command(JSONMessageParser *p= arser, GQueue *tokens) goto err; } =20 - id =3D qdict_get(qdict, "id"); - req_obj =3D g_new0(QMPRequest, 1); req_obj->mon =3D mon; - req_obj->id =3D qobject_ref(id); + req_obj->id =3D id; req_obj->req =3D req; req_obj->need_resume =3D false; =20 - qdict_del(qdict, "id"); - 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) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 935f9e159c..3d5d5e110f 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -52,8 +52,6 @@ QDict *qmp_dispatch_check_obj(const QObject *request, Err= or **errp) "QMP input member 'arguments' must be an object= "); return NULL; } - } else if (!strcmp(arg_name, "id")) { - continue; } else if (!strcmp(arg_name, "control")) { if (qobject_type(arg_obj) !=3D QTYPE_QDICT) { error_setg(errp, diff --git a/tests/test-qga.c b/tests/test-qga.c index 4edd35535d..564a4594b5 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -229,16 +229,16 @@ static void test_qga_ping(gconstpointer fix) =20 static void test_qga_invalid_id(gconstpointer fix) { - /* FIXME "id" is ignored; it should be rejected */ const TestFixture *fixture =3D fix; - QDict *ret, *val; + QDict *ret, *error; + const char *class; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); g_assert_nonnull(ret); - qmp_assert_no_error(ret); =20 - val =3D qdict_get_qdict(ret, "return"); - g_assert(!qdict_haskey(val, "id")); + error =3D qdict_get_qdict(ret, "error"); + class =3D qdict_get_try_str(error, "class"); + g_assert_cmpstr(class, =3D=3D, "GenericError"); =20 qobject_unref(ret); } --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153054868016968.95284447291226; Mon, 2 Jul 2018 09:24:40 -0700 (PDT) Received: from localhost ([::1]:34098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1cz-0005ga-9s for importer@patchew.org; Mon, 02 Jul 2018 12:24:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aq-0004Qx-6H for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ao-0006bT-UX for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54928 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 1fa1ao-0006b9-PW for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:22 -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 6D0B440250FF for ; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F5652156880; Mon, 2 Jul 2018 16:22:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8502D1132D83; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:56 +0200 Message-Id: <20180702162218.13678-11-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:22 +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 10/32] tests/test-qga: Demonstrate the guest-agent ignores "control" 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: 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qga.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test-qga.c b/tests/test-qga.c index 564a4594b5..2e9e0f73bb 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -243,6 +243,22 @@ static void test_qga_invalid_id(gconstpointer fix) qobject_unref(ret); } =20 +static void test_qga_invalid_oob(gconstpointer fix) +{ + /* FIXME "control" is ignored; it should be rejected */ + const TestFixture *fixture =3D fix; + QDict *ret; + + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping'," + " 'control': {'run-oob': true}}"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + + qdict_get_qdict(ret, "return"); + + qobject_unref(ret); +} + static void test_qga_invalid_args(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -951,6 +967,7 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write= _read); g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); g_test_add_data_func("/qga/invalid-id", &fix, test_qga_invalid_id); + g_test_add_data_func("/qga/invalid-oob", &fix, test_qga_invalid_oob); g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args); g_test_add_data_func("/qga/fsfreeze-status", &fix, --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549530479937.6536564240644; Mon, 2 Jul 2018 09:38:50 -0700 (PDT) Received: from localhost ([::1]:34175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1qf-00082G-Up for importer@patchew.org; Mon, 02 Jul 2018 12:38:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1av-0004Ti-9N for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1aq-0006e2-Sf for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54934 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 1fa1aq-0006cV-G9 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -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 0402D40250FF for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B3682026D5B; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 887921132D3B; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:57 +0200 Message-Id: <20180702162218.13678-12-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:24 +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 11/32] qmp qemu-ga: Fix qemu-ga not to accept "control" 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: 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" Commit cf869d53172 "qmp: support out-of-band (oob) execution" accidentally made qemu-ga accept and ignore "control". Fix that. Out-of-band execution in a monitor that doesn't support it now fails with {"error": {"class": "GenericError", "desc": "QMP input member 'control'= is unexpected"}} instead of {"error": {"class": "GenericError", "desc": "Please enable out-of-band = first for the session during capabilities negotiation"}} The old description is suboptimal when out-of-band cannot not be enabled, or the command doesn't support out-of-band execution. The new description is a bit unspecific, but it'll do. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qmp/dispatch.h | 6 ++++-- monitor.c | 9 ++------- qapi/qmp-dispatch.c | 14 ++++++++------ qga/main.c | 2 +- tests/test-qga.c | 9 +++++---- tests/test-qmp-cmds.c | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index b366bb48bd..303a15ba84 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -41,7 +41,6 @@ void qmp_register_command(QmpCommandList *cmds, const cha= r *name, QmpCommandFunc *fn, QmpCommandOptions options); void qmp_unregister_command(QmpCommandList *cmds, const char *name); QmpCommand *qmp_find_command(QmpCommandList *cmds, const char *name); -QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request); void qmp_disable_command(QmpCommandList *cmds, const char *name); void qmp_enable_command(QmpCommandList *cmds, const char *name); =20 @@ -49,7 +48,10 @@ bool qmp_command_is_enabled(const QmpCommand *cmd); const char *qmp_command_name(const QmpCommand *cmd); bool qmp_has_success_response(const QmpCommand *cmd); QObject *qmp_build_error_object(Error *err); -QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp); +QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob, + Error **errp); +QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request, + bool allow_oob); bool qmp_is_oob(QDict *dict); =20 typedef void (*qmp_cmd_callback_fn)(QmpCommand *cmd, void *opaque); diff --git a/monitor.c b/monitor.c index 4659399b55..2c28b05ecb 100644 --- a/monitor.c +++ b/monitor.c @@ -1318,11 +1318,6 @@ static bool qmp_cmd_oob_check(Monitor *mon, QDict *r= eq, Error **errp) } =20 if (qmp_is_oob(req)) { - if (!qmp_oob_enabled(mon)) { - error_setg(errp, "Please enable out-of-band first " - "for the session during capabilities negotiation"); - return false; - } if (!(cmd->options & QCO_ALLOW_OOB)) { error_setg(errp, "The command %s does not support OOB", command); @@ -4194,7 +4189,7 @@ static void monitor_qmp_dispatch_one(QMPRequest *req_= obj) old_mon =3D cur_mon; cur_mon =3D mon; =20 - rsp =3D qmp_dispatch(mon->qmp.commands, req); + rsp =3D qmp_dispatch(mon->qmp.commands, req, qmp_oob_enabled(mon)); =20 cur_mon =3D old_mon; =20 @@ -4285,7 +4280,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) } /* else will fail qmp_dispatch() */ =20 /* Check against the request in general layout */ - qdict =3D qmp_dispatch_check_obj(req, &err); + qdict =3D qmp_dispatch_check_obj(req, qmp_oob_enabled(mon), &err); if (!qdict) { goto err; } diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 3d5d5e110f..0ad0fab8ed 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -20,7 +20,8 @@ #include "qapi/qmp/qbool.h" #include "sysemu/sysemu.h" =20 -QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) +QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob, + Error **errp) { const QDictEntry *ent; const char *arg_name; @@ -52,7 +53,7 @@ QDict *qmp_dispatch_check_obj(const QObject *request, Err= or **errp) "QMP input member 'arguments' must be an object= "); return NULL; } - } else if (!strcmp(arg_name, "control")) { + } else if (!strcmp(arg_name, "control") && allow_oob) { if (qobject_type(arg_obj) !=3D QTYPE_QDICT) { error_setg(errp, "QMP input member 'control' must be a dict"); @@ -74,7 +75,7 @@ QDict *qmp_dispatch_check_obj(const QObject *request, Err= or **errp) } =20 static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request, - Error **errp) + bool allow_oob, Error **errp) { Error *local_err =3D NULL; const char *command; @@ -82,7 +83,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QOb= ject *request, QmpCommand *cmd; QObject *ret =3D NULL; =20 - dict =3D qmp_dispatch_check_obj(request, errp); + dict =3D qmp_dispatch_check_obj(request, allow_oob, errp); if (!dict) { return NULL; } @@ -157,13 +158,14 @@ bool qmp_is_oob(QDict *dict) return qbool_get_bool(bool_obj); } =20 -QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request) +QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request, + bool allow_oob) { Error *err =3D NULL; QObject *ret; QDict *rsp; =20 - ret =3D do_qmp_dispatch(cmds, request, &err); + ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); =20 rsp =3D qdict_new(); if (err) { diff --git a/qga/main.c b/qga/main.c index ea7540edcc..d332bacce5 100644 --- a/qga/main.c +++ b/qga/main.c @@ -586,7 +586,7 @@ static void process_command(GAState *s, QDict *req) =20 g_assert(req); g_debug("processing command"); - rsp =3D qmp_dispatch(&ga_commands, QOBJECT(req)); + rsp =3D qmp_dispatch(&ga_commands, QOBJECT(req), false); if (rsp) { ret =3D send_response(s, rsp); if (ret < 0) { diff --git a/tests/test-qga.c b/tests/test-qga.c index 2e9e0f73bb..febabc7ad5 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -245,16 +245,17 @@ static void test_qga_invalid_id(gconstpointer fix) =20 static void test_qga_invalid_oob(gconstpointer fix) { - /* FIXME "control" is ignored; it should be rejected */ const TestFixture *fixture =3D fix; - QDict *ret; + QDict *ret, *error; + const char *class; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping'," " 'control': {'run-oob': true}}"); g_assert_nonnull(ret); - qmp_assert_no_error(ret); =20 - qdict_get_qdict(ret, "return"); + error =3D qdict_get_qdict(ret, "error"); + class =3D qdict_get_try_str(error, "class"); + g_assert_cmpstr(class, =3D=3D, "GenericError"); =20 qobject_unref(ret); } diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 491b0c4a44..10c7ba40c1 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -102,7 +102,7 @@ static void test_dispatch_cmd(void) =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp !=3D NULL); assert(!qdict_haskey(qobject_to(QDict, resp), "error")); =20 @@ -119,7 +119,7 @@ static void test_dispatch_cmd_failure(void) =20 qdict_put_str(req, "execute", "user_def_cmd2"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp !=3D NULL); assert(qdict_haskey(qobject_to(QDict, resp), "error")); =20 @@ -133,7 +133,7 @@ static void test_dispatch_cmd_failure(void) =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 - resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp !=3D NULL); assert(qdict_haskey(qobject_to(QDict, resp), "error")); =20 @@ -147,7 +147,7 @@ static QObject *test_qmp_dispatch(QDict *req) QDict *resp; QObject *ret; =20 - resp_obj =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); + resp_obj =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp_obj); resp =3D qobject_to(QDict, resp_obj); assert(resp && !qdict_haskey(resp, "error")); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530550152637492.85745463068304; Mon, 2 Jul 2018 09:49:12 -0700 (PDT) Received: from localhost ([::1]:34228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa20l-0007ge-Qe for importer@patchew.org; Mon, 02 Jul 2018 12:49:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004Sz-Ld for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1aq-0006e7-Sd for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40450 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 1fa1aq-0006cT-GB for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -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 F3657805A530 for ; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B4CD2026D6B; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8BFA51132D3C; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:58 +0200 Message-Id: <20180702162218.13678-13-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.8]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 16:22:24 +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 12/32] qmp: Redo how the client requests out-of-band execution 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: 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" Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a general mechanism for command-independent arguments just for an out-of-band flag: The "control" key is introduced to store this extra flag. "control" field is used to store arguments that are shared by all the commands, rather than command specific arguments. Let "run-oob" be the first. However, it failed to reject unknown members of "control". For instance, in QMP command {"execute": "query-name", "id": 42, "control": {"crap": true}} "crap" gets silently ignored. Instead of fixing this, revert the general "control" mechanism (because YAGNI), and do it the way I initially proposed, with key "exec-oob". Simpler code, simper interface. An out-of-band command {"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}} becomes {"exec-oob": "migrate-pause", "id": 42} Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 10 +++---- docs/interop/qmp-spec.txt | 18 ++++++------- monitor.c | 3 +++ qapi/qmp-dispatch.c | 51 +++++++++++++++--------------------- tests/qmp-test.c | 7 ++--- tests/test-qga.c | 3 +-- 6 files changed, 39 insertions(+), 53 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 9625798d16..f020f6bab2 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -649,13 +649,11 @@ example: { 'command': 'migrate_recover', 'data': { 'uri': 'str' }, 'allow-oob': true } =20 -To execute a command with out-of-band priority, the client specifies -the "control" field in the request, with "run-oob" set to -true. Example: +To execute a command with out-of-band priority, the client uses key +"exec-oob" instead of "execute". Example: =20 - =3D> { "execute": "command-support-oob", - "arguments": { ... }, - "control": { "run-oob": true } } + =3D> { "exec-oob": "migrate-recover", + "arguments": { "uri": "tcp:192.168.1.200:12345" } } <=3D { "return": { } } =20 Without it, even the commands that support out-of-band execution will diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt index 794c95838f..113c9dcf51 100644 --- a/docs/interop/qmp-spec.txt +++ b/docs/interop/qmp-spec.txt @@ -92,12 +92,16 @@ Currently supported capabilities are: =20 The format for command execution is: =20 -{ "execute": json-string, "arguments": json-object, "id": json-value, - "control": json-object } +{ "execute": json-string, "arguments": json-object, "id": json-value } + +or + +{ "exec-oob": json-string, "arguments": json-object, "id": json-value } =20 Where, =20 -- The "execute" member identifies the command to be executed by the Server +- The "execute" or "exec-oob" member identifies the command to be + executed by the server. The latter requests out-of-band execution. - The "arguments" member is used to pass any arguments required for the execution of the command, it is optional when no arguments are required. Each command documents what contents will be considered @@ -106,9 +110,6 @@ The format for command execution is: command execution, it is optional and will be part of the response if provided. The "id" member can be any json-value. A json-number incremented for each successive command works fine. -- The optional "control" member further specifies how the command is - to be executed. Currently, its only member is optional "run-oob". - See section "2.3.1 Out-of-band execution" for details. =20 2.3.1 Out-of-band execution --------------------------- @@ -125,9 +126,6 @@ possibly overtaking prior in-band commands. The client= may therefore receive such a command's response before responses from prior in-band commands. =20 -To execute a command out-of-band, the client puts "run-oob": true into -execute's member "control". - If the client sends in-band commands faster than the server can execute them, the server will eventually drop commands to limit the queue length. The sever sends event COMMAND_DROPPED then. @@ -270,7 +268,7 @@ S: { "timestamp": { "seconds": 1258551470, "microsecond= s": 802384 }, 3.7 Out-of-band execution ------------------------- =20 -C: { "execute": "migrate-pause", "id": 42, "control": { "run-oob": true } } +C: { "exec-oob": "migrate-pause", "id": 42 } S: { "id": 42, "error": { "class": "GenericError", "desc": "migrate-pause is currently only supported during postcopy-a= ctive state" } } diff --git a/monitor.c b/monitor.c index 2c28b05ecb..8b0c29ce06 100644 --- a/monitor.c +++ b/monitor.c @@ -1299,6 +1299,9 @@ static bool qmp_cmd_oob_check(Monitor *mon, QDict *re= q, Error **errp) QmpCommand *cmd; =20 command =3D qdict_get_try_str(req, "execute"); + if (!command) { + command =3D qdict_get_try_str(req, "exec-oob"); + } if (!command) { error_setg(errp, "Command field 'execute' missing"); return false; diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 0ad0fab8ed..12be120fe7 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -23,11 +23,11 @@ QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob, Error **errp) { + const char *exec_key =3D NULL; const QDictEntry *ent; const char *arg_name; const QObject *arg_obj; - bool has_exec_key =3D false; - QDict *dict =3D NULL; + QDict *dict; =20 dict =3D qobject_to(QDict, request); if (!dict) { @@ -40,25 +40,25 @@ QDict *qmp_dispatch_check_obj(const QObject *request, b= ool allow_oob, arg_name =3D qdict_entry_key(ent); arg_obj =3D qdict_entry_value(ent); =20 - if (!strcmp(arg_name, "execute")) { + if (!strcmp(arg_name, "execute") + || (!strcmp(arg_name, "exec-oob") && allow_oob)) { if (qobject_type(arg_obj) !=3D QTYPE_QSTRING) { - error_setg(errp, - "QMP input member 'execute' must be a string"); + error_setg(errp, "QMP input member '%s' must be a string", + arg_name); return NULL; } - has_exec_key =3D true; + if (exec_key) { + error_setg(errp, "QMP input member '%s' clashes with '%s'", + arg_name, exec_key); + return NULL; + } + exec_key =3D arg_name; } else if (!strcmp(arg_name, "arguments")) { if (qobject_type(arg_obj) !=3D QTYPE_QDICT) { error_setg(errp, "QMP input member 'arguments' must be an object= "); return NULL; } - } else if (!strcmp(arg_name, "control") && allow_oob) { - if (qobject_type(arg_obj) !=3D QTYPE_QDICT) { - error_setg(errp, - "QMP input member 'control' must be a dict"); - return NULL; - } } else { error_setg(errp, "QMP input member '%s' is unexpected", arg_name); @@ -66,7 +66,7 @@ QDict *qmp_dispatch_check_obj(const QObject *request, boo= l allow_oob, } } =20 - if (!has_exec_key) { + if (!exec_key) { error_setg(errp, "QMP input lacks member 'execute'"); return NULL; } @@ -88,7 +88,11 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QO= bject *request, return NULL; } =20 - command =3D qdict_get_str(dict, "execute"); + command =3D qdict_get_try_str(dict, "execute"); + if (!command) { + assert(allow_oob); + command =3D qdict_get_str(dict, "exec-oob"); + } cmd =3D qmp_find_command(cmds, command); if (cmd =3D=3D NULL) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, @@ -137,25 +141,12 @@ QObject *qmp_build_error_object(Error *err) } =20 /* - * Detect whether a request should be run out-of-band, by quickly - * peeking at whether we have: { "control": { "run-oob": true } }. By - * default commands are run in-band. + * Does @qdict look like a command to be run out-of-band? */ bool qmp_is_oob(QDict *dict) { - QBool *bool_obj; - - dict =3D qdict_get_qdict(dict, "control"); - if (!dict) { - return false; - } - - bool_obj =3D qobject_to(QBool, qdict_get(dict, "run-oob")); - if (!bool_obj) { - return false; - } - - return qbool_get_bool(bool_obj); + return qdict_haskey(dict, "exec-oob") + && !qdict_haskey(dict, "execute"); } =20 QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request, diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 3932901146..dc30930201 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -174,8 +174,7 @@ static void unblock_blocked_cmd(void) =20 static void send_oob_cmd(QTestState *s, const char *id) { - qtest_async_qmp(s, "{ 'execute': 'migrate-pause', 'id': %s," - " 'control': { 'run-oob': true } }", id); + qtest_async_qmp(s, "{ 'exec-oob': 'migrate-pause', 'id': %s }", id); } =20 static void recv_cmd_id(QTestState *s, const char *id) @@ -227,9 +226,7 @@ static void test_qmp_oob(void) * Try any command that does not support OOB but with OOB flag. We * should get failure. */ - resp =3D qtest_qmp(qts, - "{ 'execute': 'query-cpus'," - " 'control': { 'run-oob': true } }"); + resp =3D qtest_qmp(qts, "{ 'exec-oob': 'query-cpus' }"); g_assert(qdict_haskey(resp, "error")); qobject_unref(resp); =20 diff --git a/tests/test-qga.c b/tests/test-qga.c index febabc7ad5..daadf22ea3 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -249,8 +249,7 @@ static void test_qga_invalid_oob(gconstpointer fix) QDict *ret, *error; const char *class; =20 - ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping'," - " 'control': {'run-oob': true}}"); + ret =3D qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}"); g_assert_nonnull(ret); =20 error =3D qdict_get_qdict(ret, "error"); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530548859576807.3805176721934; Mon, 2 Jul 2018 09:27:39 -0700 (PDT) Received: from localhost ([::1]:34119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1fu-00089h-Pz for importer@patchew.org; Mon, 02 Jul 2018 12:27:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1as-0004RF-I4 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1aq-0006dg-N3 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40452 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 1fa1aq-0006cg-Fq for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 154D281A4EA3 for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E5DC111AF36; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8F56A1132D3D; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:21:59 +0200 Message-Id: <20180702162218.13678-14-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 13/32] qmp: Revert change to handle_qmp_command tracepoint 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: 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" Commit 71da4667db6 "monitor: separate QMP parser and dispatcher" moved the handle_qmp_command tracepoint from handle_qmp_command() to monitor_qmp_dispatch_one(). This delays tracing from enqueue time to dequeue time. Revert that. Dequeue remains adequately visible via tracepoint monitor_qmp_cmd_in_band. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index 8b0c29ce06..10991757f6 100644 --- a/monitor.c +++ b/monitor.c @@ -4183,12 +4183,6 @@ static void monitor_qmp_dispatch_one(QMPRequest *req= _obj) =20 g_free(req_obj); =20 - if (trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { - QString *req_json =3D qobject_to_json(req); - trace_handle_qmp_command(mon, qstring_get_str(req_json)); - qobject_unref(req_json); - } - old_mon =3D cur_mon; cur_mon =3D mon; =20 @@ -4282,6 +4276,12 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) qdict_del(qdict, "id"); } /* else will fail qmp_dispatch() */ =20 + if (trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { + QString *req_json =3D qobject_to_json(req); + trace_handle_qmp_command(mon, qstring_get_str(req_json)); + qobject_unref(req_json); + } + /* Check against the request in general layout */ qdict =3D qmp_dispatch_check_obj(req, qmp_oob_enabled(mon), &err); if (!qdict) { --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530548691248331.43436614019606; Mon, 2 Jul 2018 09:24:51 -0700 (PDT) Received: from localhost ([::1]:34101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1d5-0005ka-26 for importer@patchew.org; Mon, 02 Jul 2018 12:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ar-0004R2-CN for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ap-0006cL-Ug for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54932 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 1fa1ap-0006bx-Pr for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:23 -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 6F7EE407048A for ; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40AD32166B5D; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9439B1132D3E; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:00 +0200 Message-Id: <20180702162218.13678-15-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:23 +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 14/32] qmp: Always free QMPRequest with qmp_request_free() 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: 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_qmp_dispatch_one() frees a QMPRequest manually, because it needs to keep a reference to ->id. Premature optimization. Take an additional reference so we can use qmp_request_free(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 10991757f6..94f5660c3c 100644 --- a/monitor.c +++ b/monitor.c @@ -4181,8 +4181,6 @@ static void monitor_qmp_dispatch_one(QMPRequest *req_= obj) id =3D req_obj->id; need_resume =3D req_obj->need_resume; =20 - g_free(req_obj); - old_mon =3D cur_mon; cur_mon =3D mon; =20 @@ -4191,14 +4189,14 @@ static void monitor_qmp_dispatch_one(QMPRequest *re= q_obj) cur_mon =3D old_mon; =20 /* Respond if necessary */ - monitor_qmp_respond(mon, rsp, NULL, id); + monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id)); =20 /* This pairs with the monitor_suspend() in handle_qmp_command(). */ if (need_resume) { monitor_resume(mon); } =20 - qobject_unref(req); + qmp_request_free(req_obj); } =20 /* --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549226247255.343098018987; Mon, 2 Jul 2018 09:33:46 -0700 (PDT) Received: from localhost ([::1]:34146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ll-0004IE-4V for importer@patchew.org; Mon, 02 Jul 2018 12:33:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1at-0004RR-CK for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006em-3g for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47590 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 1fa1aq-0006dG-O2 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F2057DAC2 for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E2A8111AF37; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 960F81132D3F; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:01 +0200 Message-Id: <20180702162218.13678-16-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 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: 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 From nobody Tue Nov 4 15:26:29 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 153054889528779.48280246515992; Mon, 2 Jul 2018 09:28:15 -0700 (PDT) Received: from localhost ([::1]:34120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1gU-0000BT-GP for importer@patchew.org; Mon, 02 Jul 2018 12:28:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1as-0004RG-KC for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1aq-0006dp-OQ for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54114 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 1fa1aq-0006cW-HT for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05B5D4022909 for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60DD71C5A7; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 996F71132CA9; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:02 +0200 Message-Id: <20180702162218.13678-17-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 16/32] tests/qmp-test: Demonstrate QMP errors jumping the queue 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: 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" When OOB is enabled, out-of-band commands are executed right away, everything else is queued. This lets out-of-band commands "jump the queue". However, certain errors are always reported right away, and therefore can jump the queue even when the erroneous input does not request out-of-band execution. These errors are pretty unlikely to occur in production, but it's wrong all the same. Mark FIXME. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Peter Xu --- monitor.c | 1 + tests/qmp-test.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/monitor.c b/monitor.c index 51ba1485ad..28fa9b8d44 100644 --- a/monitor.c +++ b/monitor.c @@ -4338,6 +4338,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) return; =20 err: + /* FIXME overtakes queued in-band commands, wrong when !qmp_is_oob() */ monitor_qmp_respond(mon, NULL, err, NULL); qobject_unref(req); } diff --git a/tests/qmp-test.c b/tests/qmp-test.c index dc30930201..fe5e5b548a 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -239,6 +239,13 @@ static void test_qmp_oob(void) unblock_blocked_cmd(); recv_cmd_id(qts, "ib-blocks-1"); recv_cmd_id(qts, "ib-quick-1"); + + /* FIXME certain in-band errors overtake slow in-band command */ + send_cmd_that_blocks(qts, "blocks-2"); + qtest_async_qmp(qts, "{ 'id': 'err-2' }"); + recv_cmd_id(qts, NULL); + unblock_blocked_cmd(); + recv_cmd_id(qts, "blocks-2"); cleanup_blocking_cmd(); =20 qtest_quit(qts); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153054995134369.39426041159584; Mon, 2 Jul 2018 09:45:51 -0700 (PDT) Received: from localhost ([::1]:34215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1xT-0005Ji-3I for importer@patchew.org; Mon, 02 Jul 2018 12:45:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004Sr-GV for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1aq-0006eG-VW for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47586 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 1fa1aq-0006cn-JW for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -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 248767CBBA for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 770322166B5D; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9CD941132CAA; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:03 +0200 Message-Id: <20180702162218.13678-18-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.2]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:24 +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 17/32] qmp: Don't let malformed in-band commands jump the queue 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: 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" handle_qmp_command() reports certain errors right away. This is wrong when OOB is enabled, because the errors can "jump the queue" then, as the previous commit demonstrates. To fix, we need to delay errors until dispatch. Do that for semantic errors, mostly by reverting ill-advised parts of commit cf869d53172 "qmp: support out-of-band (oob) execution". Bonus: doesn't run qmp_dispatch_check_obj() twice, once in handle_qmp_command(), and again in do_qmp_dispatch(). That's also due to commit cf869d53172. The next commit will fix queue jumping for syntax errors. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake qmp.commands, command); - if (!cmd) { - if (mon->qmp.commands =3D=3D &qmp_cap_negotiation_commands) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, - "Expecting capabilities negotiation " - "with 'qmp_capabilities'"); - } else { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, - "The command %s has not been found", command); - } - return false; - } - - if (qmp_is_oob(req)) { - if (!(cmd->options & QCO_ALLOW_OOB)) { - error_setg(errp, "The command %s does not support OOB", - command); - return false; - } - } - - return true; -} - void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, Error **errp) { @@ -4170,6 +4128,7 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) { Monitor *old_mon; QObject *rsp; + QDict *error; =20 old_mon =3D cur_mon; cur_mon =3D mon; @@ -4178,6 +4137,19 @@ static void monitor_qmp_dispatch(Monitor *mon, QObje= ct *req, QObject *id) =20 cur_mon =3D old_mon; =20 + if (mon->qmp.commands =3D=3D &qmp_cap_negotiation_commands) { + error =3D qdict_get_qdict(qobject_to(QDict, rsp), "error"); + if (error + && !g_strcmp0(qdict_get_try_str(error, "class"), + QapiErrorClass_str(ERROR_CLASS_COMMAND_NOT_FOUND))) { + /* Provide a more useful error message */ + qdict_del(error, "desc"); + qdict_put_str(error, "desc", "Expecting capabilities negotiati= on" + " with 'qmp_capabilities'"); + } + } + + /* Respond if necessary */ monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id)); } =20 @@ -4255,7 +4227,9 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) error_setg(&err, QERR_JSON_PARSING); } if (err) { - goto err; + assert(!req); + monitor_qmp_respond(mon, NULL, err, NULL); + return; } =20 qdict =3D qobject_to(QDict, req); @@ -4270,18 +4244,7 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) qobject_unref(req_json); } =20 - /* Check against the request in general layout */ - qdict =3D qmp_dispatch_check_obj(req, qmp_oob_enabled(mon), &err); - if (!qdict) { - goto err; - } - - /* Check against OOB specific */ - if (!qmp_cmd_oob_check(mon, qdict, &err)) { - goto err; - } - - if (qmp_is_oob(qdict)) { + if (qdict && 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) ?: ""); @@ -4335,12 +4298,6 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) =20 /* Kick the dispatcher routine */ qemu_bh_schedule(mon_global.qmp_dispatcher_bh); - return; - -err: - /* FIXME overtakes queued in-band commands, wrong when !qmp_is_oob() */ - monitor_qmp_respond(mon, NULL, err, NULL); - qobject_unref(req); } =20 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 12be120fe7..6d78f3e9f6 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -20,8 +20,8 @@ #include "qapi/qmp/qbool.h" #include "sysemu/sysemu.h" =20 -QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob, - Error **errp) +static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oo= b, + Error **errp) { const char *exec_key =3D NULL; const QDictEntry *ent; @@ -78,6 +78,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QOb= ject *request, bool allow_oob, Error **errp) { Error *local_err =3D NULL; + bool oob; const char *command; QDict *args, *dict; QmpCommand *cmd; @@ -89,9 +90,11 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QO= bject *request, } =20 command =3D qdict_get_try_str(dict, "execute"); + oob =3D false; if (!command) { assert(allow_oob); command =3D qdict_get_str(dict, "exec-oob"); + oob =3D true; } cmd =3D qmp_find_command(cmds, command); if (cmd =3D=3D NULL) { @@ -104,6 +107,11 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, command); return NULL; } + if (oob && !(cmd->options & QCO_ALLOW_OOB)) { + error_setg(errp, "The command %s does not support OOB", + command); + return false; + } =20 if (runstate_check(RUN_STATE_PRECONFIG) && !(cmd->options & QCO_ALLOW_PRECONFIG)) { diff --git a/tests/qmp-test.c b/tests/qmp-test.c index fe5e5b548a..3f29c6c305 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -240,12 +240,12 @@ static void test_qmp_oob(void) recv_cmd_id(qts, "ib-blocks-1"); recv_cmd_id(qts, "ib-quick-1"); =20 - /* FIXME certain in-band errors overtake slow in-band command */ + /* Even malformed in-band command fails in-band */ send_cmd_that_blocks(qts, "blocks-2"); qtest_async_qmp(qts, "{ 'id': 'err-2' }"); - recv_cmd_id(qts, NULL); unblock_blocked_cmd(); recv_cmd_id(qts, "blocks-2"); + recv_cmd_id(qts, "err-2"); cleanup_blocking_cmd(); =20 qtest_quit(qts); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153054959962745.431003903896; Mon, 2 Jul 2018 09:39:59 -0700 (PDT) Received: from localhost ([::1]:34177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1rq-0000Xi-Tw for importer@patchew.org; Mon, 02 Jul 2018 12:39:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1at-0004RS-Dr for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006eV-1U for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54936 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 1fa1aq-0006cq-M4 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 287B1407048A for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F30C9178B7; Mon, 2 Jul 2018 16:22:23 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A06FA1132CAF; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:04 +0200 Message-Id: <20180702162218.13678-19-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 18/32] qmp: Don't let JSON errors jump the queue 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: 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" handle_qmp_command() reports JSON syntax errors right away. This is wrong when OOB is enabled, because the errors can "jump the queue" then. The previous commit fixed the same bug for semantic errors, by delaying the checking until dispatch. We can't delay the checking, so delay the reporting. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/monitor.c b/monitor.c index 7a80e58bf2..fd83a57dda 100644 --- a/monitor.c +++ b/monitor.c @@ -253,8 +253,12 @@ struct QMPRequest { Monitor *mon; /* "id" field of the request */ QObject *id; - /* Request object to be handled */ + /* + * Request object to be handled or Error to be reported + * (exactly one of them is non-null) + */ QObject *req; + Error *err; /* * Whether we need to resume the monitor afterward. This flag is * used to emulate the old QMP server behavior that the current @@ -359,6 +363,7 @@ static void qmp_request_free(QMPRequest *req) { qobject_unref(req->id); qobject_unref(req->req); + error_free(req->err); g_free(req); } =20 @@ -4198,8 +4203,14 @@ static void monitor_qmp_bh_dispatcher(void *data) return; } =20 - 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->req) { + 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); + } else { + assert(req_obj->err); + monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL); + } + if (req_obj->need_resume) { /* Pairs with the monitor_suspend() in handle_qmp_command() */ monitor_resume(req_obj->mon); @@ -4226,11 +4237,6 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) /* json_parser_parse_err() sucks: can fail without setting @err */ error_setg(&err, QERR_JSON_PARSING); } - if (err) { - assert(!req); - monitor_qmp_respond(mon, NULL, err, NULL); - return; - } =20 qdict =3D qobject_to(QDict, req); if (qdict) { @@ -4256,6 +4262,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) req_obj->mon =3D mon; req_obj->id =3D id; req_obj->req =3D req; + req_obj->err =3D err; req_obj->need_resume =3D false; =20 /* Protect qmp_requests and fetching its length. */ --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153054923537441.37678931626658; Mon, 2 Jul 2018 09:33:55 -0700 (PDT) Received: from localhost ([::1]:34148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1lt-0004Mo-FM for importer@patchew.org; Mon, 02 Jul 2018 12:33:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004SR-BI for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006fJ-JB for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54938 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 1fa1ar-0006e0-61 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 B799C40250FF for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 718442026D5B; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AA2471132CB0; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:05 +0200 Message-Id: <20180702162218.13678-20-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:24 +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 19/32] monitor: Rename use_io_thr to use_io_thread 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: 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/monitor.c b/monitor.c index fd83a57dda..10b6634d3e 100644 --- a/monitor.c +++ b/monitor.c @@ -206,11 +206,11 @@ struct Monitor { int flags; int suspend_cnt; /* Needs to be accessed atomically */ bool skip_flush; - bool use_io_thr; + bool use_io_thread; =20 /* * State used only in the thread "owning" the monitor. - * If @use_io_thr, this is mon_global.mon_iothread. + * If @use_io_thread, this is mon_global.mon_iothread. * Else, it's the main thread. * These members can be safely accessed without locks. */ @@ -520,7 +520,7 @@ static void monitor_json_emitter_raw(Monitor *mon, =20 static void monitor_json_emitter(Monitor *mon, QObject *data) { - if (mon->use_io_thr) { + if (mon->use_io_thread) { /* * If using I/O thread, we need to queue the item so that I/O * thread will do the rest for us. Take refcount so that @@ -766,7 +766,7 @@ static void monitor_qapi_event_init(void) static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 static void monitor_data_init(Monitor *mon, bool skip_flush, - bool use_io_thr) + bool use_io_thread) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->mon_lock); @@ -775,7 +775,7 @@ static void monitor_data_init(Monitor *mon, bool skip_f= lush, /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; mon->skip_flush =3D skip_flush; - mon->use_io_thr =3D use_io_thr; + mon->use_io_thread =3D use_io_thread; mon->qmp.qmp_requests =3D g_queue_new(); mon->qmp.qmp_responses =3D g_queue_new(); } @@ -1270,7 +1270,7 @@ static void qmp_caps_check(Monitor *mon, QMPCapabilit= yList *list, assert(list->value < QMP_CAPABILITY__MAX); switch (list->value) { case QMP_CAPABILITY_OOB: - if (!mon->use_io_thr) { + if (!mon->use_io_thread) { /* * Out-of-band only works with monitors that are * running on dedicated I/O thread. @@ -4376,7 +4376,7 @@ void monitor_resume(Monitor *mon) * For QMP monitors that are running in I/O thread, let's * kick the thread in case it's sleeping. */ - if (mon->use_io_thr) { + if (mon->use_io_thread) { aio_notify(iothread_get_aio_context(mon_global.mon_iothrea= d)); } } else { @@ -4396,7 +4396,7 @@ static QObject *get_qmp_greeting(Monitor *mon) qmp_marshal_query_version(NULL, &ver, NULL); =20 for (cap =3D 0; cap < QMP_CAPABILITY__MAX; cap++) { - if (!mon->use_io_thr && cap =3D=3D QMP_CAPABILITY_OOB) { + if (!mon->use_io_thread && cap =3D=3D QMP_CAPABILITY_OOB) { /* Monitors that are not using I/O thread won't support OOB */ continue; } @@ -4609,9 +4609,9 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) Monitor *mon =3D opaque; GMainContext *context; =20 - if (mon->use_io_thr) { + if (mon->use_io_thread) { /* - * When use_io_thr is set, we use the global shared dedicated + * When @use_io_thread is set, we use the global shared dedicated * I/O thread for this monitor to handle input/output. */ context =3D monitor_get_io_context(); @@ -4660,7 +4660,7 @@ void monitor_init(Chardev *chr, int flags) if (monitor_is_qmp(mon)) { qemu_chr_fe_set_echo(&mon->chr, true); json_message_parser_init(&mon->qmp.parser, handle_qmp_command); - if (mon->use_io_thr) { + if (mon->use_io_thread) { /* * Make sure the old iowatch is gone. It's possible when * e.g. the chardev is in client mode, with wait=3Don. --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549601280258.2345263877447; Mon, 2 Jul 2018 09:40:01 -0700 (PDT) Received: from localhost ([::1]:34178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1rs-0000ZH-Fm for importer@patchew.org; Mon, 02 Jul 2018 12:40:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004Su-IK for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006fV-Kw for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47592 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 1fa1ar-0006eA-8W for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 BB5807DAC3 for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7211C2026D6B; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B1BF11132BBE; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:06 +0200 Message-Id: <20180702162218.13678-21-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:24 +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 20/32] monitor: Peel off @mon_global wrapper 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: 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" Wrapping global variables in a struct without a use for the wrapper struct buys us nothing but longer lines. Unwrap them. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/monitor.c b/monitor.c index 10b6634d3e..ef19562f65 100644 --- a/monitor.c +++ b/monitor.c @@ -210,7 +210,7 @@ struct Monitor { =20 /* * State used only in the thread "owning" the monitor. - * If @use_io_thread, this is mon_global.mon_iothread. + * If @use_io_thread, this is @mon_iothread. * Else, it's the main thread. * These members can be safely accessed without locks. */ @@ -239,14 +239,13 @@ struct Monitor { int mux_out; }; =20 -/* Let's add monitor global variables to this struct. */ -static struct { - IOThread *mon_iothread; - /* Bottom half to dispatch the requests received from I/O thread */ - QEMUBH *qmp_dispatcher_bh; - /* Bottom half to deliver the responses back to clients */ - QEMUBH *qmp_respond_bh; -} mon_global; +IOThread *mon_iothread; + +/* Bottom half to dispatch the requests received from I/O thread */ +QEMUBH *qmp_dispatcher_bh; + +/* Bottom half to deliver the responses back to clients */ +QEMUBH *qmp_respond_bh; =20 struct QMPRequest { /* Owner of the request */ @@ -530,7 +529,7 @@ static void monitor_json_emitter(Monitor *mon, QObject = *data) qemu_mutex_lock(&mon->qmp.qmp_queue_lock); g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(data)); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); - qemu_bh_schedule(mon_global.qmp_respond_bh); + qemu_bh_schedule(qmp_respond_bh); } else { /* * If not using monitor I/O thread, then we are in main thread. @@ -4218,7 +4217,7 @@ static void monitor_qmp_bh_dispatcher(void *data) qmp_request_free(req_obj); =20 /* Reschedule instead of looping so the main loop stays responsive */ - qemu_bh_schedule(mon_global.qmp_dispatcher_bh); + qemu_bh_schedule(qmp_dispatcher_bh); } =20 #define QMP_REQ_QUEUE_LEN_MAX (8) @@ -4304,7 +4303,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); =20 /* Kick the dispatcher routine */ - qemu_bh_schedule(mon_global.qmp_dispatcher_bh); + qemu_bh_schedule(qmp_dispatcher_bh); } =20 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) @@ -4357,7 +4356,7 @@ int monitor_suspend(Monitor *mon) * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ - aio_notify(iothread_get_aio_context(mon_global.mon_iothread)); + aio_notify(iothread_get_aio_context(mon_iothread)); } =20 trace_monitor_suspend(mon, 1); @@ -4377,7 +4376,7 @@ void monitor_resume(Monitor *mon) * kick the thread in case it's sleeping. */ if (mon->use_io_thread) { - aio_notify(iothread_get_aio_context(mon_global.mon_iothrea= d)); + aio_notify(iothread_get_aio_context(mon_iothread)); } } else { assert(mon->rs); @@ -4515,36 +4514,35 @@ static void sortcmdlist(void) =20 static GMainContext *monitor_get_io_context(void) { - return iothread_get_g_main_context(mon_global.mon_iothread); + return iothread_get_g_main_context(mon_iothread); } =20 static AioContext *monitor_get_aio_context(void) { - return iothread_get_aio_context(mon_global.mon_iothread); + return iothread_get_aio_context(mon_iothread); } =20 static void monitor_iothread_init(void) { - mon_global.mon_iothread =3D iothread_create("mon_iothread", - &error_abort); + mon_iothread =3D iothread_create("mon_iothread", &error_abort); =20 /* * This MUST be on main loop thread since we have commands that * have assumption to be run on main loop thread. It would be * nice that one day we can remove this assumption in the future. */ - mon_global.qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(= ), - monitor_qmp_bh_dispatcher, - NULL); + qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(), + monitor_qmp_bh_dispatcher, + NULL); =20 /* * Unlike the dispatcher BH, this must be run on the monitor I/O * thread, so that monitors that are using I/O thread will make * sure read/write operations are all done on the I/O thread. */ - mon_global.qmp_respond_bh =3D aio_bh_new(monitor_get_aio_context(), - monitor_qmp_bh_responder, - NULL); + qmp_respond_bh =3D aio_bh_new(monitor_get_aio_context(), + monitor_qmp_bh_responder, + NULL); } =20 void monitor_init_globals(void) @@ -4701,7 +4699,7 @@ void monitor_cleanup(void) * we need to unregister from chardev below in * monitor_data_destroy(), and chardev is not thread-safe yet */ - iothread_stop(mon_global.mon_iothread); + iothread_stop(mon_iothread); =20 /* * After we have I/O thread to send responses, it's possible that @@ -4722,13 +4720,13 @@ void monitor_cleanup(void) qemu_mutex_unlock(&monitor_lock); =20 /* QEMUBHs needs to be deleted before destroying the I/O thread */ - qemu_bh_delete(mon_global.qmp_dispatcher_bh); - mon_global.qmp_dispatcher_bh =3D NULL; - qemu_bh_delete(mon_global.qmp_respond_bh); - mon_global.qmp_respond_bh =3D NULL; + qemu_bh_delete(qmp_dispatcher_bh); + qmp_dispatcher_bh =3D NULL; + qemu_bh_delete(qmp_respond_bh); + qmp_respond_bh =3D NULL; =20 - iothread_destroy(mon_global.mon_iothread); - mon_global.mon_iothread =3D NULL; + iothread_destroy(mon_iothread); + mon_iothread =3D NULL; } =20 QemuOptsList qemu_mon_opts =3D { --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549067144817.7352427706174; Mon, 2 Jul 2018 09:31:07 -0700 (PDT) Received: from localhost ([::1]:34137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1jG-0002Z4-A8 for importer@patchew.org; Mon, 02 Jul 2018 12:31:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004SY-Cg for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006g2-0e for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54118 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 1fa1ar-0006e6-Ic for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 BAE95402316D for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DE2F2166B5D; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B7DF11132BBF; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:07 +0200 Message-Id: <20180702162218.13678-22-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:24 +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 21/32] qobject: New qdict_from_jsonf_nofail() 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: 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" Many uses of qobject_from_jsonf() convert JSON objects. Create new convenience function qdict_from_jsonf_nofail() that includes the conversion to QDict. The next few commits will put it to use. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qmp/qjson.h | 2 ++ qobject/qjson.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index b274ac3a86..43b2ce2f33 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -19,6 +19,8 @@ QObject *qobject_from_jsonf(const char *string, ...) GCC_= FMT_ATTR(1, 2); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); =20 +QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); + QString *qobject_to_json(const QObject *obj); QString *qobject_to_json_pretty(const QObject *obj); =20 diff --git a/qobject/qjson.c b/qobject/qjson.c index 9816a65c7d..0df3120202 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -76,6 +76,24 @@ QObject *qobject_from_jsonf(const char *string, ...) return obj; } =20 +/* + * Parse @string as JSON object with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QDict. It is never null. + */ +QDict *qdict_from_jsonf_nofail(const char *string, ...) +{ + QDict *obj; + va_list ap; + + va_start(ap, string); + obj =3D qobject_to(QDict, qobject_from_jsonv(string, &ap, &error_abort= )); + va_end(ap); + + assert(obj); + return obj; +} + typedef struct ToJsonIterState { int indent; --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549775644129.82929514981868; Mon, 2 Jul 2018 09:42:55 -0700 (PDT) Received: from localhost ([::1]:34195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1uf-0002vN-TJ for importer@patchew.org; Mon, 02 Jul 2018 12:42:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004Sw-JL for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006fi-OX for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54940 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 1fa1ar-0006eZ-CP for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 D8D95407048A for ; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EB1D2156880; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BDEF31132BC0; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:08 +0200 Message-Id: <20180702162218.13678-23-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:24 +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 22/32] qmp: De-duplicate error response building 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: 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" All callers of qmp_build_error_object() duplicate the code to wrap it in a response object. Replace it by qmp_error_response() that captures the duplicated code, including error_free(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qmp/dispatch.h | 2 +- monitor.c | 7 +------ qapi/qmp-dispatch.c | 20 +++++++++++--------- qga/main.c | 8 ++------ 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 514bfc45b0..a53e11c9b1 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -47,7 +47,7 @@ void qmp_enable_command(QmpCommandList *cmds, const char = *name); bool qmp_command_is_enabled(const QmpCommand *cmd); const char *qmp_command_name(const QmpCommand *cmd); bool qmp_has_success_response(const QmpCommand *cmd); -QObject *qmp_build_error_object(Error *err); +QDict *qmp_error_response(Error *err); QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request, bool allow_oob); bool qmp_is_oob(QDict *dict); diff --git a/monitor.c b/monitor.c index ef19562f65..db85cd0a57 100644 --- a/monitor.c +++ b/monitor.c @@ -4106,14 +4106,9 @@ static int monitor_can_read(void *opaque) static void monitor_qmp_respond(Monitor *mon, QObject *rsp, Error *err, QObject *id) { - QDict *qdict =3D NULL; - if (err) { assert(!rsp); - qdict =3D qdict_new(); - qdict_put_obj(qdict, "error", qmp_build_error_object(err)); - error_free(err); - rsp =3D QOBJECT(qdict); + rsp =3D QOBJECT(qmp_error_response(err)); } =20 if (rsp) { diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 6d78f3e9f6..c85748a33f 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -141,11 +141,15 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds,= QObject *request, return ret; } =20 -QObject *qmp_build_error_object(Error *err) +QDict *qmp_error_response(Error *err) { - return qobject_from_jsonf("{ 'class': %s, 'desc': %s }", - QapiErrorClass_str(error_get_class(err)), - error_get_pretty(err)); + QDict *rsp; + + rsp =3D qdict_from_jsonf_nofail("{ 'error': { 'class': %s, 'desc': %s = } }", + QapiErrorClass_str(error_get_class(err)), + error_get_pretty(err)); + error_free(err); + return rsp; } =20 /* @@ -166,15 +170,13 @@ QObject *qmp_dispatch(QmpCommandList *cmds, QObject *= request, =20 ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); =20 - rsp =3D qdict_new(); if (err) { - qdict_put_obj(rsp, "error", qmp_build_error_object(err)); - error_free(err); + rsp =3D qmp_error_response(err); } else if (ret) { + rsp =3D qdict_new(); qdict_put_obj(rsp, "return", ret); } else { - qobject_unref(rsp); - return NULL; + rsp =3D NULL; } =20 return QOBJECT(rsp); diff --git a/qga/main.c b/qga/main.c index d332bacce5..0e30e30248 100644 --- a/qga/main.c +++ b/qga/main.c @@ -610,15 +610,13 @@ static void process_event(JSONMessageParser *parser, = GQueue *tokens) qdict =3D qobject_to(QDict, json_parser_parse_err(tokens, NULL, &err)); if (err || !qdict) { qobject_unref(qdict); - qdict =3D qdict_new(); if (!err) { g_warning("failed to parse event: unknown error"); error_setg(&err, QERR_JSON_PARSING); } else { g_warning("failed to parse event: %s", error_get_pretty(err)); } - qdict_put_obj(qdict, "error", qmp_build_error_object(err)); - error_free(err); + qdict =3D qmp_error_response(err); } =20 /* handle host->guest commands */ @@ -627,11 +625,9 @@ static void process_event(JSONMessageParser *parser, G= Queue *tokens) } else { if (!qdict_haskey(qdict, "error")) { qobject_unref(qdict); - qdict =3D qdict_new(); g_warning("unrecognized payload format"); error_setg(&err, QERR_UNSUPPORTED); - qdict_put_obj(qdict, "error", qmp_build_error_object(err)); - error_free(err); + qdict =3D qmp_error_response(err); } ret =3D send_response(s, QOBJECT(qdict)); if (ret < 0) { --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549614977249.8035917098756; Mon, 2 Jul 2018 09:40:14 -0700 (PDT) Received: from localhost ([::1]:34179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1s2-0000f6-BR for importer@patchew.org; Mon, 02 Jul 2018 12:40:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ax-0004Vp-00 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gX-60 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54942 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 1fa1ar-0006eu-Jk for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1CE76407048F for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C932C1C5A5; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C407B1132BC1; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:09 +0200 Message-Id: <20180702162218.13678-24-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 23/32] qmp: Use QDict * instead of QObject * for response objects 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: 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" By using the more specific type, we get fewer downcasts. The downcasts are safe, but not obviously so, at least not locally. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qmp/dispatch.h | 4 ++-- monitor.c | 31 ++++++++++++++++--------------- qapi/qmp-dispatch.c | 6 +++--- qga/main.c | 8 ++++---- tests/test-qmp-cmds.c | 17 +++++++---------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index a53e11c9b1..4e2e749faf 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -48,8 +48,8 @@ bool qmp_command_is_enabled(const QmpCommand *cmd); const char *qmp_command_name(const QmpCommand *cmd); bool qmp_has_success_response(const QmpCommand *cmd); QDict *qmp_error_response(Error *err); -QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request, - bool allow_oob); +QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, + bool allow_oob); bool qmp_is_oob(QDict *dict); =20 typedef void (*qmp_cmd_callback_fn)(QmpCommand *cmd, void *opaque); diff --git a/monitor.c b/monitor.c index db85cd0a57..0f7a96213f 100644 --- a/monitor.c +++ b/monitor.c @@ -378,7 +378,7 @@ static void monitor_qmp_cleanup_req_queue_locked(Monito= r *mon) static void monitor_qmp_cleanup_resp_queue_locked(Monitor *mon) { while (!g_queue_is_empty(mon->qmp.qmp_responses)) { - qobject_unref((QObject *)g_queue_pop_head(mon->qmp.qmp_responses)); + qobject_unref((QDict *)g_queue_pop_head(mon->qmp.qmp_responses)); } } =20 @@ -527,7 +527,8 @@ 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(data)); + g_queue_push_tail(mon->qmp.qmp_responses, + qobject_ref(qobject_to(QDict, data))); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); qemu_bh_schedule(qmp_respond_bh); } else { @@ -541,13 +542,13 @@ static void monitor_json_emitter(Monitor *mon, QObjec= t *data) =20 struct QMPResponse { Monitor *mon; - QObject *data; + QDict *data; }; typedef struct QMPResponse QMPResponse; =20 -static QObject *monitor_qmp_response_pop_one(Monitor *mon) +static QDict *monitor_qmp_response_pop_one(Monitor *mon) { - QObject *data; + QDict *data; =20 qemu_mutex_lock(&mon->qmp.qmp_queue_lock); data =3D g_queue_pop_head(mon->qmp.qmp_responses); @@ -558,10 +559,10 @@ static QObject *monitor_qmp_response_pop_one(Monitor = *mon) =20 static void monitor_qmp_response_flush(Monitor *mon) { - QObject *data; + QDict *data; =20 while ((data =3D monitor_qmp_response_pop_one(mon))) { - monitor_json_emitter_raw(mon, data); + monitor_json_emitter_raw(mon, QOBJECT(data)); qobject_unref(data); } } @@ -573,7 +574,7 @@ static void monitor_qmp_response_flush(Monitor *mon) static bool monitor_qmp_response_pop_any(QMPResponse *response) { Monitor *mon; - QObject *data =3D NULL; + QDict *data =3D NULL; =20 qemu_mutex_lock(&monitor_lock); QTAILQ_FOREACH(mon, &mon_list, entry) { @@ -593,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, response.data); + monitor_json_emitter_raw(response.mon, QOBJECT(response.data)); qobject_unref(response.data); } } @@ -4103,20 +4104,20 @@ static int monitor_can_read(void *opaque) * 2. rsp, err, and id may be NULL. * 3. If err !=3D NULL then rsp must be NULL. */ -static void monitor_qmp_respond(Monitor *mon, QObject *rsp, +static void monitor_qmp_respond(Monitor *mon, QDict *rsp, Error *err, QObject *id) { if (err) { assert(!rsp); - rsp =3D QOBJECT(qmp_error_response(err)); + rsp =3D qmp_error_response(err); } =20 if (rsp) { if (id) { - qdict_put_obj(qobject_to(QDict, rsp), "id", qobject_ref(id)); + qdict_put_obj(rsp, "id", qobject_ref(id)); } =20 - monitor_json_emitter(mon, rsp); + monitor_json_emitter(mon, QOBJECT(rsp)); } =20 qobject_unref(id); @@ -4126,7 +4127,7 @@ static void monitor_qmp_respond(Monitor *mon, QObject= *rsp, static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id) { Monitor *old_mon; - QObject *rsp; + QDict *rsp; QDict *error; =20 old_mon =3D cur_mon; @@ -4137,7 +4138,7 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) cur_mon =3D old_mon; =20 if (mon->qmp.commands =3D=3D &qmp_cap_negotiation_commands) { - error =3D qdict_get_qdict(qobject_to(QDict, rsp), "error"); + error =3D qdict_get_qdict(rsp, "error"); if (error && !g_strcmp0(qdict_get_try_str(error, "class"), QapiErrorClass_str(ERROR_CLASS_COMMAND_NOT_FOUND))) { diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index c85748a33f..761812e924 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -161,8 +161,8 @@ bool qmp_is_oob(QDict *dict) && !qdict_haskey(dict, "execute"); } =20 -QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request, - bool allow_oob) +QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, + bool allow_oob) { Error *err =3D NULL; QObject *ret; @@ -179,5 +179,5 @@ QObject *qmp_dispatch(QmpCommandList *cmds, QObject *re= quest, rsp =3D NULL; } =20 - return QOBJECT(rsp); + return rsp; } diff --git a/qga/main.c b/qga/main.c index 0e30e30248..537cc0e162 100644 --- a/qga/main.c +++ b/qga/main.c @@ -545,7 +545,7 @@ fail: #endif } =20 -static int send_response(GAState *s, QObject *payload) +static int send_response(GAState *s, QDict *payload) { const char *buf; QString *payload_qstr, *response_qstr; @@ -553,7 +553,7 @@ static int send_response(GAState *s, QObject *payload) =20 g_assert(payload && s->channel); =20 - payload_qstr =3D qobject_to_json(payload); + payload_qstr =3D qobject_to_json(QOBJECT(payload)); if (!payload_qstr) { return -EINVAL; } @@ -581,7 +581,7 @@ static int send_response(GAState *s, QObject *payload) =20 static void process_command(GAState *s, QDict *req) { - QObject *rsp =3D NULL; + QDict *rsp; int ret; =20 g_assert(req); @@ -629,7 +629,7 @@ static void process_event(JSONMessageParser *parser, GQ= ueue *tokens) error_setg(&err, QERR_UNSUPPORTED); qdict =3D qmp_error_response(err); } - ret =3D send_response(s, QOBJECT(qdict)); + ret =3D send_response(s, qdict); if (ret < 0) { g_warning("error sending error response: %s", strerror(-ret)); } diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 10c7ba40c1..afb338a61e 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -98,13 +98,13 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qem= u_x_EnumList *a, static void test_dispatch_cmd(void) { QDict *req =3D qdict_new(); - QObject *resp; + QDict *resp; =20 qdict_put_str(req, "execute", "user_def_cmd"); =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp !=3D NULL); - assert(!qdict_haskey(qobject_to(QDict, resp), "error")); + assert(!qdict_haskey(resp, "error")); =20 qobject_unref(resp); qobject_unref(req); @@ -115,13 +115,13 @@ static void test_dispatch_cmd_failure(void) { QDict *req =3D qdict_new(); QDict *args =3D qdict_new(); - QObject *resp; + QDict *resp; =20 qdict_put_str(req, "execute", "user_def_cmd2"); =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp !=3D NULL); - assert(qdict_haskey(qobject_to(QDict, resp), "error")); + assert(qdict_haskey(resp, "error")); =20 qobject_unref(resp); qobject_unref(req); @@ -135,7 +135,7 @@ static void test_dispatch_cmd_failure(void) =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp !=3D NULL); - assert(qdict_haskey(qobject_to(QDict, resp), "error")); + assert(qdict_haskey(resp, "error")); =20 qobject_unref(resp); qobject_unref(req); @@ -143,18 +143,15 @@ static void test_dispatch_cmd_failure(void) =20 static QObject *test_qmp_dispatch(QDict *req) { - QObject *resp_obj; QDict *resp; QObject *ret; =20 - resp_obj =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); - assert(resp_obj); - resp =3D qobject_to(QDict, resp_obj); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); assert(resp && !qdict_haskey(resp, "error")); ret =3D qdict_get(resp, "return"); assert(ret); qobject_ref(ret); - qobject_unref(resp_obj); + qobject_unref(resp); return ret; } =20 --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549342750454.41130503730244; Mon, 2 Jul 2018 09:35:42 -0700 (PDT) Received: from localhost ([::1]:34158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1nf-0005dZ-Ld for importer@patchew.org; Mon, 02 Jul 2018 12:35:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1av-0004TQ-0P for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gP-4L for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42850 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 1fa1ar-0006ev-Jz for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20CEB401EF07 for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF0481C5A7; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CA23B1132BC2; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:10 +0200 Message-Id: <20180702162218.13678-25-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 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: 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 From nobody Tue Nov 4 15:26:29 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 1530549423037639.3105658120946; Mon, 2 Jul 2018 09:37:03 -0700 (PDT) Received: from localhost ([::1]:34164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1p0-0006hk-8j for importer@patchew.org; Mon, 02 Jul 2018 12:37:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004SO-9P for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1ar-0006g3-Vy for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47594 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 1fa1ar-0006eq-Ii for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 1638D7DAC2 for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFB672026D6B; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D02A81132BC3; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:11 +0200 Message-Id: <20180702162218.13678-26-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:25 +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 25/32] qmp: Replace get_qmp_greeting() by qmp_greeting() 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: 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" get_qmp_greeting() returns a QDict * as QObject *. It's caller converts it right back. Return QDict * instead. While there, rename to qmp_greeting(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index 399ad6b4e0..ba3124514c 100644 --- a/monitor.c +++ b/monitor.c @@ -4381,7 +4381,7 @@ void monitor_resume(Monitor *mon) trace_monitor_suspend(mon, -1); } =20 -static QObject *get_qmp_greeting(Monitor *mon) +static QDict *qmp_greeting(Monitor *mon) { QList *cap_list =3D qlist_new(); QObject *ver =3D NULL; @@ -4397,8 +4397,9 @@ static QObject *get_qmp_greeting(Monitor *mon) qlist_append_str(cap_list, QMPCapability_str(cap)); } =20 - return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': %p}= }", - ver, cap_list); + return qdict_from_jsonf_nofail( + "{'QMP': {'version': %p, 'capabilities': %p}}", + ver, cap_list); } =20 static void monitor_qmp_caps_reset(Monitor *mon) @@ -4408,15 +4409,15 @@ static void monitor_qmp_caps_reset(Monitor *mon) =20 static void monitor_qmp_event(void *opaque, int event) { - QObject *data; + QDict *data; Monitor *mon =3D opaque; =20 switch (event) { case CHR_EVENT_OPENED: mon->qmp.commands =3D &qmp_cap_negotiation_commands; monitor_qmp_caps_reset(mon); - data =3D get_qmp_greeting(mon); - qmp_queue_response(mon, qobject_to(QDict, data)); + data =3D qmp_greeting(mon); + qmp_queue_response(mon, data); qobject_unref(data); mon_refcount++; break; --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530550147709482.8768694947511; Mon, 2 Jul 2018 09:49:07 -0700 (PDT) Received: from localhost ([::1]:34227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa20h-0007ca-1Z for importer@patchew.org; Mon, 02 Jul 2018 12:49:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1av-0004Te-7k for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gH-2I for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40456 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 1fa1ar-0006et-Ji for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 1DB978011454 for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2BB32156880; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D63471132BC4; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:12 +0200 Message-Id: <20180702162218.13678-27-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.8]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 16:22:25 +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 26/32] qmp: Simplify monitor_qmp_respond() 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: 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_qmp_respond() takes both a response object and an error object. If an error object is non-null, the response object must be null, and the response is built from the error object. Of the two callers, one always passes a null response object, and one a null error object. Move building the response object from the error object to the latter, and drop the error object parameter. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/monitor.c b/monitor.c index ba3124514c..876a3a23a7 100644 --- a/monitor.c +++ b/monitor.c @@ -4099,18 +4099,12 @@ static int monitor_can_read(void *opaque) } =20 /* - * 1. This function takes ownership of rsp, err, and id. - * 2. rsp, err, and id may be NULL. - * 3. If err !=3D NULL then rsp must be NULL. + * Emit QMP response @rsp with ID @id to @mon. + * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP. + * Nothing is emitted then. */ -static void monitor_qmp_respond(Monitor *mon, QDict *rsp, - Error *err, QObject *id) +static void monitor_qmp_respond(Monitor *mon, QDict *rsp, QObject *id) { - if (err) { - assert(!rsp); - rsp =3D qmp_error_response(err); - } - if (rsp) { if (id) { qdict_put_obj(rsp, "id", qobject_ref(id)); @@ -4118,9 +4112,6 @@ static void monitor_qmp_respond(Monitor *mon, QDict *= rsp, =20 qmp_queue_response(mon, rsp); } - - qobject_unref(id); - qobject_unref(rsp); } =20 static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id) @@ -4148,8 +4139,8 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) } } =20 - /* Respond if necessary */ - monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id)); + monitor_qmp_respond(mon, rsp, id); + qobject_unref(rsp); } =20 /* @@ -4192,6 +4183,7 @@ static QMPRequest *monitor_qmp_requests_pop_any(void) static void monitor_qmp_bh_dispatcher(void *data) { QMPRequest *req_obj =3D monitor_qmp_requests_pop_any(); + QDict *rsp; =20 if (!req_obj) { return; @@ -4202,7 +4194,9 @@ static void monitor_qmp_bh_dispatcher(void *data) monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); } else { assert(req_obj->err); - monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL); + rsp =3D qmp_error_response(req_obj->err); + monitor_qmp_respond(req_obj->mon, rsp, NULL); + qobject_unref(rsp); } =20 if (req_obj->need_resume) { --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549036900653.3302847440732; Mon, 2 Jul 2018 09:30:36 -0700 (PDT) Received: from localhost ([::1]:34131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ic-00020z-RM for importer@patchew.org; Mon, 02 Jul 2018 12:30:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1at-0004Rl-S9 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006fq-0k for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47596 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 1fa1ar-0006ew-IX for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -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 2314D7DAC6 for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E48862027058; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DC3B61132927; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:13 +0200 Message-Id: <20180702162218.13678-28-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:25 +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 27/32] qmp: Add some comments around null responses 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: 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/qmp-dispatch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 761812e924..6f2d466596 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -133,6 +133,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, Q= Object *request, } else if (cmd->options & QCO_NO_SUCCESS_RESP) { g_assert(!ret); } else if (!ret) { + /* TODO turn into assertion */ ret =3D QOBJECT(qdict_new()); } =20 @@ -176,6 +177,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, rsp =3D qdict_new(); qdict_put_obj(rsp, "return", ret); } else { + /* Can only happen for commands with QCO_NO_SUCCESS_RESP */ rsp =3D NULL; } =20 --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549426532703.8630181605465; Mon, 2 Jul 2018 09:37:06 -0700 (PDT) Received: from localhost ([::1]:34166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1p3-0006m3-N7 for importer@patchew.org; Mon, 02 Jul 2018 12:37:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1au-0004TJ-SV for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gK-5j for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54120 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 1fa1ar-0006es-Jw for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C58B402315B for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E556C1C5A8; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E247C1132955; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:14 +0200 Message-Id: <20180702162218.13678-29-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 28/32] qmp: Switch timestamp_put() to qdict_from_jsonf_nofail() 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: 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" There's just one use of qobject_from_jsonf() to parse a JSON object left: timestamp_put(). Switch it to qdict_from_jsonf_nofail(). Signed-off-by: Markus Armbruster --- qapi/qmp-event.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c index 9d7e88e84a..5b8854043e 100644 --- a/qapi/qmp-event.c +++ b/qapi/qmp-event.c @@ -34,15 +34,15 @@ QMPEventFuncEmit qmp_event_get_func_emit(void) static void timestamp_put(QDict *qdict) { int err; - QObject *obj; + QDict *ts; qemu_timeval tv; =20 err =3D qemu_gettimeofday(&tv); /* Put -1 to indicate failure of getting host time */ - obj =3D qobject_from_jsonf("{ 'seconds': %lld, 'microseconds': %lld }", - err < 0 ? -1LL : (long long)tv.tv_sec, - err < 0 ? -1LL : (long long)tv.tv_usec); - qdict_put_obj(qdict, "timestamp", obj); + ts =3D qdict_from_jsonf_nofail("{ 'seconds': %lld, 'microseconds': %ll= d }", + err < 0 ? -1LL : (long long)tv.tv_sec, + err < 0 ? -1LL : (long long)tv.tv_usec); + qdict_put(qdict, "timestamp", ts); } =20 /* --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153055033277811.032390878305819; Mon, 2 Jul 2018 09:52:12 -0700 (PDT) Received: from localhost ([::1]:34247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa23g-0001d6-0S for importer@patchew.org; Mon, 02 Jul 2018 12:52:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1av-0004Tp-CI for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gq-Bi for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45544 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 1fa1ar-0006f0-SM for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DD888315E for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6BD71117620; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E8A9711328AB; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:15 +0200 Message-Id: <20180702162218.13678-30-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 29/32] qobject: Let qobject_from_jsonf() fail instead of abort 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: 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" qobject_from_jsonf() aborts on error, unlike qobject_from_jsonv(), which returns null. Since all remaining users of qobject_from_jsonf() cope fine with null, change it to return null. Signed-off-by: Markus Armbruster --- qobject/qjson.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/qobject/qjson.c b/qobject/qjson.c index 0df3120202..2f6a590e44 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -59,10 +59,6 @@ QObject *qobject_from_json(const char *string, Error **e= rrp) return qobject_from_jsonv(string, NULL, errp); } =20 -/* - * IMPORTANT: This function aborts on error, thus it must not - * be used with untrusted arguments. - */ QObject *qobject_from_jsonf(const char *string, ...) { QObject *obj; @@ -72,7 +68,6 @@ QObject *qobject_from_jsonf(const char *string, ...) obj =3D qobject_from_jsonv(string, &ap, &error_abort); va_end(ap); =20 - assert(obj !=3D NULL); return obj; } =20 --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 153054970833919.278668332656252; Mon, 2 Jul 2018 09:41:48 -0700 (PDT) Received: from localhost ([::1]:34194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1tW-0001vz-BL for importer@patchew.org; Mon, 02 Jul 2018 12:41:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aw-0004VO-Oa for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gw-Dn for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54122 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 1fa1ar-0006f7-S7 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 429854023336 for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF9991117622; Mon, 2 Jul 2018 16:22:24 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EEB851132752; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:16 +0200 Message-Id: <20180702162218.13678-31-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 30/32] qmp: Clean up capability negotiation after commit 02130314d8c 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: 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" qmp_greeting() offers capabilities to the client, and qmp_qmp_capabilities() accepts or denies capabilities requested by the client. The two compute the set of available capabilities independently. Not nice. Clean this up as follows. Compute available capabilities just once in monitor_qmp_caps_reset(), and store them in Monitor member qmp.capab_offered[]. Have qmp_greeting() and qmp_qmp_capabilities() use that. Both are now oblivious of capability details. Signed-off-by: Markus Armbruster --- monitor.c | 93 ++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/monitor.c b/monitor.c index 876a3a23a7..590e5b5b04 100644 --- a/monitor.c +++ b/monitor.c @@ -172,7 +172,8 @@ typedef struct { * mode. */ QmpCommandList *commands; - bool qmp_caps[QMP_CAPABILITY__MAX]; + bool capab_offered[QMP_CAPABILITY__MAX]; /* capabilities offered */ + bool capab[QMP_CAPABILITY__MAX]; /* offered and accepted */ /* * Protects qmp request/response queue. Please take monitor_lock * first when used together. @@ -1252,52 +1253,56 @@ static void monitor_init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG= ); } =20 -static bool qmp_cap_enabled(Monitor *mon, QMPCapability cap) -{ - return mon->qmp.qmp_caps[cap]; -} - static bool qmp_oob_enabled(Monitor *mon) { - return qmp_cap_enabled(mon, QMP_CAPABILITY_OOB); + return mon->qmp.capab[QMP_CAPABILITY_OOB]; } =20 -static void qmp_caps_check(Monitor *mon, QMPCapabilityList *list, - Error **errp) +static void monitor_qmp_caps_reset(Monitor *mon) { + memset(mon->qmp.capab_offered, 0, sizeof(mon->qmp.capab_offered)); + memset(mon->qmp.capab, 0, sizeof(mon->qmp.capab)); + mon->qmp.capab_offered[QMP_CAPABILITY_OOB] =3D mon->use_io_thread; +} + +/* + * Accept QMP capabilities in @list for @mon. + * On success, set mon->qmp.capab[], and return true. + * On error, set @errp, and return false. + */ +static bool qmp_caps_accept(Monitor *mon, QMPCapabilityList *list, + Error **errp) +{ + GString *unavailable =3D NULL; + bool capab[QMP_CAPABILITY__MAX]; + + memset(capab, 0, sizeof(capab)); + for (; list; list =3D list->next) { - assert(list->value < QMP_CAPABILITY__MAX); - switch (list->value) { - case QMP_CAPABILITY_OOB: - if (!mon->use_io_thread) { - /* - * Out-of-band only works with monitors that are - * running on dedicated I/O thread. - */ - error_setg(errp, "This monitor does not support " - "out-of-band (OOB)"); - return; + if (!mon->qmp.capab_offered[list->value]) { + if (!unavailable) { + unavailable =3D g_string_new(QMPCapability_str(list->value= )); + } else { + g_string_append_printf(unavailable, ", %s", + QMPCapability_str(list->value)); } - break; - default: - break; } + capab[list->value] =3D true; } -} =20 -/* This function should only be called after capabilities are checked. */ -static void qmp_caps_apply(Monitor *mon, QMPCapabilityList *list) -{ - for (; list; list =3D list->next) { - mon->qmp.qmp_caps[list->value] =3D true; + if (unavailable) { + error_setg(errp, "Capability %s not available", unavailable->str); + g_string_free(unavailable, true); + return false; } + + memcpy(mon->qmp.capab, capab, sizeof(capab)); + return true; } =20 void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, Error **errp) { - Error *local_err =3D NULL; - if (cur_mon->qmp.commands =3D=3D &qmp_commands) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, "Capabilities negotiation is already complete, command " @@ -1305,19 +1310,8 @@ void qmp_qmp_capabilities(bool has_enable, QMPCapabi= lityList *enable, return; } =20 - /* Enable QMP capabilities provided by the client if applicable. */ - if (has_enable) { - qmp_caps_check(cur_mon, enable, &local_err); - if (local_err) { - /* - * Failed check on any of the capabilities will fail the - * entire command (and thus not apply any of the other - * capabilities that were also requested). - */ - error_propagate(errp, local_err); - return; - } - qmp_caps_apply(cur_mon, enable); + if (!qmp_caps_accept(cur_mon, enable, errp)) { + return; } =20 cur_mon->qmp.commands =3D &qmp_commands; @@ -4384,11 +4378,9 @@ static QDict *qmp_greeting(Monitor *mon) qmp_marshal_query_version(NULL, &ver, NULL); =20 for (cap =3D 0; cap < QMP_CAPABILITY__MAX; cap++) { - if (!mon->use_io_thread && cap =3D=3D QMP_CAPABILITY_OOB) { - /* Monitors that are not using I/O thread won't support OOB */ - continue; + if (mon->qmp.capab_offered[cap]) { + qlist_append_str(cap_list, QMPCapability_str(cap)); } - qlist_append_str(cap_list, QMPCapability_str(cap)); } =20 return qdict_from_jsonf_nofail( @@ -4396,11 +4388,6 @@ static QDict *qmp_greeting(Monitor *mon) ver, cap_list); } =20 -static void monitor_qmp_caps_reset(Monitor *mon) -{ - memset(mon->qmp.qmp_caps, 0, sizeof(mon->qmp.qmp_caps)); -} - static void monitor_qmp_event(void *opaque, int event) { QDict *data; --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530550514577346.35762973684984; Mon, 2 Jul 2018 09:55:14 -0700 (PDT) Received: from localhost ([::1]:34264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa26U-0003uK-MT for importer@patchew.org; Mon, 02 Jul 2018 12:55:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1ax-0004Wd-Md for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006h2-FN for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47598 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 1fa1as-0006f9-0w for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 478017A7E5 for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 013771C5A9; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 00CDD1132753; Mon, 2 Jul 2018 18:22:18 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:17 +0200 Message-Id: <20180702162218.13678-32-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 31/32] monitor: Improve some comments 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: 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" Signed-off-by: Markus Armbruster --- monitor.c | 100 ++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/monitor.c b/monitor.c index 590e5b5b04..14af7b7ea6 100644 --- a/monitor.c +++ b/monitor.c @@ -168,15 +168,16 @@ typedef struct { JSONMessageParser parser; /* * When a client connects, we're in capabilities negotiation mode. - * When command qmp_capabilities succeeds, we go into command - * mode. + * @commands is &qmp_cap_negotiation_commands then. When command + * qmp_capabilities succeeds, we go into command mode, and + * @command becomes &qmp_commands. */ QmpCommandList *commands; bool capab_offered[QMP_CAPABILITY__MAX]; /* capabilities offered */ bool capab[QMP_CAPABILITY__MAX]; /* offered and accepted */ /* - * Protects qmp request/response queue. Please take monitor_lock - * first when used together. + * Protects qmp request/response queue. + * Take monitor_lock first when you need both. */ QemuMutex qmp_queue_lock; /* Input queue that holds all the parsed QMP requests */ @@ -231,7 +232,7 @@ struct Monitor { QemuMutex mon_lock; =20 /* - * Fields that are protected by the per-monitor lock. + * Members that are protected by the per-monitor lock */ QLIST_HEAD(, mon_fd_t) fds; QString *outbuf; @@ -240,6 +241,7 @@ struct Monitor { int mux_out; }; =20 +/* Shared monitor I/O thread */ IOThread *mon_iothread; =20 /* Bottom half to dispatch the requests received from I/O thread */ @@ -301,9 +303,9 @@ static inline bool monitor_is_qmp(const Monitor *mon) } =20 /** - * Whether @mon is using readline? Note: not all HMP monitors use - * readline, e.g., gdbserver has a non-interactive HMP monitor, so - * readline is not used there. + * Is @mon is using readline? + * Note: not all HMP monitors use readline, e.g., gdbserver has a + * non-interactive HMP monitor, so readline is not used there. */ static inline bool monitor_uses_readline(const Monitor *mon) { @@ -317,14 +319,12 @@ static inline bool monitor_is_hmp_non_interactive(con= st Monitor *mon) =20 /* * Return the clock to use for recording an event's time. + * It's QEMU_CLOCK_REALTIME, except for qtests it's + * QEMU_CLOCK_VIRTUAL, to support testing rate limits. * Beware: result is invalid before configure_accelerator(). */ static inline QEMUClockType monitor_get_event_clock(void) { - /* - * This allows us to perform tests on the monitor queues to verify - * that the rate limits are enforced. - */ return qtest_enabled() ? QEMU_CLOCK_VIRTUAL : QEMU_CLOCK_REALTIME; } =20 @@ -367,7 +367,7 @@ static void qmp_request_free(QMPRequest *req) g_free(req); } =20 -/* Must with the mon->qmp.qmp_queue_lock held */ +/* Caller must hold mon->qmp.qmp_queue_lock */ static void monitor_qmp_cleanup_req_queue_locked(Monitor *mon) { while (!g_queue_is_empty(mon->qmp.qmp_requests)) { @@ -375,7 +375,7 @@ static void monitor_qmp_cleanup_req_queue_locked(Monito= r *mon) } } =20 -/* Must with the mon->qmp.qmp_queue_lock held */ +/* Caller must hold the mon->qmp.qmp_queue_lock */ static void monitor_qmp_cleanup_resp_queue_locked(Monitor *mon) { while (!g_queue_is_empty(mon->qmp.qmp_responses)) { @@ -406,7 +406,7 @@ static gboolean monitor_unblocked(GIOChannel *chan, GIO= Condition cond, return FALSE; } =20 -/* Called with mon->mon_lock held. */ +/* Caller must hold mon->mon_lock */ static void monitor_flush_locked(Monitor *mon) { int rc; @@ -522,10 +522,8 @@ static void qmp_queue_response(Monitor *mon, QDict *rs= p) { if (mon->use_io_thread) { /* - * If using I/O thread, we need to queue the item so that I/O - * thread will do the rest for us. Take refcount so that - * caller won't free the data (which will be finally freed in - * responder thread). + * Push a reference to the response queue. The I/O thread + * drains that queue and emits. */ qemu_mutex_lock(&mon->qmp.qmp_queue_lock); g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(rsp)); @@ -533,8 +531,8 @@ static void qmp_queue_response(Monitor *mon, QDict *rsp) qemu_bh_schedule(qmp_respond_bh); } else { /* - * If not using monitor I/O thread, then we are in main thread. - * Do the emission right away. + * Not using monitor I/O thread, i.e. we are in the main thread. + * Emit right away. */ qmp_send_response(mon, rsp); } @@ -610,8 +608,9 @@ static MonitorQAPIEventConf monitor_qapi_event_conf[QAP= I_EVENT__MAX] =3D { }; =20 /* - * Emits the event to every monitor instance, @event is only used for trace - * Called with monitor_lock held. + * Broadcast an event to all monitors. + * @qdict is the event object. Its member "event" must match @event. + * Caller must hold monitor_lock. */ static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict) { @@ -980,8 +979,7 @@ static int parse_cmdline(const char *cmdline, } =20 /* - * Returns true if the command can be executed in preconfig mode - * i.e. it has the 'p' flag. + * Can command @cmd be executed in preconfig state? */ static bool cmd_can_preconfig(const mon_cmd_t *cmd) { @@ -2220,7 +2218,7 @@ void qmp_getfd(const char *fdname, Error **errp) tmp_fd =3D monfd->fd; monfd->fd =3D fd; qemu_mutex_unlock(&cur_mon->mon_lock); - /* Make sure close() is out of critical section */ + /* Make sure close() is outside critical section */ close(tmp_fd); return; } @@ -2249,7 +2247,7 @@ void qmp_closefd(const char *fdname, Error **errp) g_free(monfd->name); g_free(monfd); qemu_mutex_unlock(&cur_mon->mon_lock); - /* Make sure close() is out of critical section */ + /* Make sure close() is outside critical section */ close(tmp_fd); return; } @@ -4138,7 +4136,8 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) } =20 /* - * Pop one QMP request from monitor queues, return NULL if not found. + * Pop a QMP request from a monitor request queue. + * Return the request, or NULL all request queues are empty. * We are using round-robin fashion to pop the request, to avoid * processing commands only on a very busy monitor. To achieve that, * when we process one request on a specific monitor, we put that @@ -4233,7 +4232,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) } =20 if (qdict && qmp_is_oob(qdict)) { - /* Out-of-band (OOB) requests are executed directly in parser. */ + /* OOB commands are executed immediately */ trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) ?: ""); monitor_qmp_dispatch(mon, req, id); @@ -4355,8 +4354,8 @@ void monitor_resume(Monitor *mon) if (atomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { if (monitor_is_qmp(mon)) { /* - * For QMP monitors that are running in I/O thread, let's - * kick the thread in case it's sleeping. + * For QMP monitors that are running in the I/O thread, + * let's kick the thread in case it's sleeping. */ if (mon->use_io_thread) { aio_notify(iothread_get_aio_context(mon_iothread)); @@ -4504,18 +4503,18 @@ static void monitor_iothread_init(void) mon_iothread =3D iothread_create("mon_iothread", &error_abort); =20 /* - * This MUST be on main loop thread since we have commands that - * have assumption to be run on main loop thread. It would be - * nice that one day we can remove this assumption in the future. + * The dispatcher BH must run in the main loop thread, since we + * have commands assuming that context. It would be nice to get + * rid of those assumptions. */ qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(), monitor_qmp_bh_dispatcher, NULL); =20 /* - * Unlike the dispatcher BH, this must be run on the monitor I/O - * thread, so that monitors that are using I/O thread will make - * sure read/write operations are all done on the I/O thread. + * The responder BH must be run in the monitor I/O thread, so that + * monitors that are using the I/O thread have their output + * written by the I/O thread. */ qmp_respond_bh =3D aio_bh_new(monitor_get_aio_context(), monitor_qmp_bh_responder, @@ -4585,15 +4584,11 @@ static void monitor_qmp_setup_handlers_bh(void *opa= que) GMainContext *context; =20 if (mon->use_io_thread) { - /* - * When @use_io_thread is set, we use the global shared dedicated - * I/O thread for this monitor to handle input/output. - */ + /* Use @mon_iothread context */ context =3D monitor_get_io_context(); - /* We should have inited globals before reaching here. */ assert(context); } else { - /* The default main loop, which is the main thread */ + /* Use default main loop context */ context =3D NULL; } =20 @@ -4643,15 +4638,12 @@ void monitor_init(Chardev *chr, int flags) remove_fd_in_watch(chr); /* * We can't call qemu_chr_fe_set_handlers() directly here - * since during the procedure the chardev will be active - * and running in monitor I/O thread, while we'll still do - * something before returning from it, which is a possible - * race too. To avoid that, we just create a BH to setup - * the handlers. + * since chardev might be running in the monitor I/O + * thread. Schedule a bottom half. */ aio_bh_schedule_oneshot(monitor_get_aio_context(), monitor_qmp_setup_handlers_bh, mon); - /* We'll add this to mon_list in the BH when setup done */ + /* The bottom half will add @mon to @mon_list */ return; } else { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, @@ -4672,21 +4664,19 @@ void monitor_cleanup(void) =20 /* * We need to explicitly stop the I/O thread (but not destroy it), - * cleanup the monitor resources, then destroy the I/O thread since + * clean up the monitor resources, then destroy the I/O thread since * we need to unregister from chardev below in * monitor_data_destroy(), and chardev is not thread-safe yet */ iothread_stop(mon_iothread); =20 /* - * After we have I/O thread to send responses, it's possible that - * when we stop the I/O thread there are still replies queued in the - * responder queue. Flush all of them. Note that even after this - * flush it's still possible that out buffer is not flushed. - * It'll be done in below monitor_flush() as the last resort. + * Flush all response queues. Note that even after this flush, + * data may remain in output buffers. */ monitor_qmp_bh_responder(NULL); =20 + /* Flush output buffers and destroy monitors */ qemu_mutex_lock(&monitor_lock); QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { QTAILQ_REMOVE(&mon_list, mon, entry); --=20 2.17.1 From nobody Tue Nov 4 15:26:29 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 1530549781296385.70633343717986; Mon, 2 Jul 2018 09:43:01 -0700 (PDT) Received: from localhost ([::1]:34197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1um-00030V-GC for importer@patchew.org; Mon, 02 Jul 2018 12:43:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1aw-0004UX-1g for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1as-0006gl-B0 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54944 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 1fa1ar-0006fB-SA for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:22:26 -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 4BC3840704BB for ; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0558021568A1; Mon, 2 Jul 2018 16:22:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 06B911132754; Mon, 2 Jul 2018 18:22:19 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 18:22:18 +0200 Message-Id: <20180702162218.13678-33-armbru@redhat.com> In-Reply-To: <20180702162218.13678-1-armbru@redhat.com> References: <20180702162218.13678-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.7]); Mon, 02 Jul 2018 16:22:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 16:22:25 +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 32/32] qapi: Polish command flags documentation in qapi-code-gen.txt 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: 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" Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 61 +++++++++++++++--------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index f020f6bab2..8decd6f17d 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -624,60 +624,48 @@ its return value. In rare cases, QAPI cannot express a type-safe representation of a corresponding Client JSON Protocol command. You then have to suppress generation of a marshalling function by including a key 'gen' with -boolean value false, and instead write your own function. Please try -to avoid adding new commands that rely on this, and instead use -type-safe unions. For an example of this usage: +boolean value false, and instead write your own function. For +example: =20 { 'command': 'netdev_add', 'data': {'type': 'str', 'id': 'str'}, 'gen': false } =20 +Please try to avoid adding new commands that rely on this, and instead +use type-safe unions. + Normally, the QAPI schema is used to describe synchronous exchanges, where a response is expected. But in some cases, the action of a command is expected to change state in a way that a successful response is not possible (although the command will still return a normal dictionary error on failure). When a successful reply is not -possible, the command expression should include the optional key +possible, the command expression includes the optional key 'success-response' with boolean value false. So far, only QGA makes use of this member. =20 -A command can be declared to support out-of-band (OOB) execution. By -default, commands do not support OOB. To declare a command that -supports it, the schema includes an extra 'allow-oob' field. For -example: +Key 'allow-oob' declares whether the command supports out-of-band +(OOB) execution. It defaults to false. For example: =20 { 'command': 'migrate_recover', 'data': { 'uri': 'str' }, 'allow-oob': true } =20 -To execute a command with out-of-band priority, the client uses key -"exec-oob" instead of "execute". Example: +See qmp-spec.txt for out-of-band execution syntax and semantics. =20 - =3D> { "exec-oob": "migrate-recover", - "arguments": { "uri": "tcp:192.168.1.200:12345" } } - <=3D { "return": { } } +Commands supporting out-of-band execution can still be executed +in-band. =20 -Without it, even the commands that support out-of-band execution will -still be run in-band. +When a command is executed in-band, its handler runs in the main +thread with the BQL held. =20 -Under normal QMP command execution, the following apply to each -command: +When a command is executed out-of-band, its handler runs in a +dedicated monitor I/O thread with the BQL *not* held. =20 -- They are executed in order, -- They run only in main thread of QEMU, -- They run with the BQL held. +An OOB-capable command handler must satisfy the following conditions: =20 -When a command is executed with OOB, the following changes occur: - -- They can be completed before a pending in-band command, -- They run in a dedicated monitor thread, -- They run with the BQL not held. - -OOB command handlers must satisfy the following conditions: - -- It terminates quickly, -- It does not invoke system calls that may block, +- It terminates quickly. +- It does not invoke system calls that may block. - It does not access guest RAM that may block when userfaultfd is - enabled for postcopy live migration, + enabled for postcopy live migration. - It takes only "fast" locks, i.e. all critical sections protected by any lock it takes also satisfy the conditions for OOB command handler code. @@ -686,17 +674,18 @@ The restrictions on locking limit access to shared st= ate. Such access requires synchronization, but OOB commands can't take the BQL or any other "slow" lock. =20 -If in doubt, do not implement OOB execution support. +When in doubt, do not implement OOB execution support. =20 -A command may use the optional 'allow-preconfig' key to permit its executi= on -at early runtime configuration stage (preconfig runstate). -If not specified then a command defaults to 'allow-preconfig': false. +Key 'allow-preconfig' declares whether the command is available before +the machine is built. It defaults to false. For example: =20 -An example of declaring a command that is enabled during preconfig: { 'command': 'qmp_capabilities', 'data': { '*enable': [ 'QMPCapability' ] }, 'allow-preconfig': true } =20 +QMP is available before the machine is built only when QEMU was +started with --preconfig. + =3D=3D=3D Events =3D=3D=3D =20 Usage: { 'event': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, --=20 2.17.1