[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 018/114] qom: register late types through module_call_init_fn



Display early_init, the console-vc fallback, the PPC KVM host CPU,
and unit-test types register after MODULE_INIT_QOM. Route them
through module_call_init_fn so they take the same before/init/after
path as a late DSO.

Signed-off-by: Yonggang Luo <luoyonggang@xxxxxxxxx>
---
 target/ppc/kvm.c                      | 12 +++++++++++-
 tests/unit/check-qom-interface.c      | 12 +++++++++---
 tests/unit/check-qom-proplist.c       | 13 +++++++++----
 tests/unit/test-io-channel-websock.c  |  7 ++++++-
 tests/unit/test-io-task.c             |  7 ++++++-
 tests/unit/test-qdev-global-props.c   | 14 ++++++++++----
 tests/unit/test-qdev.c                |  8 +++++++-
 tests/unit/test-ram-discard-manager.c |  7 ++++++-
 ui/console-vc.c                       | 13 ++++++++++---
 ui/dbus.c                             |  8 +++++++-
 ui/gtk.c                              | 10 +++++++++-
 ui/spice-app.c                        |  7 ++++++-
 12 files changed, 96 insertions(+), 22 deletions(-)

diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 8e89a6c665c..a3c16850a18 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -22,6 +22,7 @@
 #include <linux/kvm.h>
 
 #include "qapi/error.h"
+#include "qemu/module.h"
 #include "qemu/error-report.h"
 #include "cpu.h"
 #include "cpu-models.h"
@@ -2706,6 +2707,13 @@ static void pseries_machine_class_fixup(ObjectClass *oc, 
void *opaque)
     mc->default_cpu_type = TYPE_HOST_POWERPC_CPU;
 }
 
+static TypeInfo host_cpu_type_info;
+
+static void kvm_ppc_register_host_cpu_type_qom(void)
+{
+    type_register_static(&host_cpu_type_info);
+}
+
 static int kvm_ppc_register_host_cpu_type(void)
 {
     TypeInfo type_info = {
@@ -2722,7 +2730,9 @@ static int kvm_ppc_register_host_cpu_type(void)
         return -1;
     }
     type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
-    type_register_static(&type_info);
+    host_cpu_type_info = type_info;
+    module_call_init_fn(MODULE_INIT_QOM, kvm_ppc_register_host_cpu_type_qom,
+                        &error_abort);
     /* override TCG default cpu type with 'host' cpu model */
     object_class_foreach(pseries_machine_class_fixup, TYPE_SPAPR_MACHINE,
                          false, NULL);
diff --git a/tests/unit/check-qom-interface.c b/tests/unit/check-qom-interface.c
index 86ae5f6c3b1..1da051ed98b 100644
--- a/tests/unit/check-qom-interface.c
+++ b/tests/unit/check-qom-interface.c
@@ -12,6 +12,7 @@
 #include "qemu/osdep.h"
 
 #include "qom/object.h"
+#include "qapi/error.h"
 #include "qemu/module.h"
 
 
@@ -86,14 +87,19 @@ static void interface_intermediate_test(void)
     test_interface_impl(TYPE_INTERMEDIATE_IMPL);
 }
 
