[PATCH 2/4] qdev: Introduce helper object_apply_globals()

Peter Xu posted 4 patches 2 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>
[PATCH 2/4] qdev: Introduce helper object_apply_globals()
Posted by Peter Xu 2 months ago
The helper allows one object to apply anything from -global command lines
to an object.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/hw/core/qdev-properties.h | 1 +
 hw/core/qdev-properties.c         | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h
index eba5436e53..779acb31b6 100644
--- a/include/hw/core/qdev-properties.h
+++ b/include/hw/core/qdev-properties.h
@@ -268,6 +268,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
                                             const char *name);
 int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev);
+void object_apply_globals(Object *obj);
 void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
                                     const char *name, const char *value);
 
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 8f870c85fc..a91c2ad101 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev)
                               dev->hotplugged ? NULL : &error_fatal);
 }
 
+void object_apply_globals(Object *obj)
+{
+    object_apply_global_props(obj, global_props(), &error_fatal);
+}
+
 /* --- 64bit unsigned int 'size' type --- */
 
 static void get_size(Object *obj, Visitor *v, const char *name, void *opaque,
-- 
2.53.0
Re: [PATCH 2/4] qdev: Introduce helper object_apply_globals()
Posted by Daniel P. Berrangé 2 months ago
On Thu, Jun 04, 2026 at 07:11:16PM -0400, Peter Xu wrote:
> The helper allows one object to apply anything from -global command lines
> to an object.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  include/hw/core/qdev-properties.h | 1 +
>  hw/core/qdev-properties.c         | 5 +++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h
> index eba5436e53..779acb31b6 100644
> --- a/include/hw/core/qdev-properties.h
> +++ b/include/hw/core/qdev-properties.h
> @@ -268,6 +268,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
>                                              const char *name);
>  int qdev_prop_check_globals(void);
>  void qdev_prop_set_globals(DeviceState *dev);
> +void object_apply_globals(Object *obj);
>  void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
>                                      const char *name, const char *value);
>  
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 8f870c85fc..a91c2ad101 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev)
>                                dev->hotplugged ? NULL : &error_fatal);
>  }
>  
> +void object_apply_globals(Object *obj)
> +{
> +    object_apply_global_props(obj, global_props(), &error_fatal);
> +}

If a method has the "object_" prefix and takex "Object *" as its
instance, then it needs to live in qom/object.c / include/qom/object.h
but this again has the complexity of relying on the qdev Property
struct.  This is really mixing qdev & qom layers together which I
find pretty unpleasant.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Re: [PATCH 2/4] qdev: Introduce helper object_apply_globals()
Posted by Fabiano Rosas 2 months ago
Daniel P. Berrangé <berrange@redhat.com> writes:

> On Thu, Jun 04, 2026 at 07:11:16PM -0400, Peter Xu wrote:
>> The helper allows one object to apply anything from -global command lines
>> to an object.
>> 
>> Signed-off-by: Peter Xu <peterx@redhat.com>
>> ---
>>  include/hw/core/qdev-properties.h | 1 +
>>  hw/core/qdev-properties.c         | 5 +++++
>>  2 files changed, 6 insertions(+)
>> 
>> diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h
>> index eba5436e53..779acb31b6 100644
>> --- a/include/hw/core/qdev-properties.h
>> +++ b/include/hw/core/qdev-properties.h
>> @@ -268,6 +268,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
>>                                              const char *name);
>>  int qdev_prop_check_globals(void);
>>  void qdev_prop_set_globals(DeviceState *dev);
>> +void object_apply_globals(Object *obj);
>>  void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
>>                                      const char *name, const char *value);
>>  
>> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
>> index 8f870c85fc..a91c2ad101 100644
>> --- a/hw/core/qdev-properties.c
>> +++ b/hw/core/qdev-properties.c
>> @@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev)
>>                                dev->hotplugged ? NULL : &error_fatal);
>>  }
>>  
>> +void object_apply_globals(Object *obj)
>> +{
>> +    object_apply_global_props(obj, global_props(), &error_fatal);
>> +}
>
> If a method has the "object_" prefix and takex "Object *" as its
> instance, then it needs to live in qom/object.c / include/qom/object.h
> but this again has the complexity of relying on the qdev Property
> struct.  This is really mixing qdev & qom layers together which I
> find pretty unpleasant.
>

True, but code like qdev_property_add_static() already mixes things up
quite a bit. Not that this is justification to mix it even more, of
course.

