From nobody Mon Feb 9 08:10:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487886719718127.50455269587269; Thu, 23 Feb 2017 13:51:59 -0800 (PST) Received: from localhost ([::1]:33060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ch1Is-0005HD-EU for importer@patchew.org; Thu, 23 Feb 2017 16:51:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ch1CV-0007l6-Vn for qemu-devel@nongnu.org; Thu, 23 Feb 2017 16:45:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ch1CT-0004ar-3I for qemu-devel@nongnu.org; Thu, 23 Feb 2017 16:45:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ch1CS-0004aN-RM for qemu-devel@nongnu.org; Thu, 23 Feb 2017 16:45:21 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 050014E4C5 for ; Thu, 23 Feb 2017 21:45:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NLjJO9003286 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 23 Feb 2017 16:45:20 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C44431138657; Thu, 23 Feb 2017 22:45:17 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Feb 2017 22:45:00 +0100 Message-Id: <1487886317-27400-5-git-send-email-armbru@redhat.com> In-Reply-To: <1487886317-27400-1-git-send-email-armbru@redhat.com> References: <1487886317-27400-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 23 Feb 2017 21:45:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/21] qmp: Dumb down how we run QMP command registration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The way we get QMP commands registered is high tech: * qapi-commands.py generates qmp_init_marshal() that does the actual work * it also generates the magic to register it as a MODULE_INIT_QAPI function, so it runs when someone calls module_call_init(MODULE_INIT_QAPI) * main() calls module_call_init() QEMU needs to register a few non-qapified commands. Same high tech works: monitor.c has its own qmp_init_marshal() along with the magic to make it run in module_call_init(MODULE_INIT_QAPI). QEMU also needs to unregister commands that are not wanted in this build's configuration (commit 5032a16). Simple enough: qmp_unregister_commands_hack(). The difficulty is to make it run after the generated qmp_init_marshal(). We can't simply run it in monitor.c's qmp_init_marshal(), because the order in which the registered functions run is indeterminate. So qmp_init_marshal() registers qmp_init_marshal() separately. Since registering *appends* to the list of registered functions, this will make it run after all the functions that have been registered already. I suspect it takes a long and expensive computer science education to not find this silly. Dumb it down as follows: * Drop MODULE_INIT_QAPI entirely * Give the generated qmp_init_marshal() external linkage. * Call it instead of module_call_init(MODULE_INIT_QAPI) * Except in QEMU proper, call new monitor_init_qmp_commands() that in turn calls the generated qmp_init_marshal(), registers the additional commands and unregisters the unwanted ones. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/monitor/monitor.h | 1 + include/qemu/module.h | 2 -- monitor.c | 9 ++++----- qga/main.c | 2 +- scripts/qapi-commands.py | 5 ++--- tests/test-qmp-commands.c | 2 +- vl.c | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index e64b944..d2b3aaf 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -16,6 +16,7 @@ extern Monitor *cur_mon; =20 bool monitor_cur_is_qmp(void); =20 +void monitor_init_qmp_commands(void); void monitor_init(Chardev *chr, int flags); void monitor_cleanup(void); =20 diff --git a/include/qemu/module.h b/include/qemu/module.h index 877cca7..56dd218 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -42,7 +42,6 @@ static void __attribute__((constructor)) do_qemu_init_ ##= function(void) \ typedef enum { MODULE_INIT_BLOCK, MODULE_INIT_OPTS, - MODULE_INIT_QAPI, MODULE_INIT_QOM, MODULE_INIT_TRACE, MODULE_INIT_MAX @@ -50,7 +49,6 @@ typedef enum { =20 #define block_init(function) module_init(function, MODULE_INIT_BLOCK) #define opts_init(function) module_init(function, MODULE_INIT_OPTS) -#define qapi_init(function) module_init(function, MODULE_INIT_QAPI) #define type_init(function) module_init(function, MODULE_INIT_QOM) #define trace_init(function) module_init(function, MODULE_INIT_TRACE) =20 diff --git a/monitor.c b/monitor.c index 56867e8..5be71d6 100644 --- a/monitor.c +++ b/monitor.c @@ -995,8 +995,10 @@ static void qmp_unregister_commands_hack(void) #endif } =20 -static void qmp_init_marshal(void) +void monitor_init_qmp_commands(void) { + qmp_init_marshal(); + qmp_register_command("query-qmp-schema", qmp_query_qmp_schema, QCO_NO_OPTIONS); qmp_register_command("device_add", qmp_device_add, @@ -1004,12 +1006,9 @@ static void qmp_init_marshal(void) qmp_register_command("netdev_add", qmp_netdev_add, QCO_NO_OPTIONS); =20 - /* call it after the rest of qapi_init() */ - register_module_init(qmp_unregister_commands_hack, MODULE_INIT_QAPI); + qmp_unregister_commands_hack(); } =20 -qapi_init(qmp_init_marshal); - /* set the current CPU defined by the user */ int monitor_set_cpu(int cpu_index) { diff --git a/qga/main.c b/qga/main.c index 538e4ee..6f8c614 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1321,7 +1321,7 @@ int main(int argc, char **argv) =20 config->log_level =3D G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; =20 - module_call_init(MODULE_INIT_QAPI); + qmp_init_marshal(); =20 init_dfl_pathnames(); config_load(config); diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 09e8467..a75946f 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -208,14 +208,12 @@ def gen_register_command(name, success_response): def gen_registry(registry): ret =3D mcgen(''' =20 -static void qmp_init_marshal(void) +void qmp_init_marshal(void) { ''') ret +=3D registry ret +=3D mcgen(''' } - -qapi_init(qmp_init_marshal); ''') return ret =20 @@ -308,6 +306,7 @@ fdecl.write(mcgen(''' #include "qapi/qmp/qdict.h" #include "qapi/error.h" =20 +void qmp_init_marshal(void); ''', prefix=3Dprefix)) =20 diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index ff94481..c4e20d1 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -273,7 +273,7 @@ int main(int argc, char **argv) g_test_add_func("/0.15/dealloc_types", test_dealloc_types); g_test_add_func("/0.15/dealloc_partial", test_dealloc_partial); =20 - module_call_init(MODULE_INIT_QAPI); + qmp_init_marshal(); g_test_run(); =20 return 0; diff --git a/vl.c b/vl.c index b5d0a19..a0634b0 100644 --- a/vl.c +++ b/vl.c @@ -2966,7 +2966,7 @@ int main(int argc, char **argv, char **envp) qemu_init_exec_dir(argv[0]); =20 module_call_init(MODULE_INIT_QOM); - module_call_init(MODULE_INIT_QAPI); + monitor_init_qmp_commands(); =20 qemu_add_opts(&qemu_drive_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); --=20 2.7.4