From nobody Sun Feb 8 21:11:34 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 1488703475881716.1488806060496; Sun, 5 Mar 2017 00:44:35 -0800 (PST) Received: from localhost ([::1]:37974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckRmM-0006Nz-HY for importer@patchew.org; Sun, 05 Mar 2017 03:44:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckReA-0000Oh-1u for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckRe6-0002x6-N4 for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckRe6-0002vr-E0 for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:02 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D02081231 for ; Sun, 5 Mar 2017 08:36:01 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 217122D653 for ; Sun, 5 Mar 2017 08:36:01 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 73A8D1138657; Sun, 5 Mar 2017 09:35:58 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Sun, 5 Mar 2017 09:35:35 +0100 Message-Id: <1488702958-24336-5-git-send-email-armbru@redhat.com> In-Reply-To: <1488702958-24336-1-git-send-email-armbru@redhat.com> References: <1488702958-24336-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 05 Mar 2017 08:36:01 +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] [PULL v2 04/27] 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_unregister_commands_hack() 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 Message-Id: <1488544368-30622-5-git-send-email-armbru@redhat.com> --- 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 b68944d..53f5f5a 100644 --- a/monitor.c +++ b/monitor.c @@ -997,8 +997,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, @@ -1006,12 +1008,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 16a3b5e..71b75ef 100644 --- a/vl.c +++ b/vl.c @@ -2988,7 +2988,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