@samitouri / QOSamiQemu / commits / 150072398f

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>

Philippe Mathieu-Daudé committed Mar 25, 2026 at 15:47 UTC 150072398f3f0c3e5bef360f9d8fb68e81201c98
6 files changed +95 -60
MAINTAINERS
+1
@@ -3533,6 +3533,7 @@ F: qapi/qom.json
3533 F: scripts/coccinelle/qom-parent-type.cocci
3534 F: scripts/qom-cast-macro-clean-cocci-gen.py
3535 F: qom/
3536 +F: stubs/qom-compat-properties.c
3537 F: tests/unit/check-qom-interface.c
3538 F: tests/unit/check-qom-proplist.c
3539 F: tests/qtest/qom-test.c
qom/compat-properties.c new
+76
@@ -0,0 +1,76 @@
1 +/*
2 + * QEMU Object Model
3 + *
4 + * Copyright IBM, Corp. 2011
5 + *
6 + * Authors:
7 + * Anthony Liguori <aliguori@us.ibm.com>
8 + *
9 + * SPDX-License-Identifier: GPL-2.0-or-later
10 + */
11 +
12 +#include "qemu/osdep.h"
13 +#include "qapi/error.h"
14 +#include "qom/compat-properties.h"
15 +#include "qom/qom-qobject.h"
16 +#include "hw/core/qdev.h"
17 +
18 +/*
19 + * Global property defaults
20 + * Slot 0: accelerator's global property defaults
21 + * Slot 1: machine's global property defaults
22 + * Slot 2: global properties from legacy command line option
23 + * Each is a GPtrArray of GlobalProperty.
24 + * Applied in order, later entries override earlier ones.
25 + */
26 +static GPtrArray *object_compat_props[3];
27 +
28 +/*
29 + * Retrieve @GPtrArray for global property defined with options
30 + * other than "-global". These are generally used for syntactic
31 + * sugar and legacy command line options.
32 + */
33 +void object_register_sugar_prop(const char *driver, const char *prop,
34 + const char *value, bool optional)
35 +{
36 + GlobalProperty *g;
37 + if (!object_compat_props[2]) {
38 + object_compat_props[2] = g_ptr_array_new();
39 + }
40 + g = g_new0(GlobalProperty, 1);
41 + g->driver = g_strdup(driver);
42 + g->property = g_strdup(prop);
43 + g->value = g_strdup(value);
44 + g->optional = optional;
45 + g_ptr_array_add(object_compat_props[2], g);
46 +}
47 +
48 +/*
49 + * Set machine's global property defaults to @compat_props.
50 + * May be called at most once.
51 + */
52 +void object_set_machine_compat_props(GPtrArray *compat_props)
53 +{
54 + assert(!object_compat_props[1]);
55 + object_compat_props[1] = compat_props;
56 +}
57 +
58 +/*
59 + * Set accelerator's global property defaults to @compat_props.
60 + * May be called at most once.
61 + */
62 +void object_set_accelerator_compat_props(GPtrArray *compat_props)
63 +{
64 + assert(!object_compat_props[0]);
65 + object_compat_props[0] = compat_props;
66 +}
67 +
68 +void object_apply_compat_props(Object *obj)
69 +{
70 + int i;
71 +
72 + for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) {
73 + object_apply_global_props(obj, object_compat_props[i],
74 + i == 2 ? &error_fatal : &error_abort);
75 + }
76 +}
qom/meson.build
+3
@@ -5,6 +5,9 @@ qom_ss.add(files(
5 'object_interfaces.c',
6 'qom-qobject.c',
7 ))
8 +if have_system
9 + qom_ss.add(files('compat-properties.c'))
10 +endif
11
12 qmp_ss.add(files('qom-qmp-cmds.c'))
13 system_ss.add(files('qom-hmp-cmds.c'))
qom/object.c
-60
@@ -480,66 +480,6 @@ bool object_apply_global_props(Object *obj, const GPtrArray *props,
480 return true;
481 }
482
483 -/*
484 - * Global property defaults
485 - * Slot 0: accelerator's global property defaults
486 - * Slot 1: machine's global property defaults
487 - * Slot 2: global properties from legacy command line option
488 - * Each is a GPtrArray of GlobalProperty.
489 - * Applied in order, later entries override earlier ones.
490 - */
491 -static GPtrArray *object_compat_props[3];
492 -
493 -/*
494 - * Retrieve @GPtrArray for global property defined with options
495 - * other than "-global". These are generally used for syntactic
496 - * sugar and legacy command line options.
497 - */
498 -void object_register_sugar_prop(const char *driver, const char *prop,
499 - const char *value, bool optional)
500 -{
501 - GlobalProperty *g;
502 - if (!object_compat_props[2]) {
503 - object_compat_props[2] = g_ptr_array_new();
504 - }
505 - g = g_new0(GlobalProperty, 1);
506 - g->driver = g_strdup(driver);
507 - g->property = g_strdup(prop);
508 - g->value = g_strdup(value);
509 - g->optional = optional;
510 - g_ptr_array_add(object_compat_props[2], g);
511 -}
512 -
513 -/*
514 - * Set machine's global property defaults to @compat_props.
515 - * May be called at most once.
516 - */
517 -void object_set_machine_compat_props(GPtrArray *compat_props)
518 -{
519 - assert(!object_compat_props[1]);
520 - object_compat_props[1] = compat_props;
521 -}
522 -
523 -/*
524 - * Set accelerator's global property defaults to @compat_props.
525 - * May be called at most once.
526 - */
527 -void object_set_accelerator_compat_props(GPtrArray *compat_props)
528 -{
529 - assert(!object_compat_props[0]);
530 - object_compat_props[0] = compat_props;
531 -}
532 -
533 -void object_apply_compat_props(Object *obj)
534 -{
535 - int i;
536 -
537 - for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) {
538 - object_apply_global_props(obj, object_compat_props[i],
539 - i == 2 ? &error_fatal : &error_abort);
540 - }
541 -}
542 -
483 static void object_class_property_init_all(Object *obj)
484 {
485 ObjectPropertyIterator iter;
stubs/meson.build
+1
@@ -54,6 +54,7 @@ if have_user
54 # Symbols that are used by hw/core.
55 stub_ss.add(files('cpu-synchronize-state.c'))
56 stub_ss.add(files('cpu-destroy-address-spaces.c'))
57 + stub_ss.add(files('qom-compat-properties.c'))
58
59 # Stubs for QAPI events. Those can always be included in the build, but
60 # they are not built at all for --disable-system builds.
stubs/qom-compat-properties.c new
+14
@@ -0,0 +1,14 @@
1 +/*
2 + * QEMU Object Model (compat properties stubs for user emulation)
3 + *
4 + * Copyright (c) Linaro
5 + *
6 + * SPDX-License-Identifier: GPL-2.0-or-later
7 + */
8 +
9 +#include "qemu/osdep.h"
10 +#include "qom/compat-properties.h"
11 +
12 +void object_apply_compat_props(Object *obj)
13 +{
14 +}