migration/qdev: Remove TYPE_DEVICE dependency on migration object
cover migration/qdev: Remove TYPE_DEVICE dependency on migration object
CI: https://gitlab.com/peterx/qemu/-/pipelines/2577688365
This is v1 of the series, rfc can be found here:
https://lore.kernel.org/r/[email protected]
I got no positive feedback on OBJECT_COMPAT in rfc, so I dropped it.
This v1 removed all OBJECT_COMPAT patches, instead migration object will stick with custom instance_post_init() to apply compat / global properties.
The goal of this series is to remove TYPE_DEVICE dependency for migration object. As a side effect, making qdev-properties available to all objects not only qdev.
After this series, other TYPE_OBJECT can also leverage qdev properties. Quite a few features I liked:
- simple declaration on setter/getter/defaults, objects can define, e.g.,
Property prop = DEFINE_PROP_UINT32(...);
Then in its class_init(), do:
object_class_add_property(klass, &prop);
- support compat properties, and one more line to support -globals
Two things I intentionally didn't do:
- Go further to remove qdev properties dependency for migration object. In that case I will need to implement most of the qdev property logic separately, duplicating code.
- Go further to make qdev-properties to be some generic object-properties concept. Logically we can do that but the rename all over the places will be a huge diffstat. I don't want this simple and straightforward change to be buried inside. So I hope (1) either it's not urgently needed, then we can so far stick with calling it qdev-properties (say, if we try grep qdev under qom/ we still get something.. so it's not like we're 100% cleared out on that..), or (2) at least it can be done separately as a separate goal.
Comments welcomed, thanks.
Peter Xu (4):
qdev: Pave way for exporting Property to be used in non-qdev
qdev: Introduce helper object_apply_globals()
qdev: Refactor and rename of qdev_class_add_property()
migration: Remove dependency to TYPE_DEVICE
include/hw/core/qdev-properties.h | 11 +++++++++ migration/migration.h | 2 +- hw/core/qdev-properties.c | 36 ++++++++++++++++++++++------- migration/migration.c | 33 +++++++++++++++----------- tests/unit/test-qdev-global-props.c | 6 ++++- 5 files changed, 64 insertions(+), 24 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/4 qdev: Pave way for exporting Property to be used in non-qdev
Property itself is a well defined interface to either support smooth conversions to Object's properties, or supports global properties. However currently it's tied to DeviceClass, aka, qdev. So non-qdev cannot use Property list.
My current observation shows Property is almost ready to be used as a separated exported interface, except two small things that may need touch up internally:
qdev_prop_allow_set
qdev_prop_check_globals
The 1st one currently checks against realize state (which is part of qdev attributes only). The 2nd one checks for all global property being used in all non-pluggable qdevs.
We can loose the check in both spots, keep the check if the driver is a qdev, otherwise we can safely whitelist non-qdev use cases of Property.
--- hw/core/qdev-properties.c | 24 ++++++++++++++++++++---- tests/unit/test-qdev-global-props.c | 6 +++++- 2 files changed, 25 insertions(+), 5 deletions(-)
hw/core/qdev-properties.c +20 -4
@@ -31,8 +31,14 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,static bool qdev_prop_allow_set (Object *obj,const char *name,const PropertyInfo *info,Error **errp) { -DeviceState *dev =DEVICE (obj); +DeviceState *dev; + +if (!object_dynamic_cast (obj,TYPE_DEVICE )) { +/* Currently, non-qdev can always set Property anytime */ +return true; + } + dev =DEVICE (obj);if (dev->realized && !info->realized_set_allowed) {qdev_prop_set_after_realize (dev, name, errp);return false;
@@ -997,6 +1003,7 @@ int qdev_prop_check_globals(void)for (i =0 ; i <global_props ()->len; i++) {GlobalProperty *prop; +bool hotpluggable;ObjectClass *oc;DeviceClass *dc;
@@ -1005,15 +1012,24 @@ int qdev_prop_check_globals(void)continue ; } oc =object_class_by_name (prop->driver); - oc =object_class_dynamic_cast (oc,TYPE_DEVICE );if (!oc) {warn_report ("global %s.%s has invalid class name" , prop->driver, prop->property); ret =1 ;continue ; } - dc =DEVICE_CLASS (oc); -if (!dc->hotpluggable && !prop->used) { + oc =object_class_dynamic_cast (oc,TYPE_DEVICE ); +if (oc) { + dc =DEVICE_CLASS (oc); + hotpluggable = dc->hotpluggable; + }else { +/* +* Currently, to be strict to assume all non-qdev are not +* hotpluggable (whoever will use -global). +*/ + hotpluggable = false; + } +if (!hotpluggable && !prop->used) {warn_report ("global %s.%s=%s not used" , prop->driver, prop->property, prop->value); ret =1 ;
tests/unit/test-qdev-global-props.c +5 -1
@@ -275,8 +275,12 @@ static void test_dynamic_globalprop(void)g_test_trap_assert_stderr_unmatched ("*prop4*" );g_test_trap_assert_stderr ("*warning: global nohotplug-type.prop5=105 not used*" ); +/* +* TYPE_OBJECT can opt-in for global properties, so the error is "not +* used" too for nondevice-type. +*/ g_test_trap_assert_stderr ( -"*warning: global nondevice-type.prop6 has invalid class name*" ); +"*warning: global nondevice-type.prop6=106 not used*" );g_test_trap_assert_stdout ("" ); }
Signature · 1 line
2.53.0
Re: [PATCH 1/4] qdev: Pave way for exporting Property to be used in non-qdev
Quoted 4 lines · Peter Xu
Property itself is a well defined interface to either support smooth conversions to Object's properties, or supports global properties. However currently it's tied to DeviceClass, aka, qdev. So non-qdev cannot use Property list.
That's indeed because Property is a qdev-only concept.
Quoted 7 lines
My current observation shows Property is almost ready to be used as a separated exported interface, except two small things that may need touch up internally:
qdev_prop_allow_set
qdev_prop_check_globals
Quoted 6 lines
The 1st one currently checks against realize state (which is part of qdev attributes only). The 2nd one checks for all global property being used in all non-pluggable qdevs.
We can loose the check in both spots, keep the check if the driver is a qdev, otherwise we can safely whitelist non-qdev use cases of Property.
I'm really not sure this is the right approach: surely you would want to flip this on its head so that -global makes use of the underlying QOM APIs instead of qdev APIs?
Quoted 69 lines
Signed-off-by Peter Xu <[email protected]>--- hw/core/qdev-properties.c | 24 ++++++++++++++++++++---- tests/unit/test-qdev-global-props.c | 6 +++++- 2 files changed, 25 insertions(+), 5 deletions(-)hw/core/qdev-properties.c +20
-4@@ -31,8 +31,14 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,static bool qdev_prop_allow_set (Object *obj,const char *name,const PropertyInfo *info,Error **errp) { -DeviceState *dev =DEVICE (obj); +DeviceState *dev; + +if (!object_dynamic_cast (obj,TYPE_DEVICE )) { +/* Currently, non-qdev can always set Property anytime */ +return true; + } + dev =DEVICE (obj);if (dev->realized && !info->realized_set_allowed) {qdev_prop_set_after_realize (dev, name, errp);return false;@@ -997,6 +1003,7 @@ int qdev_prop_check_globals(void)for (i =0 ; i <global_props ()->len; i++) {GlobalProperty *prop; +bool hotpluggable;ObjectClass *oc;DeviceClass *dc;@@ -1005,15 +1012,24 @@ int qdev_prop_check_globals(void)continue ; } oc =object_class_by_name (prop->driver); - oc =object_class_dynamic_cast (oc,TYPE_DEVICE );if (!oc) {warn_report ("global %s.%s has invalid class name" , prop->driver, prop->property); ret =1 ;continue ; } - dc =DEVICE_CLASS (oc); -if (!dc->hotpluggable && !prop->used) { + oc =object_class_dynamic_cast (oc,TYPE_DEVICE ); +if (oc) { + dc =DEVICE_CLASS (oc); + hotpluggable = dc->hotpluggable; + }else { +/* +* Currently, to be strict to assume all non-qdev are not +* hotpluggable (whoever will use -global). +*/ + hotpluggable = false; + } +if (!hotpluggable && !prop->used) {warn_report ("global %s.%s=%s not used" , prop->driver, prop->property, prop->value); ret =1 ;tests/unit/test-qdev-global-props.c +0
-0@@ -275,8 +275,12 @@ static void test_dynamic_globalprop(void)g_test_trap_assert_stderr_unmatched ("*prop4*" ); g_test_trap_assert_stderr(
tests/unit/test-qdev-global-props.c static void test_dynamic_globalprop(void) · line 285
Quoted 10 lines
tests/unit/test-qdev-global-props.c +5
-1"*warning: global nohotplug-type.prop5=105 not used*"); +/* +* TYPE_OBJECT can opt-in for global properties, so the error is "not +* used" too for nondevice-type. +*/ g_test_trap_assert_stderr ( -"*warning: global nondevice-type.prop6 has invalid class name*" ); +"*warning: global nondevice-type.prop6=106 not used*" );g_test_trap_assert_stdout ("" ); }
ATB,
Mark.
Re: [PATCH 1/4] qdev: Pave way for exporting Property to be used in non-qdev
Quoted 20 lines · Mark Cave-Ayland
Quoted 4 lines · Peter Xu
Property itself is a well defined interface to either support smooth conversions to Object's properties, or supports global properties. However currently it's tied to DeviceClass, aka, qdev. So non-qdev cannot use Property list.
That's indeed because Property is a qdev-only concept.
Quoted 11 lines
My current observation shows Property is almost ready to be used as a separated exported interface, except two small things that may need touch up internally:
qdev_prop_allow_set
qdev_prop_check_globalsThe 1st one currently checks against realize state (which is part of qdev attributes only). The 2nd one checks for all global property being used in all non-pluggable qdevs.
Quoted 7 lines
Quoted 2 lines
We can loose the check in both spots, keep the check if the driver is a qdev, otherwise we can safely whitelist non-qdev use cases of Property.
I'm really not sure this is the right approach: surely you would want to flip this on its head so that -global makes use of the underlying QOM APIs instead of qdev APIs?
That's a good point. It seems we could do the same as qdev does without having to use the Property directly. It creates some awkwardness with the setting of defaults, but it's probably quite doable.
Quoted 84 lines
Quoted 69 lines
Signed-off-by Peter Xu <[email protected]>--- hw/core/qdev-properties.c | 24 ++++++++++++++++++++---- tests/unit/test-qdev-global-props.c | 6 +++++- 2 files changed, 25 insertions(+), 5 deletions(-)hw/core/qdev-properties.c +20
-4@@ -31,8 +31,14 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,static bool qdev_prop_allow_set (Object *obj,const char *name,const PropertyInfo *info,Error **errp) { -DeviceState *dev =DEVICE (obj); +DeviceState *dev; + +if (!object_dynamic_cast (obj,TYPE_DEVICE )) { +/* Currently, non-qdev can always set Property anytime */ +return true; + } + dev =DEVICE (obj);if (dev->realized && !info->realized_set_allowed) {qdev_prop_set_after_realize (dev, name, errp);return false;@@ -997,6 +1003,7 @@ int qdev_prop_check_globals(void)for (i =0 ; i <global_props ()->len; i++) {GlobalProperty *prop; +bool hotpluggable;ObjectClass *oc;DeviceClass *dc;@@ -1005,15 +1012,24 @@ int qdev_prop_check_globals(void)continue ; } oc =object_class_by_name (prop->driver); - oc =object_class_dynamic_cast (oc,TYPE_DEVICE );if (!oc) {warn_report ("global %s.%s has invalid class name" , prop->driver, prop->property); ret =1 ;continue ; } - dc =DEVICE_CLASS (oc); -if (!dc->hotpluggable && !prop->used) { + oc =object_class_dynamic_cast (oc,TYPE_DEVICE ); +if (oc) { + dc =DEVICE_CLASS (oc); + hotpluggable = dc->hotpluggable; + }else { +/* +* Currently, to be strict to assume all non-qdev are not +* hotpluggable (whoever will use -global). +*/ + hotpluggable = false; + } +if (!hotpluggable && !prop->used) {warn_report ("global %s.%s=%s not used" , prop->driver, prop->property, prop->value); ret =1 ;tests/unit/test-qdev-global-props.c +0
-0@@ -275,8 +275,12 @@ static void test_dynamic_globalprop(void)g_test_trap_assert_stderr_unmatched ("*prop4*" ); g_test_trap_assert_stderr(tests/unit/test-qdev-global-props.c static void test_dynamic_globalprop(void) · line 285
Quoted 10 lines
tests/unit/test-qdev-global-props.c +5
-1"*warning: global nohotplug-type.prop5=105 not used*"); +/* +* TYPE_OBJECT can opt-in for global properties, so the error is "not +* used" too for nondevice-type. +*/ g_test_trap_assert_stderr ( -"*warning: global nondevice-type.prop6 has invalid class name*" ); +"*warning: global nondevice-type.prop6=106 not used*" );g_test_trap_assert_stdout ("" ); }ATB,
Mark.
Re: [PATCH 1/4] qdev: Pave way for exporting Property to be used in non-qdev
In reply to Peter XuQuoted 10 lines · Peter Xu
Property itself is a well defined interface to either support smooth conversions to Object's properties, or supports global properties. However currently it's tied to DeviceClass, aka, qdev. So non-qdev cannot use Property list.
My current observation shows Property is almost ready to be used as a separated exported interface, except two small things that may need touch up internally:
qdev_prop_allow_set
Just a thought, we could use something like this to block update of migration parameters during migration runtime.
Quoted 88 lines
qdev_prop_check_globalsThe 1st one currently checks against realize state (which is part of qdev attributes only). The 2nd one checks for all global property being used in all non-pluggable qdevs.
We can loose the check in both spots, keep the check if the driver is a qdev, otherwise we can safely whitelist non-qdev use cases of Property.
Signed-off-by Peter Xu <[email protected]>--- hw/core/qdev-properties.c | 24 ++++++++++++++++++++---- tests/unit/test-qdev-global-props.c | 6 +++++- 2 files changed, 25 insertions(+), 5 deletions(-)hw/core/qdev-properties.c +20
-4@@ -31,8 +31,14 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,static bool qdev_prop_allow_set (Object *obj,const char *name,const PropertyInfo *info,Error **errp) { -DeviceState *dev =DEVICE (obj); +DeviceState *dev; + +if (!object_dynamic_cast (obj,TYPE_DEVICE )) { +/* Currently, non-qdev can always set Property anytime */ +return true; + } + dev =DEVICE (obj);if (dev->realized && !info->realized_set_allowed) {qdev_prop_set_after_realize (dev, name, errp);return false;@@ -997,6 +1003,7 @@ int qdev_prop_check_globals(void)for (i =0 ; i <global_props ()->len; i++) {GlobalProperty *prop; +bool hotpluggable;ObjectClass *oc;DeviceClass *dc;@@ -1005,15 +1012,24 @@ int qdev_prop_check_globals(void)continue ; } oc =object_class_by_name (prop->driver); - oc =object_class_dynamic_cast (oc,TYPE_DEVICE );if (!oc) {warn_report ("global %s.%s has invalid class name" , prop->driver, prop->property); ret =1 ;continue ; } - dc =DEVICE_CLASS (oc); -if (!dc->hotpluggable && !prop->used) { + oc =object_class_dynamic_cast (oc,TYPE_DEVICE ); +if (oc) { + dc =DEVICE_CLASS (oc); + hotpluggable = dc->hotpluggable; + }else { +/* +* Currently, to be strict to assume all non-qdev are not +* hotpluggable (whoever will use -global). +*/ + hotpluggable = false; + } +if (!hotpluggable && !prop->used) {warn_report ("global %s.%s=%s not used" , prop->driver, prop->property, prop->value); ret =1 ;tests/unit/test-qdev-global-props.c +5
-1@@ -275,8 +275,12 @@ static void test_dynamic_globalprop(void)g_test_trap_assert_stderr_unmatched ("*prop4*" );g_test_trap_assert_stderr ("*warning: global nohotplug-type.prop5=105 not used*" ); +/* +* TYPE_OBJECT can opt-in for global properties, so the error is "not +* used" too for nondevice-type. +*/ g_test_trap_assert_stderr ( -"*warning: global nondevice-type.prop6 has invalid class name*" ); +"*warning: global nondevice-type.prop6=106 not used*" );g_test_trap_assert_stdout ("" ); }
Re: [PATCH 1/4] qdev: Pave way for exporting Property to be used in non-qdev
Quoted 7 lines · Fabiano Rosas
Quoted 5 lines · Peter Xu
Property itself is a well defined interface to either support smooth conversions to Object's properties, or supports global properties. However currently it's tied to DeviceClass, aka, qdev. So non-qdev cannot use Property list.
Quoted 8 lines
Quoted 5 lines
My current observation shows Property is almost ready to be used as a separated exported interface, except two small things that may need touch up internally:
qdev_prop_allow_setJust a thought, we could use something like this to block update of migration parameters during migration runtime.
Currently it may not achieve it (with qdev property or object property that I'm trying), it's because qmp set parameters currently bypasses qom properties.
We need to switch QMP set parameters to use qom set to achieve it, but yes, that sounds like something good to consider in the future to merge the two paths somehow.
If we use helpers like object_property_add_uint64_ptr() we save lines but lose control over setter() blocking updates during live migration. If we use raw object_property_add() we get control but adds boilerplate lines.
Anyway, sounds like something for the future..
Signature · 1 line
Peter Xu
PATCH 2/4 qdev: Introduce helper object_apply_globals()
In reply to Peter XuThe helper allows one object to apply anything from -global command lines to an object.
--- include/hw/core/qdev-properties.h | 1 + hw/core/qdev-properties.c | 5 +++++ 2 files changed, 6 insertions(+)
include/hw/core/qdev-properties.h +1 -0
@@ -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);
hw/core/qdev-properties.c +5 -0
@@ -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,
Signature · 1 line
2.53.0
Re: [PATCH 2/4] qdev: Introduce helper object_apply_globals()
Quoted 26 lines · Peter Xu
The helper allows one object to apply anything from -global command lines to an object.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 1 + hw/core/qdev-properties.c | 5 +++++ 2 files changed, 6 insertions(+)include/hw/core/qdev-properties.h +1
-0@@ -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);hw/core/qdev-properties.c +0
-0
hw/core/qdev-properties.c void qdev_prop_set_globals(DeviceState *dev) · line 1051
Quoted 7 lines
hw/core/qdev-properties.c +4
-0@@ -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
Signature · 3 lines
|: 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()
Quoted 30 lines · Daniel P. Berrangé
Quoted 29 lines · Peter Xu
The helper allows one object to apply anything from -global command lines to an object.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 1 + hw/core/qdev-properties.c | 5 +++++ 2 files changed, 6 insertions(+)include/hw/core/qdev-properties.h +1
-0@@ -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);hw/core/qdev-properties.c +0
-0@@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev) dev->hotplugged ? NULL : &error_fatal); }
Quoted 11 lines
hw/core/qdev-properties.c void qdev_prop_set_globals(DeviceState *dev) · line 1051
Quoted 4 lines
hw/core/qdev-properties.c +4
-0+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 inqom/object.c/include/qom/object.hbut 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.
Quoted 2 lines
With regards,
Daniel
Re: [PATCH 2/4] qdev: Introduce helper object_apply_globals()
Quoted 44 lines · Fabiano Rosas
Quoted 30 lines · Daniel P. Berrangé
Quoted 29 lines · Peter Xu
The helper allows one object to apply anything from -global command lines to an object.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 1 + hw/core/qdev-properties.c | 5 +++++ 2 files changed, 6 insertions(+)include/hw/core/qdev-properties.h +1
-0@@ -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);hw/core/qdev-properties.c +0
-0@@ -1045,6 +1045,11 @@ void qdev_prop_set_globals(DeviceState *dev) dev->hotplugged ? NULL : &error_fatal); }Quoted 11 lines
hw/core/qdev-properties.c void qdev_prop_set_globals(DeviceState *dev) · line 1051
Quoted 4 lines
hw/core/qdev-properties.c +4
-0+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 inqom/object.c/include/qom/object.hbut 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.
Quoted 3 lines
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
Signature · 3 lines
|: 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()
Quoted 45 lines · Daniel P. Berrangé
Quoted 44 lines · Fabiano Rosas
Quoted 41 lines · Daniel P. Berrangé
Quoted 26 lines · Peter Xu
The helper allows one object to apply anything from -global command lines to an object.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 1 + hw/core/qdev-properties.c | 5 +++++ 2 files changed, 6 insertions(+)include/hw/core/qdev-properties.h +1
-0@@ -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);hw/core/qdev-properties.c +0
-0hw/core/qdev-properties.c void qdev_prop_set_globals(DeviceState *dev) · line 1051
Quoted 7 lines
hw/core/qdev-properties.c +4
-0@@ -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 inqom/object.c/include/qom/object.hbut 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.
Quoted 7 lines
Quoted 3 lines
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.
Quoted 2 lines
With regards,
Daniel
PATCH 3/4 qdev: Refactor and rename of qdev_class_add_property()
In reply to Peter XuFirstly, qdev_class_add_property() function almost has nothing to do with DeviceClass, it's a bridge between Property and object properties.
Change the 1st parameter of it, so that it can be used without DeviceClass context at all. When at it, remove the "name" field because it's always prop->name.
Export it for non-qdev use cases.
--- include/hw/core/qdev-properties.h | 10 ++++++++++ hw/core/qdev-properties.c | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-)
include/hw/core/qdev-properties.h +10 -0
@@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,*/ void qdev_property_add_static (DeviceState *dev,const Property *prop); +/** +* object_class_add_property: +* @oc: Object class to operate on. +* @prop: The qdev property definition. +* +* Add a Property to @oc. This is the bridge to convert a Property into +* an object class property (as in ObjectClass.properties). +*/ +void object_class_add_property (ObjectClass *oc,const Property *prop); +/** * qdev_alias_all_properties: Create aliases on source for all target properties * @target: Device which has properties to be aliased
hw/core/qdev-properties.c +3 -4
@@ -1188,10 +1188,9 @@ void qdev_property_add_static(DeviceState *dev, const Property *prop) } } -static void qdev_class_add_property (DeviceClass *klass,const char *name, -const Property *prop) +void object_class_add_property (ObjectClass *oc,const Property *prop) { -ObjectClass *oc =OBJECT_CLASS (klass); +const char *name = prop->name;ObjectProperty *op;if (prop->info->create) {
@@ -1222,7 +1221,7 @@ void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n)for (size_t i =0 ; i < n; ++i) {const Property *prop = &props[i];assert (prop->name); -qdev_class_add_property (dc, prop->name, prop); +object_class_add_property (OBJECT_CLASS (dc), prop); } }
Signature · 1 line
2.53.0
Re: [PATCH 3/4] qdev: Refactor and rename of qdev_class_add_property()
Quoted 22 lines · Peter Xu
Firstly,
qdev_class_add_property()function almost has nothing to do with DeviceClass, it's a bridge between Property and object properties.Change the 1st parameter of it, so that it can be used without DeviceClass context at all. When at it, remove the "name" field because it's always
prop->name.Export it for non-qdev use cases.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 10 ++++++++++ hw/core/qdev-properties.c | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-)include/hw/core/qdev-properties.h +0
-0@@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,*/ void qdev_property_add_static (DeviceState *dev,const Property *prop);
include/hw/core/qdev-properties.h void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, · line 294
Quoted 10 lines
include/hw/core/qdev-properties.h +9
-0+/** +* object_class_add_property: +* @oc: Object class to operate on. +* @prop: The qdev property definition. +* +* Add a Property to @oc. This is the bridge to convert a Property into +* an object class property (as in ObjectClass.properties). +*/ +void object_class_add_property (ObjectClass *oc,const Property *prop);
I'm really not a fan of this.
Having both object_class_add_property and object_class_property_add methods is horrendous naming.
Methods named with an "object_class_" prefix must live in qom/object.c & include/qom/object.h not in qdev. If doing that though, then the entire "Property" concept would need to live in QOM code too, but I don't think that is either desirable or neccessary.
AFAICT, the MigrationState class init method could just call the existing object_class_property_add methods as any other non-qdev Object impl does.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH 3/4] qdev: Refactor and rename of qdev_class_add_property()
Quoted 39 lines · Daniel P. Berrangé
Quoted 22 lines · Peter Xu
Firstly,
qdev_class_add_property()function almost has nothing to do with DeviceClass, it's a bridge between Property and object properties.Change the 1st parameter of it, so that it can be used without DeviceClass context at all. When at it, remove the "name" field because it's always
prop->name.Export it for non-qdev use cases.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 10 ++++++++++ hw/core/qdev-properties.c | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-)include/hw/core/qdev-properties.h +0
-0@@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,*/ void qdev_property_add_static (DeviceState *dev,const Property *prop);include/hw/core/qdev-properties.h void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, · line 294
Quoted 10 lines
include/hw/core/qdev-properties.h +9
-0+/** +* object_class_add_property: +* @oc: Object class to operate on. +* @prop: The qdev property definition. +* +* Add a Property to @oc. This is the bridge to convert a Property into +* an object class property (as in ObjectClass.properties). +*/ +void object_class_add_property (ObjectClass *oc,const Property *prop);I'm really not a fan of this.
Having both
object_class_add_propertyandobject_class_property_addmethods is horrendous naming.
Quoted 8 lines
Methods named with an "
object_class_" prefix must live inqom/object.c&include/qom/object.hnot in qdev. If doing that though, then the entire "Property" concept would need to live in QOM code too, but I don't think that is either desirable or neccessary.AFAICT, the MigrationState class init method could just call the existing
object_class_property_addmethods as any other non-qdev Object impl does.
I think I somehow missed the fact that qom does actually support setters/getters for some default types too.. with default val API:
object_property_add_uint64_ptr()object_property_set_default_uint()
...
I'll give it a shot.
Signature · 1 line
Peter Xu
PATCH 4/4 migration: Remove dependency to TYPE_DEVICE
In reply to Peter XuWhile doing that, we still want to keep the Property list that migration object used to use. Apply them directly to ObjectClass instead of setting them with a DeviceClass.
Manually apply the two extra properties (compat properties, global settings) in an instance_post_init() hook, just like most of the rest users, see callers of object_apply_compat_props().
--- migration/migration.h | 2 +- migration/migration.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-)
migration/migration.h +1 -1
@@ -274,7 +274,7 @@ struct MigrationClass {struct MigrationState {/*< private >*/ -DeviceState parent_obj; +Object parent_obj;/*< public >*/ QemuThread thread;
migration/migration.c +19 -14
@@ -3966,11 +3966,9 @@ fail:static void migration_class_init (ObjectClass *klass,const void *data) { -DeviceClass *dc =DEVICE_CLASS (klass); - - dc->user_creatable = false; -device_class_set_props_n (dc, migration_properties, - migration_properties_count); +for (int i =0 ; i < migration_properties_count; i++) { +object_class_add_property (klass, &migration_properties[i]); + } }static void migration_instance_finalize (Object *obj)
@@ -4028,21 +4026,28 @@ static bool migration_object_check(MigrationState *ms, Error **errp)return migrate_caps_check (old_caps, ms->capabilities, errp); } -static const TypeInfo migration_type = { - .name =TYPE_MIGRATION , +static void migration_instance_post_init (Object *obj) +{/* -* NOTE: TYPE_MIGRATION is not really a device, as the object is -* not created using qdev_new(), it is not attached to the qdev -* device tree, and it is never realized. +* Apply these properties on top of default values: * -* TODO: Make this TYPE_OBJECT once QOM provides something like -* TYPE_DEVICE's "-global" properties. +* (1) machine compat properties +* (2) -global settings in cmdlines +* +* Need to be applied in order so (2) takes precedence over (1). */ - .parent =TYPE_DEVICE , +object_apply_compat_props (obj); +object_apply_globals (obj); +} + +static const TypeInfo migration_type = { + .name =TYPE_MIGRATION , + .parent =TYPE_OBJECT , .class_init = migration_class_init, - .class_size =sizeof (MigrationClass), + .class_size =sizeof (ObjectClass), .instance_size =sizeof (MigrationState), .instance_init = migration_instance_init, + .instance_post_init = migration_instance_post_init, .instance_finalize = migration_instance_finalize, };
Signature · 1 line
2.53.0
Re: [PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Hi
Quoted 20 lines · Peter Xu
While doing that, we still want to keep the Property list that migration object used to use. Apply them directly to ObjectClass instead of setting them with a DeviceClass.
Manually apply the two extra properties (compat properties, global settings) in an
instance_post_init()hook, just like most of the rest users, see callers ofobject_apply_compat_props().Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 2 +- migration/migration.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-)migration/migration.h +0
-0
migration/migration.h struct MigrationClass { · line 278
Quoted 6 lines
migration/migration.h +1
-1@@ -274,7 +274,7 @@ struct MigrationClass {struct MigrationState {/*< private >*/ -DeviceState parent_obj; +Object parent_obj;
You need to change MigrationClass.parent_class too
Quoted 43 lines
migration/migration.h +0
-0/*< public >*/ QemuThread thread;migration/migration.c +10
-13@@ -3966,11 +3966,9 @@ fail:static void migration_class_init (ObjectClass *klass,const void *data) { -DeviceClass *dc =DEVICE_CLASS (klass); - - dc->user_creatable = false; -device_class_set_props_n (dc, migration_properties, - migration_properties_count); +for (int i =0 ; i < migration_properties_count; i++) { +object_class_add_property (klass, &migration_properties[i]); + } }static void migration_instance_finalize (Object *obj)@@ -4028,21 +4026,28 @@ static bool migration_object_check(MigrationState *ms, Error **errp)return migrate_caps_check (old_caps, ms->capabilities, errp); } -static const TypeInfo migration_type = { - .name =TYPE_MIGRATION , +static void migration_instance_post_init (Object *obj) +{/* -* NOTE: TYPE_MIGRATION is not really a device, as the object is -* not created using qdev_new(), it is not attached to the qdev -* device tree, and it is never realized. +* Apply these properties on top of default values: * -* TODO: Make this TYPE_OBJECT once QOM provides something like -* TYPE_DEVICE's "-global" properties. +* (1) machine compat properties +* (2) -global settings in cmdlines +* +* Need to be applied in order so (2) takes precedence over (1). */ - .parent =TYPE_DEVICE ,
migration/migration.c static bool migration_object_check(MigrationState *ms, Error **errp) · line 4047
Quoted 10 lines
migration/migration.c +8
-1+object_apply_compat_props (obj); +object_apply_globals (obj); +} + +static const TypeInfo migration_type = { + .name =TYPE_MIGRATION , + .parent =TYPE_OBJECT , .class_init = migration_class_init, - .class_size = sizeof(MigrationClass), + .class_size =sizeof (ObjectClass),
and this should still be MigrationClass
Quoted 10 lines
migration/migration.c +1
-1.instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_post_init = migration_instance_post_init, .instance_finalize = migration_instance_finalize, }; --2.53.0
Otherwise, the series is good to me!
Re: [PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Quoted 24 lines · Marc-André Lureau
Hi
Quoted 21 lines · Peter Xu
While doing that, we still want to keep the Property list that migration object used to use. Apply them directly to ObjectClass instead of setting them with a DeviceClass.
Manually apply the two extra properties (compat properties, global settings) in an
instance_post_init()hook, just like most of the rest users, see callers ofobject_apply_compat_props().Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 2 +- migration/migration.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-)migration/migration.h +0
-0@@ -274,7 +274,7 @@ struct MigrationClass {
Quoted 7 lines
migration/migration.h struct MigrationClass { · line 278
Quoted 5 lines
migration/migration.h +1
-1struct MigrationState {/*< private >*/ -DeviceState parent_obj; +Object parent_obj;You need to change MigrationClass.parent_class too
Do we even need a MigrationClass struct ? It has nothing except the parent_class field, so feels redundant. Could the code just use OBJECT_DECLARE_SIMPLE_TYPE instead.
Quoted 9 lines
Quoted 9 lines
migration/migration.h +0
-0/*< public >*/ QemuThread thread;migration/migration.c +0
-0@@ -3966,11 +3966,9 @@ fail:
Quoted 10 lines
migration/migration.c fail: · line 3971
Quoted 10 lines
migration/migration.c +3
-5static void migration_class_init (ObjectClass *klass,const void *data) { -DeviceClass *dc =DEVICE_CLASS (klass); - - dc->user_creatable = false; -device_class_set_props_n (dc, migration_properties, - migration_properties_count); +for (int i =0 ; i < migration_properties_count; i++) { +object_class_add_property (klass, &migration_properties[i]); + }
This could get rid of migration_properties array indirection and call object_class_property_add directly, avoiding the need for the previous patch.
Quoted 8 lines
migration/migration.c static bool migration_object_check(MigrationState *ms, Error **errp) · line 4047
Quoted 6 lines
migration/migration.c +4
-1+static const TypeInfo migration_type = { + .name =TYPE_MIGRATION , + .parent =TYPE_OBJECT , .class_init = migration_class_init, - .class_size = sizeof(MigrationClass), + .class_size =sizeof (ObjectClass),and this should still be MigrationClass
Not if we use OBJECT_DECLARE_SIMPLE_TYPE
Quoted 7 lines
Quoted 7 lines
.instance_size = sizeof(MigrationState), .instance_init =
migration_instance_init,
+ .instance_post_init =migration_instance_post_init,
.instance_finalize =migration_instance_finalize,
};
Quoted 7 lines
Quoted 4 lines
--
2.53.0Otherwise, the series is good to me!
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Re: [PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Quoted 3 lines · Daniel P. Berrangé
Do we even need a MigrationClass struct ? It has nothing except the
parent_classfield, so feels redundant. Could the code just useOBJECT_DECLARE_SIMPLE_TYPEinstead.
True, I'll add a small patch at the beginning.
Thanks,
Signature · 1 line
Peter Xu