> With regards,
> Daniel
Re: [PATCH 2/4] qdev: Introduce helper object_apply_globals()
Posted by Daniel P. Berrangé 2 months ago
On Fri, Jun 05, 2026 at 11:44:47AM -0300, Fabiano Rosas wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> 
> > On Thu, Jun 04, 2026 at 07:11:16PM -0400, Peter Xu wrote:
> >> The helper allows one object to apply anything from -global command lines
> >> to an object.
> >> 
> >> Signed-off-by: Peter Xu <peterx@redhat.com>
> >> ---
> >>  include/hw/core/qdev-properties.h | 1 +
> >>  hw/core/qdev-properties.c         | 5 +++++
> >>  2 files changed, 6 insertions(+)
> >> 
> >> diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h
> >> index eba5436e53..779acb31b6 100644
> >> --- a/include/hw/core/qdev-properties.h
> >> +++ b/include/hw/core/qdev-properties.h
> >> @@ -268,6 +268,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
> >>                                              const char *name);
> >>  int qdev_prop_check_globals(void);
> >>  void qdev_prop_set_globals(DeviceState *dev);
> >> +void object_apply_globals(Object *obj);
> >>  void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
> >>                                      const char *name, const char *value);
> >>  
> >> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> >> index 8f870c85fc..a91c2ad101 100644
> >> --- a/hw/core/qdev-properties.c
> >> +++ b/hw/core/qdev-properties.c
> >> @@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev)
> >>                                dev->hotplugged ? NULL : &error_fatal);
> >>  }
> >>  
> >> +void object_apply_globals(Object *obj)
> >> +{
> >> +    object_apply_global_props(obj, global_props(), &error_fatal);
> >> +}
> >
> > If a method has the "object_" prefix and takex "Object *" as its
> > instance, then it needs to live in qom/object.c / include/qom/object.h
> > but this again has the complexity of relying on the qdev Property
> > struct.  This is really mixing qdev & qom layers together which I
> > find pretty unpleasant.
> >
> 
> True, but code like qdev_property_add_static() already mixes things up
> quite a bit. Not that this is justification to mix it even more, of
> course.

That's not the same scenario as it is exclusively qdev code, using
qdev_ name prefix and taking "Device *" not "Object *".

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|


Re: [PATCH 2/4] qdev: Introduce helper object_apply_globals()
Posted by Fabiano Rosas 2 months ago
Daniel P. Berrangé <berrange@redhat.com> writes:

> On Fri, Jun 05, 2026 at 11:44:47AM -0300, Fabiano Rosas wrote:
>> Daniel P. Berrangé <berrange@redhat.com> writes:
>> 
>> > On Thu, Jun 04, 2026 at 07:11:16PM -0400, Peter Xu wrote:
>> >> The helper allows one object to apply anything from -global command lines
>> >> to an object.
>> >> 
>> >> Signed-off-by: Peter Xu <peterx@redhat.com>
>> >> ---
>> >>  include/hw/core/qdev-properties.h | 1 +
>> >>  hw/core/qdev-properties.c         | 5 +++++
>> >>  2 files changed, 6 insertions(+)
>> >> 
>> >> diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h
>> >> index eba5436e53..779acb31b6 100644
>> >> --- a/include/hw/core/qdev-properties.h
>> >> +++ b/include/hw/core/qdev-properties.h
>> >> @@ -268,6 +268,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
>> >>                                              const char *name);
>> >>  int qdev_prop_check_globals(void);
>> >>  void qdev_prop_set_globals(DeviceState *dev);
>> >> +void object_apply_globals(Object *obj);
>> >>  void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
>> >>                                      const char *name, const char *value);
>> >>  
>> >> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
>> >> index 8f870c85fc..a91c2ad101 100644
>> >> --- a/hw/core/qdev-properties.c
>> >> +++ b/hw/core/qdev-properties.c
>> >> @@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev)
>> >>                                dev->hotplugged ? NULL : &error_fatal);
>> >>  }
>> >>  
>> >> +void object_apply_globals(Object *obj)
>> >> +{
>> >> +    object_apply_global_props(obj, global_props(), &error_fatal);
>> >> +}
>> >
>> > If a method has the "object_" prefix and takex "Object *" as its
>> > instance, then it needs to live in qom/object.c / include/qom/object.h
>> > but this again has the complexity of relying on the qdev Property
>> > struct.  This is really mixing qdev & qom layers together which I
>> > find pretty unpleasant.
>> >
>> 
>> True, but code like qdev_property_add_static() already mixes things up
>> quite a bit. Not that this is justification to mix it even more, of
>> course.
>
> That's not the same scenario as it is exclusively qdev code, using
> qdev_ name prefix and taking "Device *" not "Object *".
>

Reading your message again, I misinterpreted you as arguing against the
overall coupling of ObjectProperty and Property. I agree with the
specific point of the abstraction layers.

> With regards,
> Daniel