+static void register_types(void)
+{
+    type_register_static(&test_if_info);
+    type_register_static(&direct_impl_info);
+    type_register_static(&intermediate_impl_info);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
 
     module_call_init(MODULE_INIT_QOM);
-    type_register_static(&test_if_info);
-    type_register_static(&direct_impl_info);
-    type_register_static(&intermediate_impl_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
 
     g_test_add_func("/qom/interface/direct_impl", interface_direct_test);
     g_test_add_func("/qom/interface/intermediate_impl",
diff --git a/tests/unit/check-qom-proplist.c b/tests/unit/check-qom-proplist.c
index 89de92b7d91..074a69a7fd3 100644
--- a/tests/unit/check-qom-proplist.c
+++ b/tests/unit/check-qom-proplist.c
@@ -703,15 +703,20 @@ static void test_qom_partial_path(void)
     object_unparent(cont1);
 }
 
-int main(int argc, char **argv)
+static void register_types(void)
 {
-    g_test_init(&argc, &argv, NULL);
-
-    module_call_init(MODULE_INIT_QOM);
     type_register_static(&dummy_info);
     type_register_static(&dummy_dev_info);
     type_register_static(&dummy_bus_info);
     type_register_static(&dummy_backend_info);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    module_call_init(MODULE_INIT_QOM);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
 
     g_test_add_func("/qom/proplist/createlist/tree",
                     test_dummy_createlist_tree);
diff --git a/tests/unit/test-io-channel-websock.c 
b/tests/unit/test-io-channel-websock.c
index 88da24f993d..d4a92572866 100644
--- a/tests/unit/test-io-channel-websock.c
+++ b/tests/unit/test-io-channel-websock.c
@@ -219,10 +219,15 @@ static void test_websock_stalled_write(const void *opaque)
     g_assert_true(g_str_has_prefix(reply, "HTTP/1.1 400 Bad Request\r\n"));
 }
 
+static void register_types(void)
+{
+    type_register_static(&qio_channel_stall_info);
+}
+
 int main(int argc, char **argv)
 {
     module_call_init(MODULE_INIT_QOM);
-    type_register_static(&qio_channel_stall_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
     g_test_init(&argc, &argv, NULL);
 
 #define TEST_BAD_REQUEST(name, request)                         \
diff --git a/tests/unit/test-io-task.c b/tests/unit/test-io-task.c
index b1c8ecb7abb..55c4a64f041 100644
--- a/tests/unit/test-io-task.c
+++ b/tests/unit/test-io-task.c
@@ -279,11 +279,16 @@ static void test_task_thread_failure(void)
 }
 
 
+static void register_types(void)
+{
+    type_register_static(&dummy_info);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
     module_call_init(MODULE_INIT_QOM);
-    type_register_static(&dummy_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
     g_test_add_func("/crypto/task/complete", test_task_complete);
     g_test_add_func("/crypto/task/cancel", test_task_cancel);
     g_test_add_func("/crypto/task/datafree", test_task_data_free);
diff --git a/tests/unit/test-qdev-global-props.c 
b/tests/unit/test-qdev-global-props.c
index 8ea362cbb90..e0aaee05d8b 100644
--- a/tests/unit/test-qdev-global-props.c
+++ b/tests/unit/test-qdev-global-props.c
@@ -27,6 +27,7 @@
 #include "hw/core/qdev-properties.h"
 #include "qom/object.h"
 #include "qapi/error.h"
+#include "qemu/module.h"
 #include "qapi/visitor.h"
 
 
@@ -302,17 +303,22 @@ static void test_subclass_global_props(void)
     g_assert_cmpuint(mt->prop2, ==, 104);
 }
 
-int main(int argc, char **argv)
+static void register_types(void)
 {
-    g_test_init(&argc, &argv, NULL);
-
-    module_call_init(MODULE_INIT_QOM);
     type_register_static(&static_prop_type);
     type_register_static(&subclass_type);
     type_register_static(&dynamic_prop_type);
     type_register_static(&hotplug_type);
     type_register_static(&nohotplug_type);
     type_register_static(&nondevice_type);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    module_call_init(MODULE_INIT_QOM);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
 
     test_init_machine();
 
diff --git a/tests/unit/test-qdev.c b/tests/unit/test-qdev.c
index 77c3eee7171..5755fa57b58 100644
--- a/tests/unit/test-qdev.c
+++ b/tests/unit/test-qdev.c
@@ -2,6 +2,7 @@
 #include "hw/core/qdev-properties.h"
 #include "qom/object.h"
 #include "qapi/error.h"
+#include "qemu/module.h"
 #include "qapi/visitor.h"
 
 
@@ -89,12 +90,17 @@ static void test_qdev_double_realization(void)
 }
 
 
+static void register_types(void)
+{
+    type_register_static(&my_dev_type_info);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
 
     module_call_init(MODULE_INIT_QOM);
-    type_register_static(&my_dev_type_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
     test_init_machine();
 
     g_test_add_func("/qdev/free-properties",
diff --git a/tests/unit/test-ram-discard-manager.c 
b/tests/unit/test-ram-discard-manager.c
index 3d39a1e94ba..5bdcf9b074c 100644
--- a/tests/unit/test-ram-discard-manager.c
+++ b/tests/unit/test-ram-discard-manager.c
@@ -1187,12 +1187,17 @@ static void test_replay_discarded(void)
     test_teardown();
 }
 
+static void register_types(void)
+{
+    type_register_static(&test_rds_info);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
 
     module_call_init(MODULE_INIT_QOM);
-    type_register_static(&test_rds_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_types, &error_abort);
 
     g_test_add_func("/ram-discard-manager/single-source/basic",
                     test_single_source_basic);
diff --git a/ui/console-vc.c b/ui/console-vc.c
index 53d9e9d39b3..c998a0dd807 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -6,6 +6,7 @@
 
 #include "chardev/char.h"
 #include "qapi/error.h"
+#include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/queue.h"
 #include "qom/compat-properties.h"
@@ -349,10 +350,16 @@ static const TypeInfo char_vc_type_info = {
     .class_init = char_vc_class_init,
 };
 
+static void register_default_char_vc(void)
+{
+    type_register_static(&char_vc_type_info);
+}
+
 void qemu_console_early_init(void)
 {
-    /* set the default vc driver */
-    if (!object_class_by_name(TYPE_CHARDEV_VC)) {
-        type_register_static(&char_vc_type_info);
+    /* set the default vc driver if a display backend did not */
+    if (object_class_by_name(TYPE_CHARDEV_VC)) {
+        return;
     }
+    module_call_init_fn(MODULE_INIT_QOM, register_default_char_vc, 
&error_abort);
 }
diff --git a/ui/dbus.c b/ui/dbus.c
index 7be0f8e2611..34b33bb9ca1 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -38,6 +38,7 @@
 #include "qemu/audio.h"
 #include "audio/audio_int.h" /* FIXME: use QOM dynamic cast instead of 
drv->name */
 #include "qapi/error.h"
+#include "qemu/module.h"
 #include "trace.h"
 
 #include "dbus.h"
@@ -623,6 +624,11 @@ static const TypeInfo dbus_vc_type_info = {
     .class_init = dbus_vc_class_init,
 };
 
+static void register_dbus_char_vc(void)
+{
+    type_register_static(&dbus_vc_type_info);
+}
+
 static void
 early_dbus_init(DisplayOptions *opts)
 {
@@ -638,7 +644,7 @@ early_dbus_init(DisplayOptions *opts)
 
     using_dbus_display = 1;
 
-    type_register_static(&dbus_vc_type_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_dbus_char_vc, &error_abort);
 }
 
 static void
diff --git a/ui/gtk.c b/ui/gtk.c
index ed7ffc06b15..2ddc1f8a901 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -38,6 +38,7 @@
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
+#include "qemu/module.h"
 #include "qemu-main.h"
 
 #include "ui/console.h"
@@ -2893,6 +2894,13 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
     qemu_main = NULL;
 }
 
+#if defined(CONFIG_VTE)
+static void register_gtk_char_vc(void)
+{
+    type_register_static(&char_gd_vc_type_info);
+}
+#endif
+
 static void early_gtk_display_init(DisplayOptions *opts)
 {
     /* The QEMU code relies on the assumption that it's always run in
@@ -2946,7 +2954,7 @@ static void early_gtk_display_init(DisplayOptions *opts)
     keycode_map = gd_get_keymap(&keycode_maplen, &keycode_xorgevdev);
 
 #if defined(CONFIG_VTE)
-    type_register_static(&char_gd_vc_type_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_gtk_char_vc, &error_abort);
 #endif
 }
 
diff --git a/ui/spice-app.c b/ui/spice-app.c
index fe3df62bfa5..dae3415ec8d 100644
--- a/ui/spice-app.c
+++ b/ui/spice-app.c
@@ -132,6 +132,11 @@ static void spice_app_cleanup(void)
     g_clear_pointer(&app_dir, g_free);
 }
 
+static void register_spice_char_vc(void)
+{
+    type_register_static(&char_vc_type_info);
+}
+
 static void spice_app_display_early_init(DisplayOptions *opts)
 {
     QemuOpts *qopts;
@@ -170,7 +175,7 @@ static void spice_app_display_early_init(DisplayOptions 
*opts)
         exit(1);
     }
 
-    type_register_static(&char_vc_type_info);
+    module_call_init_fn(MODULE_INIT_QOM, register_spice_char_vc, &error_abort);
 
     sock_path = g_strjoin("", app_dir, "/", "spice.sock", NULL);
     qopts = qemu_opts_create(list, NULL, 0, &error_abort);
-- 
2.52.0.windows.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.