qom: Restrict compat properties API to system emulation

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é <philmd@linaro.org>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Message-Id: <20260325151728.45378-6-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé
2026-03-25 15:47:12 +01:00
parent 50362dd65a
commit 150072398f
6 changed files with 95 additions and 60 deletions
+1
View File
@@ -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
+76
View File
@@ -0,0 +1,76 @@
/*
* QEMU Object Model
*
* Copyright IBM, Corp. 2011
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* 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);
}
}
+3
View File
@@ -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'))
-60
View File
@@ -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;
+1
View File
@@ -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.
+14
View File
@@ -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)
{
}