From 150072398f3f0c3e5bef360f9d8fb68e81201c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Wed, 25 Mar 2026 15:47:12 +0100 Subject: [PATCH] qom: Restrict compat properties API to system emulation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move compat properties API definitions to their own file unit, compile it only when system emulation is configured. Add a pair of stubs for user emulation. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Michael Tokarev Message-Id: <20260325151728.45378-6-philmd@linaro.org> --- MAINTAINERS | 1 + qom/compat-properties.c | 76 +++++++++++++++++++++++++++++++++++ qom/meson.build | 3 ++ qom/object.c | 60 --------------------------- stubs/meson.build | 1 + stubs/qom-compat-properties.c | 14 +++++++ 6 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 qom/compat-properties.c create mode 100644 stubs/qom-compat-properties.c diff --git a/MAINTAINERS b/MAINTAINERS index facc4b499a..45d258f64f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3533,6 +3533,7 @@ F: qapi/qom.json F: scripts/coccinelle/qom-parent-type.cocci F: scripts/qom-cast-macro-clean-cocci-gen.py F: qom/ +F: stubs/qom-compat-properties.c F: tests/unit/check-qom-interface.c F: tests/unit/check-qom-proplist.c F: tests/qtest/qom-test.c diff --git a/qom/compat-properties.c b/qom/compat-properties.c new file mode 100644 index 0000000000..2110754155 --- /dev/null +++ b/qom/compat-properties.c @@ -0,0 +1,76 @@ +/* + * QEMU Object Model + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qom/compat-properties.h" +#include "qom/qom-qobject.h" +#include "hw/core/qdev.h" + +/* + * Global property defaults + * Slot 0: accelerator's global property defaults + * Slot 1: machine's global property defaults + * Slot 2: global properties from legacy command line option + * Each is a GPtrArray of GlobalProperty. + * Applied in order, later entries override earlier ones. + */ +static GPtrArray *object_compat_props[3]; + +/* + * Retrieve @GPtrArray for global property defined with options + * other than "-global". These are generally used for syntactic + * sugar and legacy command line options. + */ +void object_register_sugar_prop(const char *driver, const char *prop, + const char *value, bool optional) +{ + GlobalProperty *g; + if (!object_compat_props[2]) { + object_compat_props[2] = g_ptr_array_new(); + } + g = g_new0(GlobalProperty, 1); + g->driver = g_strdup(driver); + g->property = g_strdup(prop); + g->value = g_strdup(value); + g->optional = optional; + g_ptr_array_add(object_compat_props[2], g); +} + +/* + * Set machine's global property defaults to @compat_props. + * May be called at most once. + */ +void object_set_machine_compat_props(GPtrArray *compat_props) +{ + assert(!object_compat_props[1]); + object_compat_props[1] = compat_props; +} + +/* + * Set accelerator's global property defaults to @compat_props. + * May be called at most once. + */ +void object_set_accelerator_compat_props(GPtrArray *compat_props) +{ + assert(!object_compat_props[0]); + object_compat_props[0] = compat_props; +} + +void object_apply_compat_props(Object *obj) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) { + object_apply_global_props(obj, object_compat_props[i], + i == 2 ? &error_fatal : &error_abort); + } +} diff --git a/qom/meson.build b/qom/meson.build index 8192243430..bd6f4aadd7 100644 --- a/qom/meson.build +++ b/qom/meson.build @@ -5,6 +5,9 @@ qom_ss.add(files( 'object_interfaces.c', 'qom-qobject.c', )) +if have_system + qom_ss.add(files('compat-properties.c')) +endif qmp_ss.add(files('qom-qmp-cmds.c')) system_ss.add(files('qom-hmp-cmds.c')) diff --git a/qom/object.c b/qom/object.c index d6500bcbbf..f981e27044 100644 --- a/qom/object.c +++ b/qom/object.c @@ -480,66 +480,6 @@ bool object_apply_global_props(Object *obj, const GPtrArray *props, return true; } -/* - * Global property defaults - * Slot 0: accelerator's global property defaults - * Slot 1: machine's global property defaults - * Slot 2: global properties from legacy command line option - * Each is a GPtrArray of GlobalProperty. - * Applied in order, later entries override earlier ones. - */ -static GPtrArray *object_compat_props[3]; - -/* - * Retrieve @GPtrArray for global property defined with options - * other than "-global". These are generally used for syntactic - * sugar and legacy command line options. - */ -void object_register_sugar_prop(const char *driver, const char *prop, - const char *value, bool optional) -{ - GlobalProperty *g; - if (!object_compat_props[2]) { - object_compat_props[2] = g_ptr_array_new(); - } - g = g_new0(GlobalProperty, 1); - g->driver = g_strdup(driver); - g->property = g_strdup(prop); - g->value = g_strdup(value); - g->optional = optional; - g_ptr_array_add(object_compat_props[2], g); -} - -/* - * Set machine's global property defaults to @compat_props. - * May be called at most once. - */ -void object_set_machine_compat_props(GPtrArray *compat_props) -{ - assert(!object_compat_props[1]); - object_compat_props[1] = compat_props; -} - -/* - * Set accelerator's global property defaults to @compat_props. - * May be called at most once. - */ -void object_set_accelerator_compat_props(GPtrArray *compat_props) -{ - assert(!object_compat_props[0]); - object_compat_props[0] = compat_props; -} - -void object_apply_compat_props(Object *obj) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) { - object_apply_global_props(obj, object_compat_props[i], - i == 2 ? &error_fatal : &error_abort); - } -} - static void object_class_property_init_all(Object *obj) { ObjectPropertyIterator iter; diff --git a/stubs/meson.build b/stubs/meson.build index 7189ff63ed..f33b1d2a08 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -54,6 +54,7 @@ if have_user # Symbols that are used by hw/core. stub_ss.add(files('cpu-synchronize-state.c')) stub_ss.add(files('cpu-destroy-address-spaces.c')) + stub_ss.add(files('qom-compat-properties.c')) # Stubs for QAPI events. Those can always be included in the build, but # they are not built at all for --disable-system builds. diff --git a/stubs/qom-compat-properties.c b/stubs/qom-compat-properties.c new file mode 100644 index 0000000000..2c955677be --- /dev/null +++ b/stubs/qom-compat-properties.c @@ -0,0 +1,14 @@ +/* + * QEMU Object Model (compat properties stubs for user emulation) + * + * Copyright (c) Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qom/compat-properties.h" + +void object_apply_compat_props(Object *obj) +{ +}