Instead of registering compat properties as globals, let's keep them
in their own array, to avoid mixing with user globals.
Introduce object_apply_global_props() function, to apply compatibility
properties from a GPtrArray.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/hw/qdev-core.h | 10 ++++++++++
include/qom/object.h | 3 +++
include/sysemu/accel.h | 4 +---
accel/accel.c | 12 ------------
hw/core/qdev.c | 9 +++++++++
hw/xen/xen-common.c | 9 ++++++---
qom/object.c | 25 +++++++++++++++++++++++++
vl.c | 1 -
8 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index a24d0dd566..aeaa6dbbb8 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -267,6 +267,16 @@ typedef struct GlobalProperty {
Error **errp;
} GlobalProperty;
+static inline void
+compat_props_add(GPtrArray *arr,
+ GlobalProperty props[], size_t nelem)
+{
+ int i;
+ for (i = 0; i < nelem; i++) {
+ g_ptr_array_add(arr, (void *)&props[i]);
+ }
+}
+
/*** Board API. This should go away once we have a machine config file. ***/
DeviceState *qdev_create(BusState *bus, const char *name);
diff --git a/include/qom/object.h b/include/qom/object.h
index 0139838b69..5183c587f3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -676,6 +676,9 @@ Object *object_new_with_propv(const char *typename,
Error **errp,
va_list vargs);
+void object_apply_global_props(Object *obj, const GPtrArray *props,
+ Error **errp);
+
/**
* object_set_props:
* @obj: the object instance to set properties on
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 637358f430..f331d128e9 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -49,7 +49,7 @@ typedef struct AccelClass {
* global properties may be overridden by machine-type
* compat_props or user-provided global properties.
*/
- GlobalProperty *global_props;
+ GPtrArray *compat_props;
} AccelClass;
#define TYPE_ACCEL "accel"
@@ -67,8 +67,6 @@ typedef struct AccelClass {
extern unsigned long tcg_tb_size;
void configure_accelerator(MachineState *ms);
-/* Register accelerator specific global properties */
-void accel_register_compat_props(AccelState *accel);
/* Called just before os_setup_post (ie just before drop OS privs) */
void accel_setup_post(MachineState *ms);
diff --git a/accel/accel.c b/accel/accel.c
index 3da26eb90f..6db5d8f4df 100644
--- a/accel/accel.c
+++ b/accel/accel.c
@@ -119,18 +119,6 @@ void configure_accelerator(MachineState *ms)
}
}
-void accel_register_compat_props(AccelState *accel)
-{
- AccelClass *class = ACCEL_GET_CLASS(accel);
- GlobalProperty *prop = class->global_props;
-
- for (; prop && prop->driver; prop++) {
- /* Any compat_props must never cause error */
- prop->errp = &error_abort;
- qdev_prop_register_global(prop);
- }
-}
-
void accel_setup_post(MachineState *ms)
{
AccelState *accel = ms->accelerator;
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 6b3cc55b27..53b507164f 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -972,6 +972,15 @@ static void device_initfn(Object *obj)
static void device_post_init(Object *obj)
{
+ if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+ MachineState *m = MACHINE(qdev_get_machine());
+ AccelClass *ac = ACCEL_GET_CLASS(m->accelerator);
+
+ if (ac->compat_props) {
+ object_apply_global_props(obj, ac->compat_props, &error_abort);
+ }
+ }
+
qdev_prop_set_globals(DEVICE(obj));
}
diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
index 6ec14c73ca..4532aa8632 100644
--- a/hw/xen/xen-common.c
+++ b/hw/xen/xen-common.c
@@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
.driver = "migration",
.property = "send-section-footer",
.value = "off",
- },
- { /* end of list */ },
+ }
};
static void xen_accel_class_init(ObjectClass *oc, void *data)
{
AccelClass *ac = ACCEL_CLASS(oc);
+
ac->name = "Xen";
ac->init_machine = xen_init;
ac->setup_post = xen_setup_post;
ac->allowed = &xen_allowed;
- ac->global_props = xen_compat_props;
+ ac->compat_props = g_ptr_array_new();
+
+ compat_props_add(ac->compat_props,
+ xen_compat_props, G_N_ELEMENTS(xen_compat_props));
}
#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
diff --git a/qom/object.c b/qom/object.c
index 17921c0a71..dbdab0aead 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
}
}
+void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
+{
+ Error *err = NULL;
+ int i;
+
+ if (!props) {
+ return;
+ }
+
+ for (i = 0; i < props->len; i++) {
+ GlobalProperty *p = g_ptr_array_index(props, i);
+
+ if (object_dynamic_cast(obj, p->driver) == NULL) {
+ continue;
+ }
+ p->used = true;
+ object_property_parse(obj, p->value, p->property, &err);
+ if (err != NULL) {
+ error_prepend(&err, "can't apply global %s.%s=%s: ",
+ p->driver, p->property, p->value);
+ error_propagate(errp, err);
+ }
+ }
+}
+
static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
{
Object *obj = data;
diff --git a/vl.c b/vl.c
index a5ae5f23d2..88ba658572 100644
--- a/vl.c
+++ b/vl.c
@@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
*/
static void register_global_properties(MachineState *ms)
{
- accel_register_compat_props(ms->accelerator);
machine_register_compat_props(ms);
user_register_global_props();
}
--
2.20.0.rc1
On Tue, 4 Dec 2018 18:20:11 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
> Instead of registering compat properties as globals, let's keep them
> in their own array, to avoid mixing with user globals.
>
> Introduce object_apply_global_props() function, to apply compatibility
> properties from a GPtrArray.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> include/hw/qdev-core.h | 10 ++++++++++
> include/qom/object.h | 3 +++
> include/sysemu/accel.h | 4 +---
> accel/accel.c | 12 ------------
> hw/core/qdev.c | 9 +++++++++
> hw/xen/xen-common.c | 9 ++++++---
> qom/object.c | 25 +++++++++++++++++++++++++
> vl.c | 1 -
> 8 files changed, 54 insertions(+), 19 deletions(-)
>
[...]
> diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
> index 6ec14c73ca..4532aa8632 100644
> --- a/hw/xen/xen-common.c
> +++ b/hw/xen/xen-common.c
> @@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
> .driver = "migration",
> .property = "send-section-footer",
> .value = "off",
> - },
> - { /* end of list */ },
> + }
> };
>
> static void xen_accel_class_init(ObjectClass *oc, void *data)
> {
> AccelClass *ac = ACCEL_CLASS(oc);
> +
> ac->name = "Xen";
> ac->init_machine = xen_init;
> ac->setup_post = xen_setup_post;
> ac->allowed = &xen_allowed;
> - ac->global_props = xen_compat_props;
> + ac->compat_props = g_ptr_array_new();
where is matching free for that?
> +
> + compat_props_add(ac->compat_props,
> + xen_compat_props, G_N_ELEMENTS(xen_compat_props));
> }
>
> #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> diff --git a/qom/object.c b/qom/object.c
> index 17921c0a71..dbdab0aead 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
> }
> }
>
> +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
> +{
> + Error *err = NULL;
> + int i;
> +
> + if (!props) {
> + return;
> + }
> +
> + for (i = 0; i < props->len; i++) {
> + GlobalProperty *p = g_ptr_array_index(props, i);
> +
> + if (object_dynamic_cast(obj, p->driver) == NULL) {
> + continue;
> + }
> + p->used = true;
> + object_property_parse(obj, p->value, p->property, &err);
> + if (err != NULL) {
> + error_prepend(&err, "can't apply global %s.%s=%s: ",
> + p->driver, p->property, p->value);
> + error_propagate(errp, err);
> + }
> + }
> +}
> +
> static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
> {
> Object *obj = data;
> diff --git a/vl.c b/vl.c
> index a5ae5f23d2..88ba658572 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
> */
> static void register_global_properties(MachineState *ms)
> {
> - accel_register_compat_props(ms->accelerator);
> machine_register_compat_props(ms);
> user_register_global_props();
> }
On Mon, 10 Dec 2018 17:45:22 +0100
Igor Mammedov <imammedo@redhat.com> wrote:
> On Tue, 4 Dec 2018 18:20:11 +0400
> Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
>
> > Instead of registering compat properties as globals, let's keep them
> > in their own array, to avoid mixing with user globals.
> >
> > Introduce object_apply_global_props() function, to apply compatibility
> > properties from a GPtrArray.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > include/hw/qdev-core.h | 10 ++++++++++
> > include/qom/object.h | 3 +++
> > include/sysemu/accel.h | 4 +---
> > accel/accel.c | 12 ------------
> > hw/core/qdev.c | 9 +++++++++
> > hw/xen/xen-common.c | 9 ++++++---
> > qom/object.c | 25 +++++++++++++++++++++++++
> > vl.c | 1 -
> > 8 files changed, 54 insertions(+), 19 deletions(-)
> >
> [...]
> > diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
> > index 6ec14c73ca..4532aa8632 100644
> > --- a/hw/xen/xen-common.c
> > +++ b/hw/xen/xen-common.c
> > @@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
> > .driver = "migration",
> > .property = "send-section-footer",
> > .value = "off",
> > - },
> > - { /* end of list */ },
> > + }
> > };
> >
> > static void xen_accel_class_init(ObjectClass *oc, void *data)
> > {
> > AccelClass *ac = ACCEL_CLASS(oc);
> > +
> > ac->name = "Xen";
> > ac->init_machine = xen_init;
> > ac->setup_post = xen_setup_post;
> > ac->allowed = &xen_allowed;
> > - ac->global_props = xen_compat_props;
> > + ac->compat_props = g_ptr_array_new();
> where is matching free for that?
can we at least annotate it somehow so that valgrind won't complain about this leak?
>
> > +
> > + compat_props_add(ac->compat_props,
> > + xen_compat_props, G_N_ELEMENTS(xen_compat_props));
> > }
> >
> > #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> > diff --git a/qom/object.c b/qom/object.c
> > index 17921c0a71..dbdab0aead 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
> > }
> > }
> >
> > +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
> > +{
> > + Error *err = NULL;
> > + int i;
> > +
> > + if (!props) {
> > + return;
> > + }
> > +
> > + for (i = 0; i < props->len; i++) {
> > + GlobalProperty *p = g_ptr_array_index(props, i);
> > +
> > + if (object_dynamic_cast(obj, p->driver) == NULL) {
> > + continue;
> > + }
> > + p->used = true;
> > + object_property_parse(obj, p->value, p->property, &err);
> > + if (err != NULL) {
> > + error_prepend(&err, "can't apply global %s.%s=%s: ",
> > + p->driver, p->property, p->value);
> > + error_propagate(errp, err);
> > + }
> > + }
> > +}
> > +
> > static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
> > {
> > Object *obj = data;
> > diff --git a/vl.c b/vl.c
> > index a5ae5f23d2..88ba658572 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
> > */
> > static void register_global_properties(MachineState *ms)
> > {
> > - accel_register_compat_props(ms->accelerator);
> > machine_register_compat_props(ms);
> > user_register_global_props();
> > }
>
>
Hi
On Mon, Dec 10, 2018 at 8:55 PM Igor Mammedov <imammedo@redhat.com> wrote:
>
> On Mon, 10 Dec 2018 17:45:22 +0100
> Igor Mammedov <imammedo@redhat.com> wrote:
>
> > On Tue, 4 Dec 2018 18:20:11 +0400
> > Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
> >
> > > Instead of registering compat properties as globals, let's keep them
> > > in their own array, to avoid mixing with user globals.
> > >
> > > Introduce object_apply_global_props() function, to apply compatibility
> > > properties from a GPtrArray.
> > >
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > > include/hw/qdev-core.h | 10 ++++++++++
> > > include/qom/object.h | 3 +++
> > > include/sysemu/accel.h | 4 +---
> > > accel/accel.c | 12 ------------
> > > hw/core/qdev.c | 9 +++++++++
> > > hw/xen/xen-common.c | 9 ++++++---
> > > qom/object.c | 25 +++++++++++++++++++++++++
> > > vl.c | 1 -
> > > 8 files changed, 54 insertions(+), 19 deletions(-)
> > >
> > [...]
> > > diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
> > > index 6ec14c73ca..4532aa8632 100644
> > > --- a/hw/xen/xen-common.c
> > > +++ b/hw/xen/xen-common.c
> > > @@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
> > > .driver = "migration",
> > > .property = "send-section-footer",
> > > .value = "off",
> > > - },
> > > - { /* end of list */ },
> > > + }
> > > };
> > >
> > > static void xen_accel_class_init(ObjectClass *oc, void *data)
> > > {
> > > AccelClass *ac = ACCEL_CLASS(oc);
> > > +
> > > ac->name = "Xen";
> > > ac->init_machine = xen_init;
> > > ac->setup_post = xen_setup_post;
> > > ac->allowed = &xen_allowed;
> > > - ac->global_props = xen_compat_props;
> > > + ac->compat_props = g_ptr_array_new();
> > where is matching free for that?
> can we at least annotate it somehow so that valgrind won't complain about this leak?
If you check my commits on qemu, you should see that I do care (too
much?) about leaks :)
In this case though, I don't see valgrind or asan complaining, I guess
it's still a reachable reference.
Do you think a FIXME comment would be helpful?
(/me wish we had a proper object system, GObject, but that ship as
long sailed..)
>
> >
> > > +
> > > + compat_props_add(ac->compat_props,
> > > + xen_compat_props, G_N_ELEMENTS(xen_compat_props));
> > > }
> > >
> > > #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> > > diff --git a/qom/object.c b/qom/object.c
> > > index 17921c0a71..dbdab0aead 100644
> > > --- a/qom/object.c
> > > +++ b/qom/object.c
> > > @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
> > > }
> > > }
> > >
> > > +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
> > > +{
> > > + Error *err = NULL;
> > > + int i;
> > > +
> > > + if (!props) {
> > > + return;
> > > + }
> > > +
> > > + for (i = 0; i < props->len; i++) {
> > > + GlobalProperty *p = g_ptr_array_index(props, i);
> > > +
> > > + if (object_dynamic_cast(obj, p->driver) == NULL) {
> > > + continue;
> > > + }
> > > + p->used = true;
> > > + object_property_parse(obj, p->value, p->property, &err);
> > > + if (err != NULL) {
> > > + error_prepend(&err, "can't apply global %s.%s=%s: ",
> > > + p->driver, p->property, p->value);
> > > + error_propagate(errp, err);
> > > + }
> > > + }
> > > +}
> > > +
> > > static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
> > > {
> > > Object *obj = data;
> > > diff --git a/vl.c b/vl.c
> > > index a5ae5f23d2..88ba658572 100644
> > > --- a/vl.c
> > > +++ b/vl.c
> > > @@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
> > > */
> > > static void register_global_properties(MachineState *ms)
> > > {
> > > - accel_register_compat_props(ms->accelerator);
> > > machine_register_compat_props(ms);
> > > user_register_global_props();
> > > }
> >
> >
>
>
--
Marc-André Lureau
On Wed, 12 Dec 2018 16:00:06 +0400
Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
> Hi
> On Mon, Dec 10, 2018 at 8:55 PM Igor Mammedov <imammedo@redhat.com> wrote:
> >
> > On Mon, 10 Dec 2018 17:45:22 +0100
> > Igor Mammedov <imammedo@redhat.com> wrote:
> >
> > > On Tue, 4 Dec 2018 18:20:11 +0400
> > > Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
> > >
> > > > Instead of registering compat properties as globals, let's keep them
> > > > in their own array, to avoid mixing with user globals.
> > > >
> > > > Introduce object_apply_global_props() function, to apply compatibility
> > > > properties from a GPtrArray.
> > > >
> > > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > > ---
> > > > include/hw/qdev-core.h | 10 ++++++++++
> > > > include/qom/object.h | 3 +++
> > > > include/sysemu/accel.h | 4 +---
> > > > accel/accel.c | 12 ------------
> > > > hw/core/qdev.c | 9 +++++++++
> > > > hw/xen/xen-common.c | 9 ++++++---
> > > > qom/object.c | 25 +++++++++++++++++++++++++
> > > > vl.c | 1 -
> > > > 8 files changed, 54 insertions(+), 19 deletions(-)
> > > >
> > > [...]
> > > > diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
> > > > index 6ec14c73ca..4532aa8632 100644
> > > > --- a/hw/xen/xen-common.c
> > > > +++ b/hw/xen/xen-common.c
> > > > @@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
> > > > .driver = "migration",
> > > > .property = "send-section-footer",
> > > > .value = "off",
> > > > - },
> > > > - { /* end of list */ },
> > > > + }
> > > > };
> > > >
> > > > static void xen_accel_class_init(ObjectClass *oc, void *data)
> > > > {
> > > > AccelClass *ac = ACCEL_CLASS(oc);
> > > > +
> > > > ac->name = "Xen";
> > > > ac->init_machine = xen_init;
> > > > ac->setup_post = xen_setup_post;
> > > > ac->allowed = &xen_allowed;
> > > > - ac->global_props = xen_compat_props;
> > > > + ac->compat_props = g_ptr_array_new();
> > > where is matching free for that?
> > can we at least annotate it somehow so that valgrind won't complain about this leak?
>
> If you check my commits on qemu, you should see that I do care (too
> much?) about leaks :)
>
> In this case though, I don't see valgrind or asan complaining, I guess
> it's still a reachable reference.
> Do you think a FIXME comment would be helpful?
I've looked at other cases were we leak, and well we leak a lot so it's
probably futile exercise. But the comment won't hurt and will work as remainder.
> (/me wish we had a proper object system, GObject, but that ship as
> long sailed..)
>
> >
> > >
> > > > +
> > > > + compat_props_add(ac->compat_props,
> > > > + xen_compat_props, G_N_ELEMENTS(xen_compat_props));
> > > > }
> > > >
> > > > #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> > > > diff --git a/qom/object.c b/qom/object.c
> > > > index 17921c0a71..dbdab0aead 100644
> > > > --- a/qom/object.c
> > > > +++ b/qom/object.c
> > > > @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
> > > > }
> > > > }
> > > >
> > > > +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
> > > > +{
> > > > + Error *err = NULL;
> > > > + int i;
> > > > +
> > > > + if (!props) {
> > > > + return;
> > > > + }
> > > > +
> > > > + for (i = 0; i < props->len; i++) {
> > > > + GlobalProperty *p = g_ptr_array_index(props, i);
> > > > +
> > > > + if (object_dynamic_cast(obj, p->driver) == NULL) {
> > > > + continue;
> > > > + }
> > > > + p->used = true;
> > > > + object_property_parse(obj, p->value, p->property, &err);
> > > > + if (err != NULL) {
> > > > + error_prepend(&err, "can't apply global %s.%s=%s: ",
> > > > + p->driver, p->property, p->value);
> > > > + error_propagate(errp, err);
> > > > + }
> > > > + }
> > > > +}
> > > > +
> > > > static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
> > > > {
> > > > Object *obj = data;
> > > > diff --git a/vl.c b/vl.c
> > > > index a5ae5f23d2..88ba658572 100644
> > > > --- a/vl.c
> > > > +++ b/vl.c
> > > > @@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
> > > > */
> > > > static void register_global_properties(MachineState *ms)
> > > > {
> > > > - accel_register_compat_props(ms->accelerator);
> > > > machine_register_compat_props(ms);
> > > > user_register_global_props();
> > > > }
> > >
> > >
> >
> >
>
>
On Tue, 4 Dec 2018 18:20:11 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
> Instead of registering compat properties as globals, let's keep them
> in their own array, to avoid mixing with user globals.
>
> Introduce object_apply_global_props() function, to apply compatibility
> properties from a GPtrArray.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
other than static leak looks fine, considering that we already
leak compat_props, it doesn't really matter, so:
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> include/hw/qdev-core.h | 10 ++++++++++
> include/qom/object.h | 3 +++
> include/sysemu/accel.h | 4 +---
> accel/accel.c | 12 ------------
> hw/core/qdev.c | 9 +++++++++
> hw/xen/xen-common.c | 9 ++++++---
> qom/object.c | 25 +++++++++++++++++++++++++
> vl.c | 1 -
> 8 files changed, 54 insertions(+), 19 deletions(-)
>
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index a24d0dd566..aeaa6dbbb8 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -267,6 +267,16 @@ typedef struct GlobalProperty {
> Error **errp;
> } GlobalProperty;
>
> +static inline void
> +compat_props_add(GPtrArray *arr,
> + GlobalProperty props[], size_t nelem)
> +{
> + int i;
> + for (i = 0; i < nelem; i++) {
> + g_ptr_array_add(arr, (void *)&props[i]);
> + }
> +}
> +
> /*** Board API. This should go away once we have a machine config file. ***/
>
> DeviceState *qdev_create(BusState *bus, const char *name);
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 0139838b69..5183c587f3 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -676,6 +676,9 @@ Object *object_new_with_propv(const char *typename,
> Error **errp,
> va_list vargs);
>
> +void object_apply_global_props(Object *obj, const GPtrArray *props,
> + Error **errp);
> +
> /**
> * object_set_props:
> * @obj: the object instance to set properties on
> diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
> index 637358f430..f331d128e9 100644
> --- a/include/sysemu/accel.h
> +++ b/include/sysemu/accel.h
> @@ -49,7 +49,7 @@ typedef struct AccelClass {
> * global properties may be overridden by machine-type
> * compat_props or user-provided global properties.
> */
> - GlobalProperty *global_props;
> + GPtrArray *compat_props;
> } AccelClass;
>
> #define TYPE_ACCEL "accel"
> @@ -67,8 +67,6 @@ typedef struct AccelClass {
> extern unsigned long tcg_tb_size;
>
> void configure_accelerator(MachineState *ms);
> -/* Register accelerator specific global properties */
> -void accel_register_compat_props(AccelState *accel);
> /* Called just before os_setup_post (ie just before drop OS privs) */
> void accel_setup_post(MachineState *ms);
>
> diff --git a/accel/accel.c b/accel/accel.c
> index 3da26eb90f..6db5d8f4df 100644
> --- a/accel/accel.c
> +++ b/accel/accel.c
> @@ -119,18 +119,6 @@ void configure_accelerator(MachineState *ms)
> }
> }
>
> -void accel_register_compat_props(AccelState *accel)
> -{
> - AccelClass *class = ACCEL_GET_CLASS(accel);
> - GlobalProperty *prop = class->global_props;
> -
> - for (; prop && prop->driver; prop++) {
> - /* Any compat_props must never cause error */
> - prop->errp = &error_abort;
> - qdev_prop_register_global(prop);
> - }
> -}
> -
> void accel_setup_post(MachineState *ms)
> {
> AccelState *accel = ms->accelerator;
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 6b3cc55b27..53b507164f 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -972,6 +972,15 @@ static void device_initfn(Object *obj)
>
> static void device_post_init(Object *obj)
> {
> + if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
> + MachineState *m = MACHINE(qdev_get_machine());
> + AccelClass *ac = ACCEL_GET_CLASS(m->accelerator);
> +
> + if (ac->compat_props) {
> + object_apply_global_props(obj, ac->compat_props, &error_abort);
> + }
> + }
> +
> qdev_prop_set_globals(DEVICE(obj));
> }
>
> diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c
> index 6ec14c73ca..4532aa8632 100644
> --- a/hw/xen/xen-common.c
> +++ b/hw/xen/xen-common.c
> @@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = {
> .driver = "migration",
> .property = "send-section-footer",
> .value = "off",
> - },
> - { /* end of list */ },
> + }
> };
>
> static void xen_accel_class_init(ObjectClass *oc, void *data)
> {
> AccelClass *ac = ACCEL_CLASS(oc);
> +
> ac->name = "Xen";
> ac->init_machine = xen_init;
> ac->setup_post = xen_setup_post;
> ac->allowed = &xen_allowed;
> - ac->global_props = xen_compat_props;
> + ac->compat_props = g_ptr_array_new();
> +
> + compat_props_add(ac->compat_props,
> + xen_compat_props, G_N_ELEMENTS(xen_compat_props));
> }
>
> #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> diff --git a/qom/object.c b/qom/object.c
> index 17921c0a71..dbdab0aead 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
> }
> }
>
> +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp)
> +{
> + Error *err = NULL;
> + int i;
> +
> + if (!props) {
> + return;
> + }
> +
> + for (i = 0; i < props->len; i++) {
> + GlobalProperty *p = g_ptr_array_index(props, i);
> +
> + if (object_dynamic_cast(obj, p->driver) == NULL) {
> + continue;
> + }
> + p->used = true;
> + object_property_parse(obj, p->value, p->property, &err);
> + if (err != NULL) {
> + error_prepend(&err, "can't apply global %s.%s=%s: ",
> + p->driver, p->property, p->value);
> + error_propagate(errp, err);
> + }
> + }
> +}
> +
> static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
> {
> Object *obj = data;
> diff --git a/vl.c b/vl.c
> index a5ae5f23d2..88ba658572 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2968,7 +2968,6 @@ static void user_register_global_props(void)
> */
> static void register_global_properties(MachineState *ms)
> {
> - accel_register_compat_props(ms->accelerator);
> machine_register_compat_props(ms);
> user_register_global_props();
> }
© 2016 - 2026 Red Hat, Inc.