migration/qom: Remove TYPE_DEVICE dependency on migration object
Subsystems (4)
v2 cover migration/qom: Remove TYPE_DEVICE dependency on migration object
CI: https://gitlab.com/peterx/qemu/-/pipelines/2588717620
(two irrelevant failures due to no runner)
rfc: https://lore.kernel.org/r/[email protected] v1: https://lore.kernel.org/r/[email protected]
This v2 is a full rewrite of v1, changelog doesn't apply.
This version majorly addressed the concern in v1 having object API exported in qdev files. Instead of trying to expose qdev properties, this patchset switched migration object to use the object property API to add properties.
Not all QOM facilities are ready for it, there're a few prior patches to improve QOM API to achieve it.
The major concept that this series introduces that does not exist previously is the default value mechanisms for object properties (rather than object class properties). Here migration object will rely on that to set default values.
Patch 1: A cleanup to use OBJECT_DECLARE_SIMPLE_TYPE for migration Patch 2-4: Qdev changes needed for the transition Patch 5-9: Improve QOM API to prepare for the property switch Patch 10: Switch migration object to use TYPE_OBJECT and object props
Comments welcomed, thanks.
Peter Xu (10):
migration: Use OBJECT_DECLARE_SIMPLE_TYPE
qdev: Export global_props()
qdev: Introduce DEFINE_PROP_*_NODEFAULT for bool/uint32 hw/arm: Use nodefault version of qdev props when not needed
qom: Create object-property-ptr.[ch]
qom: Add object_property_add_bool_ptr()
qom: Add object_property_add_size_ptr()
qom: Add object_property_add_*_ptr_def()
qom: Allow default values for instance properties
migration: Switch to TYPE_OBJECT with object properties
include/hw/core/qdev-properties.h | 7 + include/qom/object-property-ptr.h | 162 +++++++++ include/qom/object.h | 99 +----- migration/migration.h | 9 +- migration/options.h | 8 +- hw/arm/bcm2836.c | 3 +- hw/core/qdev-properties.c | 2 +- migration/migration.c | 42 ++- migration/options.c | 526 +++++++++++++++++++----------- qom/object-property-ptr.c | 394 ++++++++++++++++++++++ qom/object.c | 266 ++------------- target/arm/cpu64.c | 3 +- qom/meson.build | 1 + rust/bindings/hwcore-sys/lib.rs | 2 +- 14 files changed, 957 insertions(+), 567 deletions(-) create mode 100644 include/qom/object-property-ptr.h create mode 100644 qom/object-property-ptr.c
Signature · 1 line
2.53.0
PATCH v2 1/10 migration: Use OBJECT_DECLARE_SIMPLE_TYPE
Migration object's class has nothing special, switch to the newly introduced macro.
--- migration/migration.h | 9 +-------- migration/migration.c | 7 +++---- 2 files changed, 4 insertions(+), 12 deletions(-)
migration/migration.h +1 -8
@@ -263,14 +263,7 @@ void fill_destination_postcopy_migration_info(MigrationInfo *info);#define TYPE_MIGRATION "migration" -typedef struct MigrationClass MigrationClass ; -DECLARE_OBJ_CHECKERS (MigrationState, MigrationClass, - MIGRATION_OBJ, TYPE_MIGRATION) - -struct MigrationClass { -/*< private >*/ -DeviceClass parent_class; -}; +OBJECT_DECLARE_SIMPLE_TYPE (MigrationState,MIGRATION );struct MigrationState {/*< private >*/
migration/migration.c +3 -4
@@ -297,7 +297,7 @@ void migration_object_init(void) {/* This can only be called once. */ assert (!current_migration); - current_migration =MIGRATION_OBJ (object_new (TYPE_MIGRATION )); + current_migration =MIGRATION (object_new (TYPE_MIGRATION ));/* * Init the migrate incoming object as well no matter whether
@@ -3975,7 +3975,7 @@ static void migration_class_init(ObjectClass *klass, const void *data)static void migration_instance_finalize (Object *obj) { -MigrationState *ms =MIGRATION_OBJ (obj); +MigrationState *ms =MIGRATION (obj);qapi_free_BitmapMigrationNodeAliasList (ms->parameters.block_bitmap_mapping);qapi_free_strList (ms->parameters.cpr_exec_command);
@@ -3993,7 +3993,7 @@ static void migration_instance_finalize(Object *obj)static void migration_instance_init (Object *obj) { -MigrationState *ms =MIGRATION_OBJ (obj); +MigrationState *ms =MIGRATION (obj); ms->state =MIGRATION_STATUS_NONE ; ms->mbps =-1 ;
@@ -4040,7 +4040,6 @@ static const TypeInfo migration_type = {*/ .parent = TYPE_DEVICE, .class_init = migration_class_init, - .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, .instance_finalize = migration_instance_finalize,
Signature · 1 line
2.53.0
Re: [PATCH v2 01/10] migration: Use OBJECT_DECLARE_SIMPLE_TYPE
Quoted 62 lines · Peter Xu
Migration object's class has nothing special, switch to the newly introduced macro.
Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 9 +-------- migration/migration.c | 7 +++---- 2 files changed, 4 insertions(+), 12 deletions(-)migration/migration.h +1
-8@@ -263,14 +263,7 @@ void fill_destination_postcopy_migration_info(MigrationInfo *info);#define TYPE_MIGRATION "migration" -typedef struct MigrationClass MigrationClass ; -DECLARE_OBJ_CHECKERS (MigrationState, MigrationClass, - MIGRATION_OBJ, TYPE_MIGRATION) - -struct MigrationClass { -/*< private >*/ -DeviceClass parent_class; -}; +OBJECT_DECLARE_SIMPLE_TYPE (MigrationState,MIGRATION );struct MigrationState {/*< private >*/ migration/migration.c +3
-3@@ -297,7 +297,7 @@ void migration_object_init(void) {/* This can only be called once. */ assert (!current_migration); - current_migration =MIGRATION_OBJ (object_new (TYPE_MIGRATION )); + current_migration =MIGRATION (object_new (TYPE_MIGRATION ));/* * Init the migrate incoming object as well no matter whether @@ -3975,7 +3975,7 @@ static void migration_class_init(ObjectClass *klass, const void *data)static void migration_instance_finalize (Object *obj) { -MigrationState *ms =MIGRATION_OBJ (obj); +MigrationState *ms =MIGRATION (obj);qapi_free_BitmapMigrationNodeAliasList (ms->parameters.block_bitmap_mapping);qapi_free_strList (ms->parameters.cpr_exec_command);@@ -3993,7 +3993,7 @@ static void migration_instance_finalize(Object *obj)static void migration_instance_init (Object *obj) { -MigrationState *ms =MIGRATION_OBJ (obj); +MigrationState *ms =MIGRATION (obj); ms->state =MIGRATION_STATUS_NONE ; ms->mbps =-1 ;
migration/migration.c static const TypeInfo migration_type = { · line 4045
Quoted 7 lines
migration/migration.c +0
-1@@ -4040,7 +4040,6 @@ static const TypeInfo migration_type = {*/ .parent = TYPE_DEVICE, .class_init = migration_class_init, - .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, .instance_finalize = migration_instance_finalize,
Re: [PATCH v2 01/10] migration: Use OBJECT_DECLARE_SIMPLE_TYPE
In reply to Peter XuQuoted 9 lines · Peter Xu
Migration object's class has nothing special, switch to the newly introduced macro.
Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 9 +-------- migration/migration.c | 7 +++---- 2 files changed, 4 insertions(+), 12 deletions(-)
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 v2 01/10] migration: Use OBJECT_DECLARE_SIMPLE_TYPE
In reply to Peter XuQuoted 62 lines · Peter Xu
Migration object's class has nothing special, switch to the newly introduced macro.
Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 9 +-------- migration/migration.c | 7 +++---- 2 files changed, 4 insertions(+), 12 deletions(-)migration/migration.h +1
-8@@ -263,14 +263,7 @@ void fill_destination_postcopy_migration_info(MigrationInfo *info);#define TYPE_MIGRATION "migration" -typedef struct MigrationClass MigrationClass ; -DECLARE_OBJ_CHECKERS (MigrationState, MigrationClass, - MIGRATION_OBJ, TYPE_MIGRATION) - -struct MigrationClass { -/*< private >*/ -DeviceClass parent_class; -}; +OBJECT_DECLARE_SIMPLE_TYPE (MigrationState,MIGRATION );struct MigrationState {/*< private >*/ migration/migration.c +3
-3@@ -297,7 +297,7 @@ void migration_object_init(void) {/* This can only be called once. */ assert (!current_migration); - current_migration =MIGRATION_OBJ (object_new (TYPE_MIGRATION )); + current_migration =MIGRATION (object_new (TYPE_MIGRATION ));/* * Init the migrate incoming object as well no matter whether @@ -3975,7 +3975,7 @@ static void migration_class_init(ObjectClass *klass, const void *data)static void migration_instance_finalize (Object *obj) { -MigrationState *ms =MIGRATION_OBJ (obj); +MigrationState *ms =MIGRATION (obj);qapi_free_BitmapMigrationNodeAliasList (ms->parameters.block_bitmap_mapping);qapi_free_strList (ms->parameters.cpr_exec_command);@@ -3993,7 +3993,7 @@ static void migration_instance_finalize(Object *obj)static void migration_instance_init (Object *obj) { -MigrationState *ms =MIGRATION_OBJ (obj); +MigrationState *ms =MIGRATION (obj); ms->state =MIGRATION_STATUS_NONE ; ms->mbps =-1 ;
migration/migration.c static const TypeInfo migration_type = { · line 4045
Quoted 7 lines
migration/migration.c +0
-1@@ -4040,7 +4040,6 @@ static const TypeInfo migration_type = {*/ .parent = TYPE_DEVICE, .class_init = migration_class_init, - .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, .instance_finalize = migration_instance_finalize,
ATB,
Mark.
PATCH v2 2/10 qdev: Export global_props()
In reply to Peter XuMake it accessible from outside (to apply -global properties).
--- include/hw/core/qdev-properties.h | 2 ++ hw/core/qdev-properties.c | 2 +- rust/bindings/hwcore-sys/lib.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
include/hw/core/qdev-properties.h +2 -0
@@ -321,4 +321,6 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj,const char *name, Object *val, Error **errp); +GPtrArray *global_props (void ); +#endif
hw/core/qdev-properties.c +1 -1
@@ -958,7 +958,7 @@ void qlist_append_link(QList *qlist, Object *obj)qlist_append_str (qlist, path); } -static GPtrArray *global_props (void ) +GPtrArray *global_props (void ) {static GPtrArray *gp;
rust/bindings/hwcore-sys/lib.rs +1 -1
@@ -20,7 +20,7 @@use chardev_sys::Chardev ;use common::Zeroable ; -use glib_sys::GSList ; +use glib_sys::{GPtrArray ,GSList };use migration_sys::VMStateDescription ;use qom_sys::{InterfaceClass ,Object ,ObjectClass ,ObjectProperty ,ObjectPropertyAccessor ,
Signature · 1 line
2.53.0
Re: [PATCH v2 02/10] qdev: Export global_props()
Quoted 38 lines · Peter Xu
Make it accessible from outside (to apply -global properties).
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 2 ++ hw/core/qdev-properties.c | 2 +- rust/bindings/hwcore-sys/lib.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)include/hw/core/qdev-properties.h +2
-0@@ -321,4 +321,6 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj,const char *name, Object *val, Error **errp); +GPtrArray *global_props (void ); +#endif hw/core/qdev-properties.c +1
-1@@ -958,7 +958,7 @@ void qlist_append_link(QList *qlist, Object *obj)qlist_append_str (qlist, path); } -static GPtrArray *global_props (void ) +GPtrArray *global_props (void ) {static GPtrArray *gp;rust/bindings/hwcore-sys/lib.rs +0
-0
rust/bindings/hwcore-sys/lib.rs line 26
Quoted 8 lines
rust/bindings/hwcore-sys/lib.rs +1
-1@@ -20,7 +20,7 @@use chardev_sys::Chardev ;use common::Zeroable ; -use glib_sys::GSList ; +use glib_sys::{GPtrArray ,GSList };use migration_sys::VMStateDescription ;use qom_sys::{InterfaceClass ,Object ,ObjectClass ,ObjectProperty ,ObjectPropertyAccessor ,
Re: [PATCH v2 02/10] qdev: Export global_props()
In reply to Peter XuQuoted 38 lines · Peter Xu
Make it accessible from outside (to apply -global properties).
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 2 ++ hw/core/qdev-properties.c | 2 +- rust/bindings/hwcore-sys/lib.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)include/hw/core/qdev-properties.h +2
-0@@ -321,4 +321,6 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj,const char *name, Object *val, Error **errp); +GPtrArray *global_props (void ); +#endif hw/core/qdev-properties.c +1
-1@@ -958,7 +958,7 @@ void qlist_append_link(QList *qlist, Object *obj)qlist_append_str (qlist, path); } -static GPtrArray *global_props (void ) +GPtrArray *global_props (void ) {static GPtrArray *gp;rust/bindings/hwcore-sys/lib.rs +0
-0
rust/bindings/hwcore-sys/lib.rs line 26
Quoted 8 lines
rust/bindings/hwcore-sys/lib.rs +1
-1@@ -20,7 +20,7 @@use chardev_sys::Chardev ;use common::Zeroable ; -use glib_sys::GSList ; +use glib_sys::{GPtrArray ,GSList };use migration_sys::VMStateDescription ;use qom_sys::{InterfaceClass ,Object ,ObjectClass ,ObjectProperty ,ObjectPropertyAccessor ,
I'd have to take the Rust part on trust, but at least for the C version:
ATB,
Mark.
PATCH v2 3/10 qdev: Introduce DEFINE_PROP_*_NODEFAULT for bool/uint32
In reply to Peter XuIntroduce two macros that will be used in follow up patch to create qdev bool or uint32 properties without a default value. Do not introduce the rest until they can be used.
--- include/hw/core/qdev-properties.h | 5 +++++ 1 file changed, 5 insertions(+)
include/hw/core/qdev-properties.h +5 -0
@@ -124,6 +124,9 @@ extern const PropertyInfo qdev_prop_link; .set_default = true, \ .defval.u = (bool)_defval) +#define DEFINE_PROP_BOOL_NODEFAULT (_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool) +/** * The DEFINE_PROP_UINT64_CHECKMASK macro checks a user-supplied value * against corresponding bitmask, rejects the value if it violates.
@@ -201,6 +204,8 @@ extern const PropertyInfo qdev_prop_link; DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)#define DEFINE_PROP_UINT32 (_n, _s, _f, _d) \ DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) +#define DEFINE_PROP_UINT32_NODEFAULT (_n, _s, _f) \ + DEFINE_PROP_UNSIGNED_NODEFAULT(_n, _s, _f, qdev_prop_uint32, uint32_t)#define DEFINE_PROP_INT32 (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)#define DEFINE_PROP_UINT64 (_n, _s, _f, _d) \
Signature · 1 line
2.53.0
Re: [PATCH v2 03/10] qdev: Introduce DEFINE_PROP_*_NODEFAULT for bool/uint32
Quoted 24 lines · Peter Xu
Introduce two macros that will be used in follow up patch to create qdev bool or uint32 properties without a default value. Do not introduce the rest until they can be used.
Signed-off-by Peter Xu <[email protected]>--- include/hw/core/qdev-properties.h | 5 +++++ 1 file changed, 5 insertions(+)include/hw/core/qdev-properties.h +3
-0@@ -124,6 +124,9 @@ extern const PropertyInfo qdev_prop_link; .set_default = true, \ .defval.u = (bool)_defval) +#define DEFINE_PROP_BOOL_NODEFAULT (_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool) +/** * The DEFINE_PROP_UINT64_CHECKMASK macro checks a user-supplied value * against corresponding bitmask, rejects the value if it violates.
include/hw/core/qdev-properties.h extern const PropertyInfo qdev_prop_link; · line 211
Quoted 8 lines
include/hw/core/qdev-properties.h +2
-0@@ -201,6 +204,8 @@ extern const PropertyInfo qdev_prop_link; DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)#define DEFINE_PROP_UINT32 (_n, _s, _f, _d) \ DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) +#define DEFINE_PROP_UINT32_NODEFAULT (_n, _s, _f) \ + DEFINE_PROP_UNSIGNED_NODEFAULT(_n, _s, _f, qdev_prop_uint32, uint32_t)#define DEFINE_PROP_INT32 (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)#define DEFINE_PROP_UINT64 (_n, _s, _f, _d) \
I think it's worth mentioning in the commit message that this extends the existing set of _NODEFAULT() macros, since I had to go and check to see if this was something completely new being introduced by the patch (it's not something I was familiar with, and we don't appear to mention them in our docs!).
Anyhow it seems correct, so:
ATB,
Mark.
PATCH v2 4/10 hw/arm: Use nodefault version of qdev props when not needed
In reply to Peter XuWe're going to introduce defvars for object properties just like qdev-props defvars. It work slightly differently in that props can be added in instance_init() with default values, then the default values can only apply after instance_init() completes.
It means any explicit set of property values within instance_init() when used together with object property's default value (or qdev-prop, which builts the default value framework on top) will stop working.
This patch touches two of such use cases where the device may add qdev properties with a default value first, then quickly set another value within instance_init().
These are the only two outliers I found across the QEMU tree that do it this way. Switch them to use qdev-prop's NODEFAULT APIs, and always initialize the values manually.
Example 1:
bcm283x_base_init() adds qdev prop bcm2836_enabled_cores_property with a default value 0, then it immediately set another value inside the same instance_init() hook.
Example 2:
aarch64_add_pauth_properties() adds qdev prop arm_cpu_pauth_property, but then it will immediately update the same field (cpu->prop_pauth) conditionally when hwaccel_enabled()==true.
Without the change, some arm test may fail (boot-serial-test) after introducing object property's default value framework, because devices' values will be overwritten by the properties' later.
OTOH, this patch itself should introduce no functional change.
--- hw/arm/bcm2836.c | 3 ++- target/arm/cpu64.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
hw/arm/bcm2836.c +2 -1
@@ -19,7 +19,8 @@#include "target/arm/gtimer.h" static const Property bcm2836_enabled_cores_property = -DEFINE_PROP_UINT32 ("enabled-cpus" , BCM283XBaseState, enabled_cpus,0 ); +DEFINE_PROP_UINT32_NODEFAULT ( +"enabled-cpus" , BCM283XBaseState, enabled_cpus);static void bcm283x_base_init (Object *obj) {
target/arm/cpu64.c +2 -1
@@ -635,7 +635,7 @@ void aarch64_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) }static const Property arm_cpu_pauth_property = -DEFINE_PROP_BOOL ("pauth" ,ARMCPU , prop_pauth, true); +DEFINE_PROP_BOOL_NODEFAULT ("pauth" ,ARMCPU , prop_pauth);static const Property arm_cpu_pauth_impdef_property =DEFINE_PROP_BOOL ("pauth-impdef" ,ARMCPU , prop_pauth_impdef, false); static const Property arm_cpu_pauth_qarma3_property =
@@ -660,6 +660,7 @@ void aarch64_add_pauth_properties(Object *obj)*/ cpu->prop_pauth =cpu_isar_feature (aa64_pauth, cpu); }else { + cpu->prop_pauth = true;qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_impdef_property);qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_qarma3_property);qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_qarma5_property);
Signature · 1 line
2.53.0
Re: [PATCH v2 04/10] hw/arm: Use nodefault version of qdev props when not needed
Quoted 71 lines · Peter Xu
We're going to introduce defvars for object properties just like qdev-props defvars. It work slightly differently in that props can be added in
instance_init()with default values, then the default values can only apply afterinstance_init()completes.It means any explicit set of property values within
instance_init()when used together with object property's default value (or qdev-prop, which builts the default value framework on top) will stop working.This patch touches two of such use cases where the device may add qdev properties with a default value first, then quickly set another value within
instance_init().These are the only two outliers I found across the QEMU tree that do it this way. Switch them to use qdev-prop's NODEFAULT APIs, and always initialize the values manually.
Example 1:
bcm283x_base_init()adds qdev propbcm2836_enabled_cores_propertywith a default value 0, then it immediately set another value inside the sameinstance_init()hook.Example 2:
aarch64_add_pauth_properties()adds qdev proparm_cpu_pauth_property, but then it will immediately update the same field (cpu->prop_pauth) conditionally when hwaccel_enabled()==true.Without the change, some arm test may fail (boot-serial-test) after introducing object property's default value framework, because devices' values will be overwritten by the properties' later.
OTOH, this patch itself should introduce no functional change.
Cc Marc Zyngier <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Peter Xu <[email protected]>--- hw/arm/bcm2836.c | 3 ++- target/arm/cpu64.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)hw/arm/bcm2836.c +2
-1@@ -19,7 +19,8 @@#include "target/arm/gtimer.h" static const Property bcm2836_enabled_cores_property = -DEFINE_PROP_UINT32 ("enabled-cpus" , BCM283XBaseState, enabled_cpus,0 ); +DEFINE_PROP_UINT32_NODEFAULT ( +"enabled-cpus" , BCM283XBaseState, enabled_cpus);static void bcm283x_base_init (Object *obj) {target/arm/cpu64.c +1
-1@@ -635,7 +635,7 @@ void aarch64_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) }static const Property arm_cpu_pauth_property = -DEFINE_PROP_BOOL ("pauth" ,ARMCPU , prop_pauth, true); +DEFINE_PROP_BOOL_NODEFAULT ("pauth" ,ARMCPU , prop_pauth);static const Property arm_cpu_pauth_impdef_property =DEFINE_PROP_BOOL ("pauth-impdef" ,ARMCPU , prop_pauth_impdef, false); static const Property arm_cpu_pauth_qarma3_property =
target/arm/cpu64.c void aarch64_add_pauth_properties(Object *obj) · line 666
Quoted 7 lines
target/arm/cpu64.c +1
-0@@ -660,6 +660,7 @@ void aarch64_add_pauth_properties(Object *obj)*/ cpu->prop_pauth =cpu_isar_feature (aa64_pauth, cpu); }else { + cpu->prop_pauth = true;qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_impdef_property);qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_qarma3_property);qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_qarma5_property);
I checked against the commit message for 5cc56cc687 ("qdev: support properties which don't set a default value") and this is exactly what _NODEFAULT() is intended for, so:
ATB,
Mark.
PATCH v2 5/10 qom: Create object-property-ptr.[ch]
In reply to Peter XuCreate object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since object.c has been already too big, split that part out.
No functional change intended.
--- include/qom/object-property-ptr.h | 103 +++++++++++++ include/qom/object.h | 99 +----------- qom/object-property-ptr.c | 248 ++++++++++++++++++++++++++++++ qom/object.c | 240 ----------------------------- qom/meson.build | 1 + 5 files changed, 358 insertions(+), 333 deletions(-) create mode 100644 include/qom/object-property-ptr.h create mode 100644 qom/object-property-ptr.c
include/qom/object-property-ptr.h new file +103 -0
@@ -0,0 +1,103 @@ +/* +* Object property helpers to operate on a pointer. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef QEMU_OBJECT_PROPERTY_PTR_H +#define QEMU_OBJECT_PROPERTY_PTR_H + +typedef enum { +/* Automatically add a getter to the property */ +OBJ_PROP_FLAG_READ =1 <<0 , +/* Automatically add a setter to the property */ +OBJ_PROP_FLAG_WRITE =1 <<1 , +/* Automatically add a getter and a setter to the property */ +OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), +}ObjectPropertyFlags ; + +/** +* object_property_add_uint8_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint8'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint8_ptr (Object *obj,const char *name, +const uint8_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +const uint8_t *v, +ObjectPropertyFlags flags); + +/** +* object_property_add_uint16_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint16'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint16_ptr (Object *obj,const char *name, +const uint16_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +const char *name, +const uint16_t *v, +ObjectPropertyFlags flags); + +/** +* object_property_add_uint32_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint32'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint32_ptr (Object *obj,const char *name, +const uint32_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +const char *name, +const uint32_t *v, +ObjectPropertyFlags flags); + +/** +* object_property_add_uint64_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint64'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint64_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +const char *name, +const uint64_t *v, +ObjectPropertyFlags flags); + +#endif
include/qom/object.h +6 -93
109 lines not on this page · raw message
qom/object-property-ptr.c new file +248 -0
248 lines not on this page · raw message
qom/object.c +0 -240
246 lines not on this page · raw message
qom/meson.build +1 -0
@@ -3,6 +3,7 @@ qom_ss.add(files( 'container.c', 'object.c', 'object_interfaces.c', + 'object-property-ptr.c', 'qom-qobject.c', )) if have_system
Signature · 1 line
2.53.0
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 9 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.
The "ptr" helpers are all instance level properties which is a concept we discourage from new usage, in favour of class level properties.
I don't think we should be adding more "ptr" helpers, but rather planning to eliminiate the (surprisingly little) usage of the existing ones.
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 v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 11 lines · Daniel P. Berrangé
Quoted 9 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.
Quoted 6 lines
The "ptr" helpers are all instance level properties which is a concept we discourage from new usage, in favour of class level properties.
I don't think we should be adding more "ptr" helpers, but rather planning to eliminiate the (surprisingly little) usage of the existing ones.
The other way to do similar thing is qdev's offset way, but IMHO that's more awkward to remember an offset of a pointer then do math everytime. Essentially, from technical pov we need at least one uintptr_t to store either (1) offset, or (2) field pointer when there's a field that is bound to a prop. IMHO (2) can be better otherwise we'll need to do all the maths to calculate offsets then when access we add the offset back and do a force cast. It seems not necessary.
OTOH, I still see value on non-class instance properties (that sometimes we don't even want to have some props avail for the class, but conditional to some instances when created dynamically). If that is needed, IMHO it's fine we still provide per-instance properties.
Is there any pointer I can read about the discussion previously on this?
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 19 lines · Peter Xu
Quoted 11 lines · Daniel P. Berrangé
Quoted 9 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.Quoted 6 lines
The "ptr" helpers are all instance level properties which is a concept we discourage from new usage, in favour of class level properties.
I don't think we should be adding more "ptr" helpers, but rather planning to eliminiate the (surprisingly little) usage of the existing ones.
Quoted 8 lines
The other way to do similar thing is qdev's offset way, but IMHO that's more awkward to remember an offset of a pointer then do math everytime. Essentially, from technical pov we need at least one
uintptr_tto store either (1) offset, or (2) field pointer when there's a field that is bound to a prop. IMHO (2) can be better otherwise we'll need to do all the maths to calculate offsets then when access we add the offset back and do a force cast. It seems not necessary.
The more limiting aspect of using the offset is that MigrationParameters needs to be embedded into MigrationState because the Object is MigrationState and not MigrationParameters. We could try to solve that issue specifically by making MigrationParameters a standalone object.
The main issue is that we would need to figure out how to set the compat properties that are not part of MigrationParameters.
The other main issue =) is that we'd need to wrap this in another structure because MigrationParameters is generated by QAPI.
A minor issue is that -object migration and -global migration use the "migration" word from TYPE_MIGRATION, so the MigrationState would have to be renamed.
We could actually solve the first two by doing similarly to what I did in qom.json in my reply to the cover-letter:
struct MigrationOptions {
MigrationParameters params;
<compat props>
}
... then access it by offset. This is fine because we can then do whatever we want with the MigrationOptions pointer without having to follow the lifetime of MigrationState.
Quoted 8 lines
OTOH, I still see value on non-class instance properties (that sometimes we don't even want to have some props avail for the class, but conditional to some instances when created dynamically). If that is needed, IMHO it's fine we still provide per-instance properties.
Is there any pointer I can read about the discussion previously on this?
Thanks,
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
In reply to Peter XuQuoted 19 lines · Peter Xu
Quoted 11 lines · Daniel P. Berrangé
Quoted 9 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.Quoted 6 lines
The "ptr" helpers are all instance level properties which is a concept we discourage from new usage, in favour of class level properties.
I don't think we should be adding more "ptr" helpers, but rather planning to eliminiate the (surprisingly little) usage of the existing ones.
Quoted 7 lines
The other way to do similar thing is qdev's offset way, but IMHO that's more awkward to remember an offset of a pointer then do math everytime. Essentially, from technical pov we need at least one
uintptr_tto store either (1) offset, or (2) field pointer when there's a field that is bound to a prop. IMHO (2) can be better otherwise we'll need to do all the maths to calculate offsets then when access we add the offset back and do a force cast. It seems not necessary.
There shouldn't be any need to play with field offsets either. Just define the setters & getters to directly access the fields.
Take some samples from the "machine_class_init" in hw/core/machine.c as an example of the normal design pattern:
object_class_property_add_str(oc, "dumpdtb",
machine_get_dumpdtb, machine_set_dumpdtb);
object_class_property_set_description(oc, "dumpdtb",
"Dump current dtb to a file and quit");..snip..
object_class_property_add_bool(oc, "dump-guest-core",
machine_get_dump_guest_core, machine_set_dump_guest_core);
object_class_property_set_description(oc, "dump-guest-core",
"Include guest memory in a core dump");These are paired with:
static char *machine_get_dumpdtb(Object *obj, Error **errp)
{
MachineState *ms = MACHINE(obj);return g_strdup(ms->dumpdtb);
}
static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
{
MachineState *ms = MACHINE(obj); g_free(ms->dumpdtb);
ms->dumpdtb = g_strdup(value);}
and
static bool machine_get_dump_guest_core(Object *obj, Error **errp)
{
MachineState *ms = MACHINE(obj);return ms->dump_guest_core;
}
static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
{
MachineState *ms = MACHINE(obj); if (!value && QEMU_MADV_DONTDUMP == QEMU_MADV_INVALID) {
error_setg(errp, "Dumping guest memory cannot be disabled on this host");
return;
}
ms->dump_guest_core = value;}
and defaults (if needed) are set in the instance init method:
static void machine_initfn(Object *obj)
{
MachineState *ms = MACHINE(obj);
MachineClass *mc = MACHINE_GET_CLASS(obj); ms->dump_guest_core = true;
ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID);
...}
Quoted 4 lines
OTOH, I still see value on non-class instance properties (that sometimes we don't even want to have some props avail for the class, but conditional to some instances when created dynamically). If that is needed, IMHO it's fine we still provide per-instance properties.
Conditionally registering properties on instances is an anti-pattern IMHO. It results in objects that cannot have all their properties statically introspected.
If a class needs different subsets of properties for different scenarios, that is potentially a sign there ought to be a base class and two or more specialized subclasses. Or that the property needs a more explicit "unset" state in addition to its other valid values.
For introspection we hack around the use of instance properties by instantiating every object in order to trigger registration of instance props. This is such a gross hack that it periodically suffers crashes from objects not expecting to be instantiated in this context and having undesired side-effects. Class props are the only sane way to reliably provide introspection without side-effects.
Quoted 1 line
Is there any pointer I can read about the discussion previously on this?
I don't know that there's a particular thread in recent times that I'd point to, just my ancient series from when I introduced class properties for QOM back in 2015 and started the effort to convert away from instances properties.
https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg03112.html
Quoted 6 lines
Thanks,
Signature · 1 line
Peter Xu
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 v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 91 lines · Daniel P. Berrangé
Quoted 19 lines · Peter Xu
Quoted 11 lines · Daniel P. Berrangé
Quoted 9 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.Quoted 6 lines
The "ptr" helpers are all instance level properties which is a concept we discourage from new usage, in favour of class level properties.
I don't think we should be adding more "ptr" helpers, but rather planning to eliminiate the (surprisingly little) usage of the existing ones.
Quoted 7 lines
The other way to do similar thing is qdev's offset way, but IMHO that's more awkward to remember an offset of a pointer then do math everytime. Essentially, from technical pov we need at least one
uintptr_tto store either (1) offset, or (2) field pointer when there's a field that is bound to a prop. IMHO (2) can be better otherwise we'll need to do all the maths to calculate offsets then when access we add the offset back and do a force cast. It seems not necessary.There shouldn't be any need to play with field offsets either. Just define the setters & getters to directly access the fields.
Take some samples from the "
machine_class_init" inhw/core/machine.cas an example of the normal design pattern:object_class_property_add_str(oc, "dumpdtb", machine_get_dumpdtb, machine_set_dumpdtb); object_class_property_set_description(oc, "dumpdtb", "Dump current dtb to a file and quit");..snip.. object_class_property_add_bool(oc, "dump-guest-core", machine_get_dump_guest_core, machine_set_dump_guest_core); object_class_property_set_description(oc, "dump-guest-core", "Include guest memory in a core dump");These are paired with:
static char *machine_get_dumpdtb(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj);return g_strdup(ms->dumpdtb);}
static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) { MachineState *ms = MACHINE(obj);g_free(ms->dumpdtb); ms->dumpdtb = g_strdup(value);}
and
static bool machine_get_dump_guest_core(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj);return ms->dump_guest_core;}
static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) { MachineState *ms = MACHINE(obj);if (!value && QEMU_MADV_DONTDUMP == QEMU_MADV_INVALID) { error_setg(errp, "Dumping guest memory cannot be disabled on this host"); return; } ms->dump_guest_core = value;}
and defaults (if needed) are set in the instance init method:
static void machine_initfn(Object *obj) { MachineState *ms = MACHINE(obj); MachineClass *mc = MACHINE_GET_CLASS(obj);
Quoted 5 lines
ms->dump_guest_core = true; ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID); ...}
Thanks for the practical example. In this usage, do you think there would be a way to avoid having 53 getters and setters? We often run into this issue of the rest of QEMU having just a handful of options and migration having a ton. Anything we can do to streamline this would be good.
Quoted 23 lines
Quoted 4 lines
OTOH, I still see value on non-class instance properties (that sometimes we don't even want to have some props avail for the class, but conditional to some instances when created dynamically). If that is needed, IMHO it's fine we still provide per-instance properties.
Conditionally registering properties on instances is an anti-pattern IMHO. It results in objects that cannot have all their properties statically introspected.
If a class needs different subsets of properties for different scenarios, that is potentially a sign there ought to be a base class and two or more specialized subclasses. Or that the property needs a more explicit "unset" state in addition to its other valid values.
For introspection we hack around the use of instance properties by instantiating every object in order to trigger registration of instance props. This is such a gross hack that it periodically suffers crashes from objects not expecting to be instantiated in this context and having undesired side-effects. Class props are the only sane way to reliably provide introspection without side-effects.
Quoted 9 lines
Quoted 1 line
Is there any pointer I can read about the discussion previously on this?
I don't know that there's a particular thread in recent times that I'd point to, just my ancient series from when I introduced class properties for QOM back in 2015 and started the effort to convert away from instances properties.
https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg03112.html
Anything we can do to avoid stumbling into this again? Should we add some words to object_property_add() discouraging instance properties?
Quoted 11 lines
Quoted 8 lines
Thanks,
Signature · 1 line
Peter XuWith regards,
Daniel
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 99 lines · Fabiano Rosas
Quoted 91 lines · Daniel P. Berrangé
Quoted 19 lines · Peter Xu
Quoted 11 lines · Daniel P. Berrangé
Quoted 9 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.Quoted 6 lines
The "ptr" helpers are all instance level properties which is a concept we discourage from new usage, in favour of class level properties.
I don't think we should be adding more "ptr" helpers, but rather planning to eliminiate the (surprisingly little) usage of the existing ones.
Quoted 7 lines
The other way to do similar thing is qdev's offset way, but IMHO that's more awkward to remember an offset of a pointer then do math everytime. Essentially, from technical pov we need at least one
uintptr_tto store either (1) offset, or (2) field pointer when there's a field that is bound to a prop. IMHO (2) can be better otherwise we'll need to do all the maths to calculate offsets then when access we add the offset back and do a force cast. It seems not necessary.There shouldn't be any need to play with field offsets either. Just define the setters & getters to directly access the fields.
Take some samples from the "
machine_class_init" inhw/core/machine.cas an example of the normal design pattern:object_class_property_add_str(oc, "dumpdtb", machine_get_dumpdtb, machine_set_dumpdtb); object_class_property_set_description(oc, "dumpdtb", "Dump current dtb to a file and quit");..snip.. object_class_property_add_bool(oc, "dump-guest-core", machine_get_dump_guest_core, machine_set_dump_guest_core); object_class_property_set_description(oc, "dump-guest-core", "Include guest memory in a core dump");These are paired with:
static char *machine_get_dumpdtb(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj);return g_strdup(ms->dumpdtb);}
static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) { MachineState *ms = MACHINE(obj);g_free(ms->dumpdtb); ms->dumpdtb = g_strdup(value);}
and
static bool machine_get_dump_guest_core(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj);return ms->dump_guest_core;}
static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) { MachineState *ms = MACHINE(obj);if (!value && QEMU_MADV_DONTDUMP == QEMU_MADV_INVALID) { error_setg(errp, "Dumping guest memory cannot be disabled on this host"); return; } ms->dump_guest_core = value;}
and defaults (if needed) are set in the instance init method:
static void machine_initfn(Object *obj) { MachineState *ms = MACHINE(obj); MachineClass *mc = MACHINE_GET_CLASS(obj);Quoted 5 lines
ms->dump_guest_core = true; ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID); ...}
Quoted 5 lines
Thanks for the practical example. In this usage, do you think there would be a way to avoid having 53 getters and setters? We often run into this issue of the rest of QEMU having just a handful of options and migration having a ton. Anything we can do to streamline this would be good.
There's nothing standard in QOM, but in patch 10 in this series Peter has a DEFINE_TLS_PROP_HELPERS() which macro-ized the repetitive getters/setters for the TLS string properties. The duplicate code still exists in the binary of course, just hidden from the source.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Is there any pointer I can read about the discussion previously on this?
I don't know that there's a particular thread in recent times that I'd point to, just my ancient series from when I introduced class properties for QOM back in 2015 and started the effort to convert away from instances properties.
Quoted 5 lines
Anything we can do to avoid stumbling into this again? Should we add some words to
object_property_add()discouraging instance properties?
Yeah, it is probably worth adding some guidance to the docs there.
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 v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 5 lines · Daniel P. Berrangé
There's nothing standard in QOM, but in patch 10 in this series Peter has a
DEFINE_TLS_PROP_HELPERS()which macro-ized the repetitive getters/setters for the TLS string properties. The duplicate code still exists in the binary of course, just hidden from the source.
I believe we have the standard, which is qdev-properties.. which is (1) class properties, (2) allow variable bindings so no setter/getter needed, remembering them with pointer offsets.
It goes back to last version where the question becomes: whether we want to make qdev-properties to be official QOM API, by removing qdev specific changes and move them over to qom/. Then make qdev only add its special things on top.
Said that, considering if we want to make all things qom-set-able to migration in the future, another option is directly go with getter/setter that will do the property checks one by one. One benefit of that is we can then get rid of migrate_params_check() and migrate_caps_check() altogether.
Maybe I should go with the latter, and forget qdev?
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 16 lines · Peter Xu
Quoted 5 lines · Daniel P. Berrangé
There's nothing standard in QOM, but in patch 10 in this series Peter has a
DEFINE_TLS_PROP_HELPERS()which macro-ized the repetitive getters/setters for the TLS string properties. The duplicate code still exists in the binary of course, just hidden from the source.I believe we have the standard, which is qdev-properties.. which is (1) class properties, (2) allow variable bindings so no setter/getter needed, remembering them with pointer offsets.
It goes back to last version where the question becomes: whether we want to make qdev-properties to be official QOM API, by removing qdev specific changes and move them over to qom/. Then make qdev only add its special things on top.
Quoted 6 lines
Said that, considering if we want to make all things qom-set-able to migration in the future, another option is directly go with getter/setter that will do the property checks one by one. One benefit of that is we can then get rid of
migrate_params_check()andmigrate_caps_check()altogether.Maybe I should go with the latter, and forget qdev?
I think it's a good idea. For caps that depend on one another do you intend to check once in each setter? The _check functions exist is because we want to validate the total state of params/caps, not just a single param. Just pointing it out, it's not necessarily an issue.
Quoted 2 lines
Thanks,
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 23 lines · Fabiano Rosas
Quoted 21 lines · Peter Xu
Quoted 5 lines · Daniel P. Berrangé
There's nothing standard in QOM, but in patch 10 in this series Peter has a
DEFINE_TLS_PROP_HELPERS()which macro-ized the repetitive getters/setters for the TLS string properties. The duplicate code still exists in the binary of course, just hidden from the source.I believe we have the standard, which is qdev-properties.. which is (1) class properties, (2) allow variable bindings so no setter/getter needed, remembering them with pointer offsets.
It goes back to last version where the question becomes: whether we want to make qdev-properties to be official QOM API, by removing qdev specific changes and move them over to qom/. Then make qdev only add its special things on top.
Said that, considering if we want to make all things qom-set-able to migration in the future, another option is directly go with getter/setter that will do the property checks one by one. One benefit of that is we can then get rid of
migrate_params_check()andmigrate_caps_check()altogether.
Quoted 6 lines
Quoted 1 line
Maybe I should go with the latter, and forget qdev?
I think it's a good idea. For caps that depend on one another do you intend to check once in each setter? The
_checkfunctions exist is because we want to validate the total state of params/caps, not just a single param. Just pointing it out, it's not necessarily an issue.
The user-creatable interface has a "complete" method which is called once all props have been set. So if there are semantics you can't validate against individual props in isolation, you can leave that validation until "complete".
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 v2 05/10] qom: Create object-property-ptr.[ch]
In reply to Peter XuQuoted 237 lines · Peter Xu
Create object-property-ptr.[ch] files to include all the helpers for object_property_add*_ptr().
These set of helpers are handy because they look extremely familiar with qdev-properties, allowing the caller to provide a pointer and it will manage all the setters and getters.
The follow up patches may introduce more of such helpers. Since
object.chas been already too big, split that part out.No functional change intended.
Signed-off-by Peter Xu <[email protected]>--- include/qom/object-property-ptr.h | 103 +++++++++++++ include/qom/object.h | 99 +----------- qom/object-property-ptr.c | 248 ++++++++++++++++++++++++++++++ qom/object.c | 240 ----------------------------- qom/meson.build | 1 + 5 files changed, 358 insertions(+), 333 deletions(-)create mode 100644
include/qom/object-property-ptr.hcreate mode 100644qom/object-property-ptr.cinclude/qom/object-property-ptr.h new file +103
-0@@ -0,0 +1,103 @@ +/* +* Object property helpers to operate on a pointer. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef QEMU_OBJECT_PROPERTY_PTR_H +#define QEMU_OBJECT_PROPERTY_PTR_H + +typedef enum { +/* Automatically add a getter to the property */ +OBJ_PROP_FLAG_READ =1 <<0 , +/* Automatically add a setter to the property */ +OBJ_PROP_FLAG_WRITE =1 <<1 , +/* Automatically add a getter and a setter to the property */ +OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), +}ObjectPropertyFlags ; + +/** +* object_property_add_uint8_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint8'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint8_ptr (Object *obj,const char *name, +const uint8_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, +const char *name, +const uint8_t *v, +ObjectPropertyFlags flags); + +/** +* object_property_add_uint16_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint16'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint16_ptr (Object *obj,const char *name, +const uint16_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, +const char *name, +const uint16_t *v, +ObjectPropertyFlags flags); + +/** +* object_property_add_uint32_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint32'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint32_ptr (Object *obj,const char *name, +const uint32_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, +const char *name, +const uint32_t *v, +ObjectPropertyFlags flags); + +/** +* object_property_add_uint64_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add an integer property in memory. This function will add a +* property of type 'uint64'. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty *object_property_add_uint64_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags); + +ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, +const char *name, +const uint64_t *v, +ObjectPropertyFlags flags); + +#endif include/qom/object.h +0
-93@@ -1931,99 +1931,6 @@ ObjectProperty *object_class_property_add_tm(ObjectClass *klass,const char *name, void (*get)(Object *, struct tm *, Error **)); -typedef enum { -/* Automatically add a getter to the property */ -OBJ_PROP_FLAG_READ =1 <<0 , -/* Automatically add a setter to the property */ -OBJ_PROP_FLAG_WRITE =1 <<1 , -/* Automatically add a getter and a setter to the property */ -OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), -}ObjectPropertyFlags ; - -/** -* object_property_add_uint8_ptr: -* @obj: the object to add a property to -* @name: the name of the property -* @v: pointer to value -* @flags: bitwise-or'd ObjectPropertyFlags -* -* Add an integer property in memory. This function will add a -* property of type 'uint8'. -* -* Returns: The newly added property on success, or %NULL on failure. -*/ -ObjectProperty *object_property_add_uint8_ptr (Object *obj,const char *name, -const uint8_t *v, -ObjectPropertyFlags flags); - -ObjectProperty *object_class_property_add_uint8_ptr (ObjectClass *klass, -const char *name, -const uint8_t *v, -ObjectPropertyFlags flags); - -/** -* object_property_add_uint16_ptr: -* @obj: the object to add a property to -* @name: the name of the property -* @v: pointer to value -* @flags: bitwise-or'd ObjectPropertyFlags -* -* Add an integer property in memory. This function will add a -* property of type 'uint16'. -* -* Returns: The newly added property on success, or %NULL on failure. -*/ -ObjectProperty *object_property_add_uint16_ptr (Object *obj,const char *name, -const uint16_t *v, -ObjectPropertyFlags flags); - -ObjectProperty *object_class_property_add_uint16_ptr (ObjectClass *klass, -const char *name, -const uint16_t *v, -ObjectPropertyFlags flags); - -/** -* object_property_add_uint32_ptr: -* @obj: the object to add a property to -* @name: the name of the property -* @v: pointer to value -* @flags: bitwise-or'd ObjectPropertyFlags -* -* Add an integer property in memory. This function will add a -* property of type 'uint32'. -* -* Returns: The newly added property on success, or %NULL on failure. -*/ -ObjectProperty *object_property_add_uint32_ptr (Object *obj,const char *name, -const uint32_t *v, -ObjectPropertyFlags flags); - -ObjectProperty *object_class_property_add_uint32_ptr (ObjectClass *klass, -const char *name, -const uint32_t *v, -ObjectPropertyFlags flags); - -/** -* object_property_add_uint64_ptr: -* @obj: the object to add a property to -* @name: the name of the property -* @v: pointer to value -* @flags: bitwise-or'd ObjectPropertyFlags -* -* Add an integer property in memory. This function will add a -* property of type 'uint64'. -* -* Returns: The newly added property on success, or %NULL on failure. -*/ -ObjectProperty *object_property_add_uint64_ptr (Object *obj,const char *name, -const uint64_t *v, -ObjectPropertyFlags flags); - -ObjectProperty *object_class_property_add_uint64_ptr (ObjectClass *klass, -const char *name, -const uint64_t *v, -ObjectPropertyFlags flags); -/** * object_property_add_alias: * @obj: the object to add a property to
include/qom/object.h char *object_property_help(const char *name, const char *type, · line 2055
Quoted 8 lines
include/qom/object.h +5
-0@@ -2141,4 +2048,10 @@ char *object_property_help(const char *name, const char *type,G_DEFINE_AUTOPTR_CLEANUP_FUNC (Object, object_unref) +/* +* Object property ptr helpers cannot be included at the beginning of the +* file, because it depends on QOM definitions in current header. + */ +#include "qom/object-property-ptr.h"
I wonder if possibly we might want to let the caller include the extra header? But I don't feel too strongly either way.
Quoted 511 lines
include/qom/object.h +0
-0#endif qom/object-property-ptr.c new file +248
-0@@ -0,0 +1,248 @@ +/* +* Object property helpers to operate on a pointer. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include "qemu/osdep.h" +#include "qom/object.h" +#include "qapi/visitor.h" + +static void property_get_uint8_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint8_t value = *(uint8_t *)opaque; +visit_type_uint8 (v, name, &value, errp); +} + +static void property_set_uint8_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint8_t *field = opaque; +uint8_t value; + +if (!visit_type_uint8 (v, name, &value, errp)) { +return ; + } + + *field = value; +} + +static void property_get_uint16_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value = *(uint16_t *)opaque; +visit_type_uint16 (v, name, &value, errp); +} + +static void property_set_uint16_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t *field = opaque; +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + + *field = value; +} + +static void property_get_uint32_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint32_t value = *(uint32_t *)opaque; +visit_type_uint32 (v, name, &value, errp); +} + +static void property_set_uint32_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint32_t *field = opaque; +uint32_t value; + +if (!visit_type_uint32 (v, name, &value, errp)) { +return ; + } + + *field = value; +} + +static void property_get_uint64_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque; +visit_type_uint64 (v, name, &value, errp); +} + +static void property_set_uint64_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t *field = opaque; +uint64_t value; + +if (!visit_type_uint64 (v, name, &value, errp)) { +return ; + } + + *field = value; +} + +ObjectProperty * +object_property_add_uint8_ptr (Object *obj,const char *name, +const uint8_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint8_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint8_ptr; + } + +return object_property_add (obj, name,"uint8" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_class_property_add_uint8_ptr (ObjectClass *klass,const char *name, +const uint8_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint8_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint8_ptr; + } + +return object_class_property_add (klass, name,"uint8" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_property_add_uint16_ptr (Object *obj,const char *name, +const uint16_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint16_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint16_ptr; + } + +return object_property_add (obj, name,"uint16" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_class_property_add_uint16_ptr (ObjectClass *klass,const char *name, +const uint16_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint16_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint16_ptr; + } + +return object_class_property_add (klass, name,"uint16" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_property_add_uint32_ptr (Object *obj,const char *name, +const uint32_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint32_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint32_ptr; + } + +return object_property_add (obj, name,"uint32" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_class_property_add_uint32_ptr (ObjectClass *klass,const char *name, +const uint32_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint32_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint32_ptr; + } + +return object_class_property_add (klass, name,"uint32" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_property_add_uint64_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint64_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint64_ptr; + } + +return object_property_add (obj, name,"uint64" , + getter, setter,NULL , (void *)v); +} + +ObjectProperty * +object_class_property_add_uint64_ptr (ObjectClass *klass,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_uint64_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_uint64_ptr; + } + +return object_class_property_add (klass, name,"uint64" , + getter, setter,NULL , (void *)v); +}qom/object.c +0
-240@@ -2673,246 +2673,6 @@ static char *object_get_type(Object *obj, Error **errp)return g_strdup (object_get_typename (obj)); } -static void property_get_uint8_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint8_t value = *(uint8_t *)opaque; -visit_type_uint8 (v, name, &value, errp); -} - -static void property_set_uint8_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint8_t *field = opaque; -uint8_t value; - -if (!visit_type_uint8 (v, name, &value, errp)) { -return ; - } - - *field = value; -} - -static void property_get_uint16_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint16_t value = *(uint16_t *)opaque; -visit_type_uint16 (v, name, &value, errp); -} - -static void property_set_uint16_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint16_t *field = opaque; -uint16_t value; - -if (!visit_type_uint16 (v, name, &value, errp)) { -return ; - } - - *field = value; -} - -static void property_get_uint32_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint32_t value = *(uint32_t *)opaque; -visit_type_uint32 (v, name, &value, errp); -} - -static void property_set_uint32_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint32_t *field = opaque; -uint32_t value; - -if (!visit_type_uint32 (v, name, &value, errp)) { -return ; - } - - *field = value; -} - -static void property_get_uint64_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint64_t value = *(uint64_t *)opaque; -visit_type_uint64 (v, name, &value, errp); -} - -static void property_set_uint64_ptr (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint64_t *field = opaque; -uint64_t value; - -if (!visit_type_uint64 (v, name, &value, errp)) { -return ; - } - - *field = value; -} - -ObjectProperty * -object_property_add_uint8_ptr (Object *obj,const char *name, -const uint8_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint8_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint8_ptr; - } - -return object_property_add (obj, name,"uint8" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_class_property_add_uint8_ptr (ObjectClass *klass,const char *name, -const uint8_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint8_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint8_ptr; - } - -return object_class_property_add (klass, name,"uint8" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_property_add_uint16_ptr (Object *obj,const char *name, -const uint16_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint16_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint16_ptr; - } - -return object_property_add (obj, name,"uint16" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_class_property_add_uint16_ptr (ObjectClass *klass,const char *name, -const uint16_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint16_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint16_ptr; - } - -return object_class_property_add (klass, name,"uint16" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_property_add_uint32_ptr (Object *obj,const char *name, -const uint32_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint32_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint32_ptr; - } - -return object_property_add (obj, name,"uint32" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_class_property_add_uint32_ptr (ObjectClass *klass,const char *name, -const uint32_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint32_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint32_ptr; - } - -return object_class_property_add (klass, name,"uint32" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_property_add_uint64_ptr (Object *obj,const char *name, -const uint64_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint64_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint64_ptr; - } - -return object_property_add (obj, name,"uint64" , - getter, setter,NULL , (void *)v); -} - -ObjectProperty * -object_class_property_add_uint64_ptr (ObjectClass *klass,const char *name, -const uint64_t *v, -ObjectPropertyFlags flags) -{ -ObjectPropertyAccessor *getter =NULL ; -ObjectPropertyAccessor *setter =NULL ; - -if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { - getter = property_get_uint64_ptr; - } - -if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { - setter = property_set_uint64_ptr; - } - -return object_class_property_add (klass, name,"uint64" , - getter, setter,NULL , (void *)v); -} - typedef struct { Object *target_obj; char *target_name;qom/meson.build +0
-0
qom/meson.build qom_ss.add(files( · line 9
Quoted 7 lines
qom/meson.build +1
-0@@ -3,6 +3,7 @@ qom_ss.add(files( 'container.c', 'object.c', 'object_interfaces.c', + 'object-property-ptr.c', 'qom-qobject.c', )) if have_system
Otherwise looks okay to me:
ATB,
Mark.
Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Quoted 10 lines · Mark Cave-Ayland
include/qom/object.h char *object_property_help(const char *name, const char *type, · line 2053
Quoted 7 lines
include/qom/object.h +5
-0@@ -2141,4 +2048,10 @@ char *object_property_help(const char *name, const char *type,G_DEFINE_AUTOPTR_CLEANUP_FUNC (Object, object_unref) +/* +* Object property ptr helpers cannot be included at the beginning of the +* file, because it depends on QOM definitions in current header. + */ +#include "qom/object-property-ptr.h" I wonder if possibly we might want to let the caller include the extra header? But I don't feel too strongly either way.
Yes, I didn't try to when drafting, but I also agree it's cleaner. It will need to update existing files (20 .c files) that used the api set. I'll do it if we can reach a consensus on the concept.
[...]
Quoted 3 lines
Otherwise looks okay to me:
Reviewed-by Mark Cave-Ayland <[email protected]>
Thanks,
Signature · 1 line
Peter Xu
PATCH v2 6/10 qom: Add object_property_add_bool_ptr()
In reply to Peter XuAdd a helper to set qom property via a bool pointer.
--- include/qom/object-property-ptr.h | 15 ++++++++++++ qom/object-property-ptr.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
include/qom/object-property-ptr.h +15 -0
@@ -16,6 +16,21 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_property_add_bool_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add a property of type 'bool' to the object. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty * +object_property_add_bool_ptr (Object *obj,const char *name,const bool *v, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to
qom/object-property-ptr.c +39 -0
@@ -7,6 +7,26 @@#include "qom/object.h" #include "qapi/visitor.h" +static void property_get_bool_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool value = *(bool *)opaque; +visit_type_bool (v, name, &value, errp); +} + +static void property_set_bool_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool *field = opaque; +bool value; + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + *field = value; +} +static void property_get_uint8_ptr (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -87,6 +107,25 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +ObjectProperty * +object_property_add_bool_ptr (Object *obj,const char *name, +const bool *v,ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_bool_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_bool_ptr; + } + +return object_property_add (obj, name,"bool" , + getter, setter,NULL , (void *)v); +} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,
Signature · 1 line
2.53.0
Re: [PATCH v2 06/10] qom: Add object_property_add_bool_ptr()
Quoted 3 lines · Peter Xu
Add a helper to set qom property via a bool pointer.
Signed-off-by Peter Xu <[email protected]>
Quoted 88 lines
--- include/qom/object-property-ptr.h | 15 ++++++++++++ qom/object-property-ptr.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)include/qom/object-property-ptr.h +15
-0@@ -16,6 +16,21 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_property_add_bool_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add a property of type 'bool' to the object. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty * +object_property_add_bool_ptr (Object *obj,const char *name,const bool *v, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to qom/object-property-ptr.c +39
-0@@ -7,6 +7,26 @@#include "qom/object.h" #include "qapi/visitor.h" +static void property_get_bool_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool value = *(bool *)opaque; +visit_type_bool (v, name, &value, errp); +} + +static void property_set_bool_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool *field = opaque; +bool value; + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + *field = value; +} +static void property_get_uint8_ptr (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {@@ -87,6 +107,25 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +ObjectProperty * +object_property_add_bool_ptr (Object *obj,const char *name, +const bool *v,ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_bool_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_bool_ptr; + } + +return object_property_add (obj, name,"bool" , + getter, setter,NULL , (void *)v); +} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,
Re: [PATCH v2 06/10] qom: Add object_property_add_bool_ptr()
In reply to Peter XuQuoted 81 lines · Peter Xu
Add a helper to set qom property via a bool pointer.
Signed-off-by Peter Xu <[email protected]>--- include/qom/object-property-ptr.h | 15 ++++++++++++ qom/object-property-ptr.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)include/qom/object-property-ptr.h +15
-0@@ -16,6 +16,21 @@ typedef enum {OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ |OBJ_PROP_FLAG_WRITE ), } ObjectPropertyFlags; +/** +* object_property_add_bool_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add a property of type 'bool' to the object. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty * +object_property_add_bool_ptr (Object *obj,const char *name,const bool *v, +ObjectPropertyFlags flags); +/** * object_property_add_uint8_ptr: * @obj: the object to add a property to qom/object-property-ptr.c +32
-0@@ -7,6 +7,26 @@#include "qom/object.h" #include "qapi/visitor.h" +static void property_get_bool_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool value = *(bool *)opaque; +visit_type_bool (v, name, &value, errp); +} + +static void property_set_bool_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool *field = opaque; +bool value; + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + *field = value; +} +static void property_get_uint8_ptr (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {@@ -87,6 +107,25 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +ObjectProperty * +object_property_add_bool_ptr (Object *obj,const char *name, +const bool *v,ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_bool_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) {
qom/object-property-ptr.c static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, · line 131
Quoted 10 lines
qom/object-property-ptr.c +7
-0+ setter = property_set_bool_ptr; + } + +return object_property_add (obj, name,"bool" , + getter, setter,NULL , (void *)v); +} +ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v,
ATB,
Mark.
PATCH v2 7/10 qom: Add object_property_add_size_ptr()
In reply to Peter XuAdd a helper to set qom property via a size pointer.
--- include/qom/object-property-ptr.h | 16 +++++++++++++ qom/object-property-ptr.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
include/qom/object-property-ptr.h +16 -0
@@ -115,4 +115,20 @@ ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,const uint64_t *v, ObjectPropertyFlags flags); +/** +* object_property_add_size_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add a property of type 'size' to the object. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty * +object_property_add_size_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags); +#endif
qom/object-property-ptr.c +40 -0
@@ -107,6 +107,26 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +static void property_get_size_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque; +visit_type_size (v, name, &value, errp); +} + +static void property_set_size_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t *field = opaque; +uint64_t value; + +if (!visit_type_size (v, name, &value, errp)) { +return ; + } + + *field = value; +} +ObjectProperty *object_property_add_bool_ptr (Object *obj,const char *name,const bool *v,ObjectPropertyFlags flags)
@@ -285,3 +305,23 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,return object_class_property_add (klass, name,"uint64" , getter, setter,NULL , (void *)v); } + +ObjectProperty * +object_property_add_size_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_size_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_size_ptr; + } + +return object_property_add (obj, name,"size" , + getter, setter,NULL , (void *)v); +}
Signature · 1 line
2.53.0
Re: [PATCH v2 07/10] qom: Add object_property_add_size_ptr()
Quoted 3 lines · Peter Xu
Add a helper to set qom property via a size pointer.
Signed-off-by Peter Xu <[email protected]>
Quoted 85 lines
--- include/qom/object-property-ptr.h | 16 +++++++++++++ qom/object-property-ptr.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)include/qom/object-property-ptr.h +16
-0@@ -115,4 +115,20 @@ ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,const uint64_t *v, ObjectPropertyFlags flags); +/** +* object_property_add_size_ptr: +* @obj: the object to add a property to +* @name: the name of the property +* @v: pointer to value +* @flags: bitwise-or'd ObjectPropertyFlags +* +* Add a property of type 'size' to the object. +* +* Returns: The newly added property on success, or %NULL on failure. +*/ +ObjectProperty * +object_property_add_size_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags); +#endif qom/object-property-ptr.c +40
-0@@ -107,6 +107,26 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +static void property_get_size_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value = *(uint64_t *)opaque; +visit_type_size (v, name, &value, errp); +} + +static void property_set_size_ptr (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t *field = opaque; +uint64_t value; + +if (!visit_type_size (v, name, &value, errp)) { +return ; + } + + *field = value; +} +ObjectProperty *object_property_add_bool_ptr (Object *obj,const char *name,const bool *v,ObjectPropertyFlags flags)@@ -285,3 +305,23 @@ object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,return object_class_property_add (klass, name,"uint64" , getter, setter,NULL , (void *)v); } + +ObjectProperty * +object_property_add_size_ptr (Object *obj,const char *name, +const uint64_t *v, +ObjectPropertyFlags flags) +{ +ObjectPropertyAccessor *getter =NULL ; +ObjectPropertyAccessor *setter =NULL ; + +if ((flags &OBJ_PROP_FLAG_READ ) ==OBJ_PROP_FLAG_READ ) { + getter = property_get_size_ptr; + } + +if ((flags &OBJ_PROP_FLAG_WRITE ) ==OBJ_PROP_FLAG_WRITE ) { + setter = property_set_size_ptr; + } + +return object_property_add (obj, name,"size" , + getter, setter,NULL , (void *)v); +}
PATCH v2 8/10 qom: Add object_property_add_*_ptr_def()
In reply to Peter XuAdd sister functions for existing pointer versions, to make it even easier to use by:
- always make properties to be rw-able
- allowing to specify default values
- no retcode needed (assert on failure, always)
--- include/qom/object-property-ptr.h | 28 +++++++++++++ qom/object-property-ptr.c | 67 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)
include/qom/object-property-ptr.h +28 -0
@@ -131,4 +131,32 @@ object_property_add_size_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); +/* +* Below are sister helpers of above, except that: +* +* (1) nothing is returned +* (2) always make the property to be both readable and writeable +* (3) allow setting default value +* +* Please refer to the sister functions for the documentation. +*/ +void +object_property_add_bool_ptr_def (Object *obj,const char *name, +const bool *v,bool def); +void +object_property_add_uint8_ptr_def (Object *obj,const char *name, +const uint8_t *v,uint8_t def); +void +object_property_add_uint16_ptr_def (Object *obj,const char *name, +const uint16_t *v,uint16_t def); +void +object_property_add_uint32_ptr_def (Object *obj,const char *name, +const uint32_t *v,uint32_t def); +void +object_property_add_uint64_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def); +void +object_property_add_size_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def); +#endif
qom/object-property-ptr.c +67 -0
70 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 08/10] qom: Add object_property_add_*_ptr_def()
Quoted 115 lines · Peter Xu
Add sister functions for existing pointer versions, to make it even easier to use by:
- always make properties to be rw-able
- allowing to specify default values
- no retcode needed (assert on failure, always)Signed-off-by Peter Xu <[email protected]>--- include/qom/object-property-ptr.h | 28 +++++++++++++ qom/object-property-ptr.c | 67 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)include/qom/object-property-ptr.h +28
-0@@ -131,4 +131,32 @@ object_property_add_size_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); +/* +* Below are sister helpers of above, except that: +* +* (1) nothing is returned +* (2) always make the property to be both readable and writeable +* (3) allow setting default value +* +* Please refer to the sister functions for the documentation. +*/ +void +object_property_add_bool_ptr_def (Object *obj,const char *name, +const bool *v,bool def); +void +object_property_add_uint8_ptr_def (Object *obj,const char *name, +const uint8_t *v,uint8_t def); +void +object_property_add_uint16_ptr_def (Object *obj,const char *name, +const uint16_t *v,uint16_t def); +void +object_property_add_uint32_ptr_def (Object *obj,const char *name, +const uint32_t *v,uint32_t def); +void +object_property_add_uint64_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def); +void +object_property_add_size_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def); +#endif qom/object-property-ptr.c +57
-0@@ -325,3 +325,70 @@ object_property_add_size_ptr(Object *obj, const char *name,return object_property_add (obj, name,"size" , getter, setter,NULL , (void *)v); } + +void +object_property_add_bool_ptr_def (Object *obj,const char *name, +const bool *v,bool def) +{ +ObjectProperty *prop; + + prop =object_property_add_bool_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_bool (prop, def); +} + + +void +object_property_add_uint8_ptr_def (Object *obj,const char *name, +const uint8_t *v,uint8_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint8_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} + +void +object_property_add_uint16_ptr_def (Object *obj,const char *name, +const uint16_t *v,uint16_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint16_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} + +void +object_property_add_uint32_ptr_def (Object *obj,const char *name, +const uint32_t *v,uint32_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint32_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} + +void +object_property_add_uint64_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint64_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} +
qom/object-property-ptr.c object_property_add_size_ptr(Object *obj, const char *name, · line 394
Quoted 10 lines
qom/object-property-ptr.c +10
-0+void +object_property_add_size_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_size_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +}
Re: [PATCH v2 08/10] qom: Add object_property_add_*_ptr_def()
In reply to Peter XuQuoted 115 lines · Peter Xu
Add sister functions for existing pointer versions, to make it even easier to use by:
- always make properties to be rw-able
- allowing to specify default values
- no retcode needed (assert on failure, always)Signed-off-by Peter Xu <[email protected]>--- include/qom/object-property-ptr.h | 28 +++++++++++++ qom/object-property-ptr.c | 67 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)include/qom/object-property-ptr.h +28
-0@@ -131,4 +131,32 @@ object_property_add_size_ptr(Object *obj, const char *name,const uint64_t *v, ObjectPropertyFlags flags); +/* +* Below are sister helpers of above, except that: +* +* (1) nothing is returned +* (2) always make the property to be both readable and writeable +* (3) allow setting default value +* +* Please refer to the sister functions for the documentation. +*/ +void +object_property_add_bool_ptr_def (Object *obj,const char *name, +const bool *v,bool def); +void +object_property_add_uint8_ptr_def (Object *obj,const char *name, +const uint8_t *v,uint8_t def); +void +object_property_add_uint16_ptr_def (Object *obj,const char *name, +const uint16_t *v,uint16_t def); +void +object_property_add_uint32_ptr_def (Object *obj,const char *name, +const uint32_t *v,uint32_t def); +void +object_property_add_uint64_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def); +void +object_property_add_size_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def); +#endif qom/object-property-ptr.c +57
-0@@ -325,3 +325,70 @@ object_property_add_size_ptr(Object *obj, const char *name,return object_property_add (obj, name,"size" , getter, setter,NULL , (void *)v); } + +void +object_property_add_bool_ptr_def (Object *obj,const char *name, +const bool *v,bool def) +{ +ObjectProperty *prop; + + prop =object_property_add_bool_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_bool (prop, def); +} + + +void +object_property_add_uint8_ptr_def (Object *obj,const char *name, +const uint8_t *v,uint8_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint8_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} + +void +object_property_add_uint16_ptr_def (Object *obj,const char *name, +const uint16_t *v,uint16_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint16_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} + +void +object_property_add_uint32_ptr_def (Object *obj,const char *name, +const uint32_t *v,uint32_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint32_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} + +void +object_property_add_uint64_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_uint64_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +} +
qom/object-property-ptr.c object_property_add_size_ptr(Object *obj, const char *name, · line 394
Quoted 10 lines
qom/object-property-ptr.c +10
-0+void +object_property_add_size_ptr_def (Object *obj,const char *name, +const uint64_t *v,uint64_t def) +{ +ObjectProperty *prop; + + prop =object_property_add_size_ptr (obj, name, v, +OBJ_PROP_FLAG_READWRITE ); +object_property_set_default_uint (prop, def); +}
Would these ever be required outside of the migration logic? I'm wondering if it might make sense to use macros within the migration code instead. This would at least prevent them from leaking elsewhere into QEMU until we figure out a long-term strategy.
ATB,
Mark.
PATCH v2 9/10 qom: Allow default values for instance properties
In reply to Peter XuObjectProperty allows default value settings via proper setup of prop->init() and prop->defval. It currently is only supported in class properties, not instance properties.
However, since QOM allows class and instance properties, it should also allow instance to add properties during instance_init() and allow the default values to be applied properly for this instance only.
Add the logic. It will be useful for all kinds of pointer based properties because pointers are normally not accessble in a class but only when an instance is available. This will be able to achieve similar function as what qdev properties have (which works by remembering offsets within a structure instead).
--- qom/object.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
qom/object.c +26 -0
@@ -487,6 +487,20 @@ static void object_class_property_init_all(Object *obj) } } +static void object_property_init_all (Object *obj) +{ +GHashTableIter iter; +gpointer key, val; + +g_hash_table_iter_init (&iter, obj->properties); +while (g_hash_table_iter_next (&iter, &key, &val)) { +ObjectProperty *prop = val; +if (prop->init) { + prop->init (obj, prop); + } + } +} +static void object_initialize_with_type (Object *obj,size_t size,TypeImpl *type) {type_initialize (type);
@@ -498,10 +512,22 @@ static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *typememset (obj,0 , type->instance_size); obj->class = type->class;object_ref (obj); +/* +* A few steps to initialize properties for the objects: +* +* (1) apply default values from class properties when available +* (2) invoke instance_init(), which may add per-instance properties, +* which may further contain default values +* (3) apply default values from instance properties when available +* +* instance_post_init() should happen at last, after the instance is +* fully initialized. +*/ object_class_property_init_all (obj); obj->properties =g_hash_table_new_full (g_str_hash, g_str_equal,NULL , object_property_free);object_init_with_type (obj, type); +object_property_init_all (obj);object_post_init_with_type (obj, type); }
Signature · 1 line
2.53.0
Re: [PATCH v2 09/10] qom: Allow default values for instance properties
Quoted 8 lines · Peter Xu
ObjectProperty allows default value settings via proper setup of
prop->init()andprop->defval. It currently is only supported in class properties, not instance properties.However, since QOM allows class and instance properties, it should also allow instance to add properties during
instance_init()and allow the default values to be applied properly for this instance only.
Quoted 5 lines
Add the logic. It will be useful for all kinds of pointer based properties because pointers are normally not accessble in a class but only when an instance is available. This will be able to achieve similar function as what qdev properties have (which works by remembering offsets within a structure instead).
Again, I don't think we should be adding more features to the instance properties concept, as new code should use class level properties.
Quoted 5 lines
Signed-off-by Peter Xu <[email protected]>--- qom/object.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
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 v2 09/10] qom: Allow default values for instance properties
In reply to Peter XuQuoted 7 lines · Peter Xu
ObjectProperty allows default value settings via proper setup of
prop->init()andprop->defval. It currently is only supported in class properties, not instance properties.However, since QOM allows class and instance properties, it should also allow instance to add properties during
instance_init()and allow the default values to be applied properly for this instance only.
Thinking back to the earlier patches, a question that has come up before is whether we should require all properties to be class properties? IIRC one of the motivations for this move was to allow schema introspection, but I don't immediately have a reference to the original discussion.
Quoted 48 lines
Add the logic. It will be useful for all kinds of pointer based properties because pointers are normally not accessble in a class but only when an instance is available. This will be able to achieve similar function as what qdev properties have (which works by remembering offsets within a structure instead).
Signed-off-by Peter Xu <[email protected]>--- qom/object.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)qom/object.c +22
-0@@ -487,6 +487,20 @@ static void object_class_property_init_all(Object *obj) } } +static void object_property_init_all (Object *obj) +{ +GHashTableIter iter; +gpointer key, val; + +g_hash_table_iter_init (&iter, obj->properties); +while (g_hash_table_iter_next (&iter, &key, &val)) { +ObjectProperty *prop = val; +if (prop->init) { + prop->init (obj, prop); + } + } +} +static void object_initialize_with_type (Object *obj,size_t size,TypeImpl *type) {type_initialize (type);@@ -498,10 +512,22 @@ static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *typememset (obj,0 , type->instance_size); obj->class = type->class;object_ref (obj); +/* +* A few steps to initialize properties for the objects: +* +* (1) apply default values from class properties when available +* (2) invoke instance_init(), which may add per-instance properties, +* which may further contain default values +* (3) apply default values from instance properties when available +*
qom/object.c static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *type · line 532
Quoted 10 lines
qom/object.c +4
-0+* instance_post_init() should happen at last, after the instance is +* fully initialized. +*/ object_class_property_init_all (obj); obj->properties =g_hash_table_new_full (g_str_hash, g_str_equal,NULL , object_property_free);object_init_with_type (obj, type); +object_property_init_all (obj);object_post_init_with_type (obj, type); }
Nice!
ATB,
Mark.
Re: [PATCH v2 09/10] qom: Allow default values for instance properties
Quoted 6 lines · Mark Cave-Ayland
Quoted 4 lines · Peter Xu
ObjectProperty allows default value settings via proper setup of
prop->init()andprop->defval. It currently is only supported in class properties, not instance properties.
Quoted 6 lines
Quoted 3 lines
However, since QOM allows class and instance properties, it should also allow instance to add properties during
instance_init()and allow the default values to be applied properly for this instance only.Thinking back to the earlier patches, a question that has come up before is whether we should require all properties to be class properties?
Ideally yes, but we have the classic QEMU problem of a big pile of technical debt that would need converting and always more interesting things to work on.
Most is a boring mechanical task, but there are some awkward edge cases around dynamically added properties.
Quoted 3 lines
IIRC one of
the motivations for this move was to allow schema introspection, but I don't immediately have a reference to the original discussion.
Better supporting introspection was the original key goal, but also reducing memory footprint for classes which have 100s or 1000s of instances registering the same props over & over. Introspection against the class means we trivially avoid risk of side-effects from instantiating objects and not completing their realization.
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 v2 09/10] qom: Allow default values for instance properties
Quoted 14 lines · Daniel P. Berrangé
Quoted 6 lines · Mark Cave-Ayland
Quoted 4 lines · Peter Xu
ObjectProperty allows default value settings via proper setup of
prop->init()andprop->defval. It currently is only supported in class properties, not instance properties.Quoted 6 lines
Quoted 3 lines
However, since QOM allows class and instance properties, it should also allow instance to add properties during
instance_init()and allow the default values to be applied properly for this instance only.Thinking back to the earlier patches, a question that has come up before is whether we should require all properties to be class properties?
Quoted 6 lines
Ideally yes, but we have the classic QEMU problem of a big pile of technical debt that would need converting and always more interesting things to work on.
Most is a boring mechanical task, but there are some awkward edge cases around dynamically added properties.
That's true, although we already have to handle this given a codebase with the history of QEMU. The most important part is often to take the decision and enforce it.
For example, we can take the decision today that we all new properties must be class properties but if we do, then we also need to ensure that all code reviewers are aware of this and enforce it.
That leaves the issue of the existing code. Our normal acceptance criteria is does it pass the regression/functional tests, so I don't see why we can't aim for that here?
Back to this particular patch, if we want to make the decision that class properties are the way forward we can at least ensure that the patches is written in a way such that object property support can be easily removed later.
Quoted 9 lines
Quoted 3 lines
IIRC one of
the motivations for this move was to allow schema introspection, but I don't immediately have a reference to the original discussion.Better supporting introspection was the original key goal, but also reducing memory footprint for classes which have 100s or 1000s of instances registering the same props over & over. Introspection against the class means we trivially avoid risk of side-effects from instantiating objects and not completing their realization.
That does sounds like another compelling reason :)
ATB,
Mark.
PATCH v2 10/10 migration: Switch to TYPE_OBJECT with object properties
In reply to Peter XuThe migration object used to depend on TYPE_DEVICE due to:
- Usage of qdev properties
- Apply compat properties and global properties
This patch re-based the object to TYPE_OBJECT with the changes:
- Switch to object properties API
- Manually apply both compat and global properties in post_init()
Note that to avoid too many property getter/setter helpers, this patch used the object_property_add_*_ptr_def() APIs so that an pointer is passed to bind to the property. Such API is used for most of the conversions.
After patch, the migration object initializes instance properties within its instance_init() callback, in migrate_params_init().
One side effect of this change is, since we switched to a loop to add all capabilities, the name of the properties representing a migration capability may chance from previously hard-coded ones (many with x-). It's fine since it's only used in -global so it's only for debugging.
Similarly, I removed "x-" from other properites that used to start with "x-" but actually are not experimental.
After the whole conversion, we don't need migration_properties or the count anymore, hence can be removed. While at it, we can also remove two DEFINE_PROP*() API that only migration uses (DEFINE_PROP_STR_OR_NULL, and DEFINE_PROP_MIG_CAP).
--- migration/options.h | 8 +- migration/migration.c | 35 ++- migration/options.c | 526 ++++++++++++++++++++++++++---------------- 3 files changed, 351 insertions(+), 218 deletions(-)
migration/options.h +2 -6
@@ -18,11 +18,6 @@#include "hw/core/qdev-properties-system.h" #include "migration/client-options.h" -/* migration properties */ - -extern const Property migration_properties[]; -extern const size_t migration_properties_count; -/* capabilities */ bool migrate_auto_converge (void );
@@ -92,6 +87,7 @@ uint64_t migrate_rdma_chunk_size(void);/* parameters helpers */ bool migrate_params_check (MigrationParameters *params,Error **errp); -void migrate_params_init (MigrationParameters *params); +void migrate_params_init (MigrationState *s);void migrate_tls_opts_free (MigrationParameters *params); +#endif
migration/migration.c +16 -19
@@ -3964,15 +3964,6 @@ 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); -} -static void migration_instance_finalize (Object *obj) {MigrationState *ms =MIGRATION (obj);
@@ -4001,7 +3992,7 @@ static void migration_instance_init(Object *obj)qemu_event_init (&ms->pause_event, false);qemu_mutex_init (&ms->error_mutex); -migrate_params_init (&ms->parameters); +migrate_params_init (ms);qemu_sem_init (&ms->postcopy_pause_sem,0 );qemu_sem_init (&ms->rp_state.rp_sem,0 );
@@ -4028,20 +4019,26 @@ 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: +* +* (1) machine compat properties +* (2) -global settings in cmdlines * -* TODO: Make this TYPE_OBJECT once QOM provides something like -* TYPE_DEVICE's "-global" properties. +* Need to be applied in order so (2) takes precedence over (1). */ - .parent =TYPE_DEVICE , - .class_init = migration_class_init, +object_apply_compat_props (obj); +object_apply_global_props (obj,global_props (), &error_fatal); +} + +static const TypeInfo migration_type = { + .name =TYPE_MIGRATION , + .parent =TYPE_OBJECT , .instance_size =sizeof (MigrationState), .instance_init = migration_instance_init, + .instance_post_init = migration_instance_post_init, .instance_finalize = migration_instance_finalize, };
migration/options.c +333 -193
565 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 10/10] migration: Switch to TYPE_OBJECT with object properties
Quoted 17 lines · Peter Xu
The migration object used to depend on
TYPE_DEVICEdue to:- Usage of qdev properties
- Apply compat properties and global propertiesThis patch re-based the object to
TYPE_OBJECTwith the changes:- Switch to object properties API
- Manually apply both compat and global properties inpost_init()Note that to avoid too many property getter/setter helpers, this patch used the object_property_add_*_ptr_def() APIs so that an pointer is passed to bind to the property. Such API is used for most of the conversions.
After patch, the migration object initializes instance properties within its
instance_init()callback, inmigrate_params_init().
Quoted 7 lines
One side effect of this change is, since we switched to a loop to add all capabilities, the name of the properties representing a migration capability may chance from previously hard-coded ones (many with x-). It's fine since it's only used in -global so it's only for debugging.
Similarly, I removed "x-" from other properites that used to start with "x-" but actually are not experimental.
Mixing such a change into a refactoring commit is bad practice, can you keep property changes separated.
Quoted 72 lines
After the whole conversion, we don't need
migration_propertiesor the count anymore, hence can be removed. While at it, we can also remove two DEFINE_PROP*() API that only migration uses (DEFINE_PROP_STR_OR_NULL, andDEFINE_PROP_MIG_CAP).Signed-off-by Peter Xu <[email protected]>--- migration/options.h | 8 +- migration/migration.c | 35 ++- migration/options.c | 526 ++++++++++++++++++++++++++---------------- 3 files changed, 351 insertions(+), 218 deletions(-)migration/options.c +40
-10@@ -54,7 +54,7 @@ +static void migration_object_init_props_bool (MigrationState *s) { -const Property *prop = opaque; -StrOrNull **ptr =object_field_prop_ptr (obj, prop); -StrOrNull *str_or_null = *ptr; +Object *obj =OBJECT (s); +int i; -/* -* The property should never be NULL because it's part of -* s->parameters and a default value is always set by qdev. It -* should also never be QNULL as the setter doesn't allow it. -*/ -assert (str_or_null && str_or_null->type !=QTYPE_QNULL ); -visit_type_str (v, name, &str_or_null->u.s, errp); +struct MigPropBool { +const char *name; +void *ptr; +bool defvar; + } bool_list[] = { + { +"store-global-state" , + &s->store_global_state, + true, + }, + { +"send-configuration" , + &s->send_configuration, + true, + }, + { +"send-section-footer" , + &s->send_section_footer, + true, + }, + { +"send-switchover-start" , + &s->send_switchover_start, + true, + }, + { +"x-preempt-pre-7-2" , + &s->preempt_pre_7_2, + false, + }, + { +"x-cpu-throttle-tailslow" , + &s->parameters.cpu_throttle_tailslow, + false, + }, + { +"multifd-clean-tls-termination" ,
migration/options.c line 139
Quoted 10 lines
migration/options.c +10
-0+ &s->multifd_clean_tls_termination, + true, + }, + { +"multifd-flush-after-each-section" , + &s->multifd_flush_after_each_section, + false, + }, + }; +struct MigPropBool *prop;
This approach to declaring properties is pretty unpleasant to follow IMHO. Being a custom different approach from every other object impl is not a good thing.
migration/options.c line 145
Quoted 6 lines
migration/options.c +6
-0+ +for (i =0 ; i <ARRAY_SIZE (bool_list); i++) { + prop = &bool_list[i]; +object_property_add_bool_ptr_def (obj, prop->name, + prop->ptr, prop->defvar); + }
Using instance level properties is the old way to do things, it is preferred to use class level properties instead.
This means you can't use the "ptr" concept to directly reference the instance fields and have to provide setters / getters explicitly instead, but as you've shown with the TLS properties, a macro can make it simple to define the repetitive getters/setters.
Quoted 13 lines
migration/options.c +13
-0+static void migration_object_init_props_enum (MigrationState *s) +{ +Object *obj =OBJECT (s); +ObjectProperty *prop; + + prop =object_property_add_enum (obj,"multifd-compression" , +"MultiFDCompression" , + &MultiFDCompression_lookup, + mig_prop_multifd_compression_get, + mig_prop_multifd_compression_set); +object_property_set_default_str (prop,DEFAULT_MIGRATE_MULTIFD_COMPRESSION ); + + prop = object_property_add_enum(obj, "mode", "MigMode", &MigMode_lookup,
migration/options.c line 420
Quoted 10 lines
migration/options.c +10
-0+ mig_prop_mode_get, mig_prop_mode_set); +object_property_set_default_str (prop,"normal" ); + + prop =object_property_add_enum (obj,"zero-page-detection" , +"ZeroPageDetection" , + &ZeroPageDetection_lookup, + mig_prop_zero_page_detection_get, + mig_prop_zero_page_detection_set); +object_property_set_default_str (prop,"multifd" ); +}
Perhaps I'm missing something, but I'm not seeing the point in using the set_default methods - in fact I'm not really sure why they exist in QOM at all.
I'd expect all defaults to be set in the instance _init method. ie why isn't this done as:
void migrate_params_init(MigrationState *s)
{
s->parameters.mode = MIG_MODE_NORMAL;
s->parameters.zero_page_detection = ZERO_PAGE_DETECTION_MULTIFD;
.... all other defaults...
}migration/options.c line 432
Quoted 12 lines
migration/options.c +12
-0+ +static void migration_object_init_properties (MigrationState *s) +{ +migration_object_init_props_bool (s); +migration_object_init_props_uint8 (s); +migration_object_init_props_uint32 (s); +migration_object_init_props_uint64 (s); +migration_object_init_props_size (s); +migration_object_init_props_caps (s); +migration_object_init_props_tls (s); +migration_object_init_props_enum (s); +}
...and class properties be registered in migrate_params_class_init() and the grouping per type isn't helpful IMHO, just put all the object_class_property_add calls inline in one place.
Quoted 19 lines
bool
migrate_auto_converge(void)
{migration/options.c +3
-2@@ -1107,9 +1246,10 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)return params; } -void migrate_params_init (MigrationParameters *params) +void migrate_params_init (MigrationState *s) { -migrate_mark_all_params_present (params); +migration_object_init_properties (s); +migrate_mark_all_params_present (&s->parameters); }static void migrate_post_update_params (MigrationParameters *new,Error **errp)Signature · 1 line
2.53.0
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 v2 10/10] migration: Switch to TYPE_OBJECT with object properties
Quoted 23 lines · Daniel P. Berrangé
Quoted 22 lines · Peter Xu
The migration object used to depend on
TYPE_DEVICEdue to:- Usage of qdev properties
- Apply compat properties and global propertiesThis patch re-based the object to
TYPE_OBJECTwith the changes:- Switch to object properties API
- Manually apply both compat and global properties inpost_init()Note that to avoid too many property getter/setter helpers, this patch used the object_property_add_*_ptr_def() APIs so that an pointer is passed to bind to the property. Such API is used for most of the conversions.
After patch, the migration object initializes instance properties within its
instance_init()callback, inmigrate_params_init().One side effect of this change is, since we switched to a loop to add all capabilities, the name of the properties representing a migration capability may chance from previously hard-coded ones (many with x-). It's fine since it's only used in -global so it's only for debugging.
Quoted 5 lines
Quoted 2 lines
Similarly, I removed "x-" from other properites that used to start with "x-" but actually are not experimental.
Mixing such a change into a refactoring commit is bad practice, can you keep property changes separated.
Sure.
Quoted 84 lines
Quoted 73 lines
After the whole conversion, we don't need
migration_propertiesor the count anymore, hence can be removed. While at it, we can also remove two DEFINE_PROP*() API that only migration uses (DEFINE_PROP_STR_OR_NULL, andDEFINE_PROP_MIG_CAP).Signed-off-by Peter Xu <[email protected]>--- migration/options.h | 8 +- migration/migration.c | 35 ++- migration/options.c | 526 ++++++++++++++++++++++++++---------------- 3 files changed, 351 insertions(+), 218 deletions(-)migration/options.c +40
-10@@ -54,7 +54,7 @@ +static void migration_object_init_props_bool (MigrationState *s) { -const Property *prop = opaque; -StrOrNull **ptr =object_field_prop_ptr (obj, prop); -StrOrNull *str_or_null = *ptr; +Object *obj =OBJECT (s); +int i; -/* -* The property should never be NULL because it's part of -* s->parameters and a default value is always set by qdev. It -* should also never be QNULL as the setter doesn't allow it. -*/ -assert (str_or_null && str_or_null->type !=QTYPE_QNULL ); -visit_type_str (v, name, &str_or_null->u.s, errp); +struct MigPropBool { +const char *name; +void *ptr; +bool defvar; + } bool_list[] = { + { +"store-global-state" , + &s->store_global_state, + true, + }, + { +"send-configuration" , + &s->send_configuration, + true, + }, + { +"send-section-footer" , + &s->send_section_footer, + true, + }, + { +"send-switchover-start" , + &s->send_switchover_start, + true, + }, + { +"x-preempt-pre-7-2" , + &s->preempt_pre_7_2, + false, + }, + { +"x-cpu-throttle-tailslow" , + &s->parameters.cpu_throttle_tailslow, + false, + }, + { +"multifd-clean-tls-termination" ,migration/options.c line 139
Quoted 10 lines
migration/options.c +10
-0+ &s->multifd_clean_tls_termination, + true, + }, + { +"multifd-flush-after-each-section" , + &s->multifd_flush_after_each_section, + false, + }, + }; +struct MigPropBool *prop;
Quoted 3 lines
This approach to declaring properties is pretty unpleasant to follow IMHO. Being a custom different approach from every other object impl is not a good thing.
[I asked this question elsewhere, I'll keep the discussion there]
Quoted 8 lines
migration/options.c line 145
Quoted 7 lines
migration/options.c +6
-0+ +for (i =0 ; i <ARRAY_SIZE (bool_list); i++) { + prop = &bool_list[i]; +object_property_add_bool_ptr_def (obj, prop->name, + prop->ptr, prop->defvar); + }
Quoted 7 lines
Using instance level properties is the old way to do things, it is preferred to use class level properties instead.
This means you can't use the "ptr" concept to directly reference the instance fields and have to provide setters / getters explicitly instead, but as you've shown with the TLS properties, a macro can make it simple to define the repetitive getters/setters.
If pointer is unwanted, I can switch to some more macro magic. But since this series got rewrote the 3rd time.. I'll make sure it's extremely required before doing it..
Quoted 31 lines
Quoted 13 lines
migration/options.c +13
-0+static void migration_object_init_props_enum (MigrationState *s) +{ +Object *obj =OBJECT (s); +ObjectProperty *prop; + + prop =object_property_add_enum (obj,"multifd-compression" , +"MultiFDCompression" , + &MultiFDCompression_lookup, + mig_prop_multifd_compression_get, + mig_prop_multifd_compression_set); +object_property_set_default_str (prop,DEFAULT_MIGRATE_MULTIFD_COMPRESSION ); + + prop = object_property_add_enum(obj, "mode", "MigMode", &MigMode_lookup,migration/options.c line 420
Quoted 10 lines
migration/options.c +10
-0+ mig_prop_mode_get, mig_prop_mode_set); +object_property_set_default_str (prop,"normal" ); + + prop =object_property_add_enum (obj,"zero-page-detection" , +"ZeroPageDetection" , + &ZeroPageDetection_lookup, + mig_prop_zero_page_detection_get, + mig_prop_zero_page_detection_set); +object_property_set_default_str (prop,"multifd" ); +}Perhaps I'm missing something, but I'm not seeing the point in using the
set_defaultmethods - in fact I'm not really sure why they exist in QOM at all.I'd expect all defaults to be set in the instance
_initmethod. ie why isn't this done as:
Quoted 6 lines
void migrate_params_init(MigrationState *s)
{
s->parameters.mode = MIG_MODE_NORMAL;
s->parameters.zero_page_detection = ZERO_PAGE_DETECTION_MULTIFD;
.... all other defaults...
}Yes frankly I asked myself the same question when looking at this.
I still saw quite some defvar references, type_print_class_properties() can be one example where we dump help message with default values but without the need to apply. I didn't check the rest. If the concept exists and if we will be using qobj props, IMHO sticking with it is defintely safer so that all qom future defvar changes will apply and it'll just work there.
Quoted 18 lines
Quoted 4 lines
migration/options.c +2
-0+ +static void migration_object_init_properties (MigrationState *s)migration/options.c line 432
Quoted 10 lines
migration/options.c +10
-0+{ +migration_object_init_props_bool (s); +migration_object_init_props_uint8 (s); +migration_object_init_props_uint32 (s); +migration_object_init_props_uint64 (s); +migration_object_init_props_size (s); +migration_object_init_props_caps (s); +migration_object_init_props_tls (s); +migration_object_init_props_enum (s); +}...and class properties be registered in
migrate_params_class_init()and the grouping per type isn't helpful IMHO, just put all theobject_class_property_addcalls inline in one place.
I still want to avoid long functions, one way or another.
Hopefully it makes sense when I have those arrays to init different type of props it makes sense to split with this, but I'm open to other way to split. I still want to not make it a extremely long function.
Thanks,
Quoted 28 lines
Quoted 20 lines
bool
migrate_auto_converge(void)
{migration/options.c +3
-2@@ -1107,9 +1246,10 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)return params; } -void migrate_params_init (MigrationParameters *params) +void migrate_params_init (MigrationState *s) { -migrate_mark_all_params_present (params); +migration_object_init_properties (s); +migrate_mark_all_params_present (&s->parameters); }static void migrate_post_update_params (MigrationParameters *new,Error **errp)Signature · 1 line
2.53.0With regards,
DanielSignature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Signature · 1 line
Peter Xu
Re: [PATCH v2 10/10] migration: Switch to TYPE_OBJECT with object properties
Quoted 207 lines · Peter Xu
Quoted 23 lines · Daniel P. Berrangé
Quoted 22 lines · Peter Xu
The migration object used to depend on
TYPE_DEVICEdue to:- Usage of qdev properties
- Apply compat properties and global propertiesThis patch re-based the object to
TYPE_OBJECTwith the changes:- Switch to object properties API
- Manually apply both compat and global properties inpost_init()Note that to avoid too many property getter/setter helpers, this patch used the object_property_add_*_ptr_def() APIs so that an pointer is passed to bind to the property. Such API is used for most of the conversions.
After patch, the migration object initializes instance properties within its
instance_init()callback, inmigrate_params_init().One side effect of this change is, since we switched to a loop to add all capabilities, the name of the properties representing a migration capability may chance from previously hard-coded ones (many with x-). It's fine since it's only used in -global so it's only for debugging.
Quoted 5 lines
Quoted 2 lines
Similarly, I removed "x-" from other properites that used to start with "x-" but actually are not experimental.
Mixing such a change into a refactoring commit is bad practice, can you keep property changes separated.
Sure.
Quoted 84 lines
Quoted 73 lines
After the whole conversion, we don't need
migration_propertiesor the count anymore, hence can be removed. While at it, we can also remove two DEFINE_PROP*() API that only migration uses (DEFINE_PROP_STR_OR_NULL, andDEFINE_PROP_MIG_CAP).Signed-off-by Peter Xu <[email protected]>--- migration/options.h | 8 +- migration/migration.c | 35 ++- migration/options.c | 526 ++++++++++++++++++++++++++---------------- 3 files changed, 351 insertions(+), 218 deletions(-)migration/options.c +40
-10@@ -54,7 +54,7 @@ +static void migration_object_init_props_bool (MigrationState *s) { -const Property *prop = opaque; -StrOrNull **ptr =object_field_prop_ptr (obj, prop); -StrOrNull *str_or_null = *ptr; +Object *obj =OBJECT (s); +int i; -/* -* The property should never be NULL because it's part of -* s->parameters and a default value is always set by qdev. It -* should also never be QNULL as the setter doesn't allow it. -*/ -assert (str_or_null && str_or_null->type !=QTYPE_QNULL ); -visit_type_str (v, name, &str_or_null->u.s, errp); +struct MigPropBool { +const char *name; +void *ptr; +bool defvar; + } bool_list[] = { + { +"store-global-state" , + &s->store_global_state, + true, + }, + { +"send-configuration" , + &s->send_configuration, + true, + }, + { +"send-section-footer" , + &s->send_section_footer, + true, + }, + { +"send-switchover-start" , + &s->send_switchover_start, + true, + }, + { +"x-preempt-pre-7-2" , + &s->preempt_pre_7_2, + false, + }, + { +"x-cpu-throttle-tailslow" , + &s->parameters.cpu_throttle_tailslow, + false, + }, + { +"multifd-clean-tls-termination" ,migration/options.c
Quoted 10 lines
migration/options.c +10
-0+ &s->multifd_clean_tls_termination, + true, + }, + { +"multifd-flush-after-each-section" , + &s->multifd_flush_after_each_section, + false, + }, + }; +struct MigPropBool *prop;Quoted 3 lines
This approach to declaring properties is pretty unpleasant to follow IMHO. Being a custom different approach from every other object impl is not a good thing.
[I asked this question elsewhere, I'll keep the discussion there]
Quoted 8 lines
migration/options.c
Quoted 7 lines
migration/options.c +6
-0+ +for (i =0 ; i <ARRAY_SIZE (bool_list); i++) { + prop = &bool_list[i]; +object_property_add_bool_ptr_def (obj, prop->name, + prop->ptr, prop->defvar); + }Quoted 7 lines
Using instance level properties is the old way to do things, it is preferred to use class level properties instead.
This means you can't use the "ptr" concept to directly reference the instance fields and have to provide setters / getters explicitly instead, but as you've shown with the TLS properties, a macro can make it simple to define the repetitive getters/setters.
If pointer is unwanted, I can switch to some more macro magic. But since this series got rewrote the 3rd time.. I'll make sure it's extremely required before doing it..
Quoted 31 lines
Quoted 13 lines
migration/options.c +13
-0+static void migration_object_init_props_enum (MigrationState *s) +{ +Object *obj =OBJECT (s); +ObjectProperty *prop; + + prop =object_property_add_enum (obj,"multifd-compression" , +"MultiFDCompression" , + &MultiFDCompression_lookup, + mig_prop_multifd_compression_get, + mig_prop_multifd_compression_set); +object_property_set_default_str (prop,DEFAULT_MIGRATE_MULTIFD_COMPRESSION ); + + prop = object_property_add_enum(obj, "mode", "MigMode", &MigMode_lookup,migration/options.c
Quoted 10 lines
migration/options.c +10
-0+ mig_prop_mode_get, mig_prop_mode_set); +object_property_set_default_str (prop,"normal" ); + + prop =object_property_add_enum (obj,"zero-page-detection" , +"ZeroPageDetection" , + &ZeroPageDetection_lookup, + mig_prop_zero_page_detection_get, + mig_prop_zero_page_detection_set); +object_property_set_default_str (prop,"multifd" ); +}Perhaps I'm missing something, but I'm not seeing the point in using the
set_defaultmethods - in fact I'm not really sure why they exist in QOM at all.I'd expect all defaults to be set in the instance
_initmethod. ie why isn't this done as:Quoted 6 lines
void migrate_params_init(MigrationState *s) { s->parameters.mode = MIG_MODE_NORMAL; s->parameters.zero_page_detection = ZERO_PAGE_DETECTION_MULTIFD; .... all other defaults... }Yes frankly I asked myself the same question when looking at this.
I still saw quite some defvar references,
type_print_class_properties()can be one example where we dump help message with default values but without the need to apply. I didn't check the rest. If the concept exists and if we will be using qobj props, IMHO sticking with it is defintely safer so that all qom future defvar changes will apply and it'll just work there.Quoted 18 lines
Quoted 4 lines
migration/options.c +2
-0+ +static void migration_object_init_properties (MigrationState *s)migration/options.c
Quoted 10 lines
migration/options.c +10
-0+{ +migration_object_init_props_bool (s); +migration_object_init_props_uint8 (s); +migration_object_init_props_uint32 (s); +migration_object_init_props_uint64 (s); +migration_object_init_props_size (s); +migration_object_init_props_caps (s); +migration_object_init_props_tls (s); +migration_object_init_props_enum (s); +}...and class properties be registered in
migrate_params_class_init()and the grouping per type isn't helpful IMHO, just put all theobject_class_property_addcalls inline in one place.
Quoted 6 lines
I still want to avoid long functions, one way or another.
Hopefully it makes sense when I have those arrays to init different type of props it makes sense to split with this, but I'm open to other way to split. I still want to not make it a extremely long function.
I see why you did it that way, it's mostly a limitation of the object code in that it requires the type of the default value only to convert it to a QObject internally. IMO, this is backwards, the object.c code should take the QObject and let the caller do the conversion.
I rewrote this part of the code using a ObjectProperties object as intermediary, instead of MigProp*. I think this looks easier to parse, although it's longer.
-->8--
From a6529d119d25ecc00f92686e2cddf1d81dc43183 Mon Sep 17 00:00:00 2001
From: Fabiano Rosas <[email protected]>
Date: Wed, 10 Jun 2026 16:49:52 -0300
Subject: [PATCH] poc
--- migration/options.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)
migration/options.c +114 -0
@@ -90,6 +90,120 @@#define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1/* MB/s */ #define DEFAULT_MIGRATE_X_RDMA_CHUNK_SIZE MiB +#define defstr (def) QOBJECT(qstring_from_str((const char *)def)) +#define defbool (def) QOBJECT(qbool_from_bool((bool)def)) +#define defint (def) QOBJECT(qnum_from_int((int64_t)def)) +#define defuint (def) QOBJECT(qnum_from_uint(def)) + +#define defuint8 defuint +#define defuint16 defuint +#define defuint32 defuint +#define defuint64 defuint +#define defenum defstr +#define defStrOrNull defstr +#define defMigMode defenum +#define defMultiFDCompression defenum +#define defZeroPageDetection defenum + +#define DEFPROP_PTR_ACCESSOR (_t) \ + static void property_visit_type_##_t(Object *obj, Visitor *v, \ + const char *name, void *opaque, \ + Error **errp) \ + { \ + visit_type_##_t(v, name, opaque, errp); \ + } \ + \ + static inline ObjectProperty prop_##_t(const char *name, void *opaque, \ + uint64_t def) \ + { \ + return (ObjectProperty) { \ + .name = (char *)name, \ + .type = (char *)"##_t", \ + .opaque = opaque, \ + .get = property_visit_type_##_t, \ + .set = property_visit_type_##_t, \ + .defval = def##_t(def), \ + }; \ + } \ + +DEFPROP_PTR_ACCESSOR (str); +DEFPROP_PTR_ACCESSOR (bool); +DEFPROP_PTR_ACCESSOR (int); +DEFPROP_PTR_ACCESSOR (uint8); +DEFPROP_PTR_ACCESSOR (uint16); +DEFPROP_PTR_ACCESSOR (uint32); +DEFPROP_PTR_ACCESSOR (uint64); +DEFPROP_PTR_ACCESSOR (StrOrNull); +DEFPROP_PTR_ACCESSOR (MigMode); +DEFPROP_PTR_ACCESSOR (MultiFDCompression); +DEFPROP_PTR_ACCESSOR (ZeroPageDetection); + +static void migration_object_init_properties (MigrationState *s) +{ +Object *obj =OBJECT (s); +ObjectProperty props_list[] = { +prop_bool ("store-global-state" , &s->store_global_state, true), +prop_bool ("send-configuration" , &s->send_configuration, true), +prop_bool ("send-section-footer" , &s->send_section_footer, true), +prop_bool ("send-switchover-start" , &s->send_switchover_start, true), +prop_bool ("x-preempt-pre-7-2" , &s->preempt_pre_7_2, false), +prop_bool ("x-cpu-throttle-tailslow" , &s->parameters.cpu_throttle_tailslow, false), +prop_bool ("multifd-clean-tls-termination" , &s->multifd_clean_tls_termination, true), +prop_bool ("multifd-flush-after-each-section" , &s->multifd_flush_after_each_section, false), + +prop_uint8 ("clear-bitmap-shift" , &s->clear_bitmap_shift,CLEAR_BITMAP_SHIFT_DEFAULT ), +prop_uint8 ("throttle-trigger-threshold" , &s->parameters.throttle_trigger_threshold,DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD ), +prop_uint8 ("cpu-throttle-initial" , &s->parameters.cpu_throttle_initial,DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL ), +prop_uint8 ("cpu-throttle-increment" , &s->parameters.cpu_throttle_increment,DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT ), +prop_uint8 ("multifd-channels" , &s->parameters.multifd_channels,DEFAULT_MIGRATE_MULTIFD_CHANNELS ), +prop_uint8 ("multifd-zlib-level" , &s->parameters.multifd_zlib_level,DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL ), +prop_uint8 ("multifd-qatzip-level" , &s->parameters.multifd_qatzip_level,DEFAULT_MIGRATE_MULTIFD_QATZIP_LEVEL ), +prop_uint8 ("multifd-zstd-level" , &s->parameters.multifd_zstd_level,DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL ), +prop_uint8 ("max-cpu-throttle" , &s->parameters.max_cpu_throttle,DEFAULT_MIGRATE_MAX_CPU_THROTTLE ), + +prop_uint32 ("x-checkpoint-delay" , &s->parameters.x_checkpoint_delay,DEFAULT_MIGRATE_X_CHECKPOINT_DELAY ), + +prop_uint64 ("downtime-limit" , &s->parameters.downtime_limit,DEFAULT_MIGRATE_SET_DOWNTIME ), +prop_uint64 ("x-vcpu-dirty-limit-period" , &s->parameters.x_vcpu_dirty_limit_period,DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD ), +prop_uint64 ("vcpu-dirty-limit" , &s->parameters.vcpu_dirty_limit,DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT ), +prop_uint64 ("x-rdma-chunk-size" , &s->parameters.x_rdma_chunk_size,DEFAULT_MIGRATE_X_RDMA_CHUNK_SIZE ), +prop_uint64 ("xbzrle-cache-size" , &s->parameters.xbzrle_cache_size,DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE ), +prop_uint64 ("max-postcopy-bandwidth" , &s->parameters.max_postcopy_bandwidth,DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH ), +prop_uint64 ("announce-initial" , &s->parameters.announce_initial,DEFAULT_MIGRATE_ANNOUNCE_INITIAL ), +prop_uint64 ("announce-max" , &s->parameters.announce_max,DEFAULT_MIGRATE_ANNOUNCE_MAX ), +prop_uint64 ("announce-rounds" , &s->parameters.announce_rounds,DEFAULT_MIGRATE_ANNOUNCE_ROUNDS ), +prop_uint64 ("announce-step" , &s->parameters.announce_step,DEFAULT_MIGRATE_ANNOUNCE_STEP ), +prop_uint64 ("max-bandwidth" , &s->parameters.max_bandwidth,MAX_THROTTLE ), +prop_uint64 ("avail-switchover-bandwidth" , &s->parameters.avail_switchover_bandwidth,0 ), + +prop_StrOrNull ("tls-creds" , &s->parameters.tls_creds, (uint64_t )"" ), +prop_StrOrNull ("tls-hostname" , &s->parameters.tls_hostname, (uint64_t )"" ), +prop_StrOrNull ("tls-authz" , &s->parameters.tls_authz, (uint64_t )"" ), + +prop_MigMode ("mode" , &s->parameters.mode, (uint64_t )"normal" ), +prop_MultiFDCompression ("multifd-compression" , &s->parameters.multifd_compression, (uint64_t )DEFAULT_MIGRATE_MULTIFD_COMPRESSION ), +prop_ZeroPageDetection ("zero-page-detection" , &s->parameters.zero_page_detection, (uint64_t )"multifd" ), + }; + +for (int i =0 ; i <ARRAY_SIZE (props_list); i++) { +ObjectProperty *new; +ObjectProperty *in = &props_list[i]; + + new =object_property_add (obj, in->name, in->type, in->get, in->set, + in->release, in->opaque); +object_property_set_default (new, in->defval); + } + +/* Migration capabilities are always turned off by default */ +for (int i =0 ; i <MIGRATION_CAPABILITY__MAX ; i++) { +ObjectProperty prop, *new; + + prop =prop_bool (MigrationCapability_str (i), &s->capabilities[i], false); + new =object_property_add (obj, prop.name, prop.type, prop.get, prop.set, +NULL , prop.opaque); +object_property_set_default (new, prop.defval); + } +}bool migrate_auto_converge (void ) {
Signature · 1 line
2.53.0
Re: [PATCH v2 10/10] migration: Switch to TYPE_OBJECT with object properties
Quoted 255 lines · Fabiano Rosas
Quoted 207 lines · Peter Xu
Quoted 23 lines · Daniel P. Berrangé
Quoted 22 lines · Peter Xu
The migration object used to depend on
TYPE_DEVICEdue to:- Usage of qdev properties
- Apply compat properties and global propertiesThis patch re-based the object to
TYPE_OBJECTwith the changes:- Switch to object properties API
- Manually apply both compat and global properties inpost_init()Note that to avoid too many property getter/setter helpers, this patch used the object_property_add_*_ptr_def() APIs so that an pointer is passed to bind to the property. Such API is used for most of the conversions.
After patch, the migration object initializes instance properties within its
instance_init()callback, inmigrate_params_init().One side effect of this change is, since we switched to a loop to add all capabilities, the name of the properties representing a migration capability may chance from previously hard-coded ones (many with x-). It's fine since it's only used in -global so it's only for debugging.
Quoted 5 lines
Quoted 2 lines
Similarly, I removed "x-" from other properites that used to start with "x-" but actually are not experimental.
Mixing such a change into a refactoring commit is bad practice, can you keep property changes separated.
Sure.
Quoted 84 lines
Quoted 73 lines
After the whole conversion, we don't need
migration_propertiesor the count anymore, hence can be removed. While at it, we can also remove two DEFINE_PROP*() API that only migration uses (DEFINE_PROP_STR_OR_NULL, andDEFINE_PROP_MIG_CAP).Signed-off-by Peter Xu <[email protected]>--- migration/options.h | 8 +- migration/migration.c | 35 ++- migration/options.c | 526 ++++++++++++++++++++++++++---------------- 3 files changed, 351 insertions(+), 218 deletions(-)migration/options.c +40
-10@@ -54,7 +54,7 @@ +static void migration_object_init_props_bool (MigrationState *s) { -const Property *prop = opaque; -StrOrNull **ptr =object_field_prop_ptr (obj, prop); -StrOrNull *str_or_null = *ptr; +Object *obj =OBJECT (s); +int i; -/* -* The property should never be NULL because it's part of -* s->parameters and a default value is always set by qdev. It -* should also never be QNULL as the setter doesn't allow it. -*/ -assert (str_or_null && str_or_null->type !=QTYPE_QNULL ); -visit_type_str (v, name, &str_or_null->u.s, errp); +struct MigPropBool { +const char *name; +void *ptr; +bool defvar; + } bool_list[] = { + { +"store-global-state" , + &s->store_global_state, + true, + }, + { +"send-configuration" , + &s->send_configuration, + true, + }, + { +"send-section-footer" , + &s->send_section_footer, + true, + }, + { +"send-switchover-start" , + &s->send_switchover_start, + true, + }, + { +"x-preempt-pre-7-2" , + &s->preempt_pre_7_2, + false, + }, + { +"x-cpu-throttle-tailslow" , + &s->parameters.cpu_throttle_tailslow, + false, + }, + { +"multifd-clean-tls-termination" ,migration/options.c
Quoted 10 lines
migration/options.c +10
-0+ &s->multifd_clean_tls_termination, + true, + }, + { +"multifd-flush-after-each-section" , + &s->multifd_flush_after_each_section, + false, + }, + }; +struct MigPropBool *prop;Quoted 3 lines
This approach to declaring properties is pretty unpleasant to follow IMHO. Being a custom different approach from every other object impl is not a good thing.
[I asked this question elsewhere, I'll keep the discussion there]
Quoted 8 lines
migration/options.c
Quoted 7 lines
migration/options.c +6
-0+ +for (i =0 ; i <ARRAY_SIZE (bool_list); i++) { + prop = &bool_list[i]; +object_property_add_bool_ptr_def (obj, prop->name, + prop->ptr, prop->defvar); + }Quoted 7 lines
Using instance level properties is the old way to do things, it is preferred to use class level properties instead.
This means you can't use the "ptr" concept to directly reference the instance fields and have to provide setters / getters explicitly instead, but as you've shown with the TLS properties, a macro can make it simple to define the repetitive getters/setters.
If pointer is unwanted, I can switch to some more macro magic. But since this series got rewrote the 3rd time.. I'll make sure it's extremely required before doing it..
Quoted 31 lines
Quoted 13 lines
migration/options.c +13
-0+static void migration_object_init_props_enum (MigrationState *s) +{ +Object *obj =OBJECT (s); +ObjectProperty *prop; + + prop =object_property_add_enum (obj,"multifd-compression" , +"MultiFDCompression" , + &MultiFDCompression_lookup, + mig_prop_multifd_compression_get, + mig_prop_multifd_compression_set); +object_property_set_default_str (prop,DEFAULT_MIGRATE_MULTIFD_COMPRESSION ); + + prop = object_property_add_enum(obj, "mode", "MigMode", &MigMode_lookup,migration/options.c
Quoted 10 lines
migration/options.c +10
-0+ mig_prop_mode_get, mig_prop_mode_set); +object_property_set_default_str (prop,"normal" ); + + prop =object_property_add_enum (obj,"zero-page-detection" , +"ZeroPageDetection" , + &ZeroPageDetection_lookup, + mig_prop_zero_page_detection_get, + mig_prop_zero_page_detection_set); +object_property_set_default_str (prop,"multifd" ); +}Perhaps I'm missing something, but I'm not seeing the point in using the
set_defaultmethods - in fact I'm not really sure why they exist in QOM at all.I'd expect all defaults to be set in the instance
_initmethod. ie why isn't this done as:Quoted 6 lines
void migrate_params_init(MigrationState *s) { s->parameters.mode = MIG_MODE_NORMAL; s->parameters.zero_page_detection = ZERO_PAGE_DETECTION_MULTIFD; .... all other defaults... }Yes frankly I asked myself the same question when looking at this.
I still saw quite some defvar references,
type_print_class_properties()can be one example where we dump help message with default values but without the need to apply. I didn't check the rest. If the concept exists and if we will be using qobj props, IMHO sticking with it is defintely safer so that all qom future defvar changes will apply and it'll just work there.Quoted 18 lines
Quoted 4 lines
migration/options.c +2
-0+ +static void migration_object_init_properties (MigrationState *s)migration/options.c
Quoted 10 lines
migration/options.c +10
-0+{ +migration_object_init_props_bool (s); +migration_object_init_props_uint8 (s); +migration_object_init_props_uint32 (s); +migration_object_init_props_uint64 (s); +migration_object_init_props_size (s); +migration_object_init_props_caps (s); +migration_object_init_props_tls (s); +migration_object_init_props_enum (s); +}...and class properties be registered in
migrate_params_class_init()and the grouping per type isn't helpful IMHO, just put all theobject_class_property_addcalls inline in one place.Quoted 6 lines
I still want to avoid long functions, one way or another.
Hopefully it makes sense when I have those arrays to init different type of props it makes sense to split with this, but I'm open to other way to split. I still want to not make it a extremely long function.
I see why you did it that way, it's mostly a limitation of the object code in that it requires the type of the default value only to convert it to a QObject internally. IMO, this is backwards, the
object.ccode should take the QObject and let the caller do the conversion.I rewrote this part of the code using a ObjectProperties object as intermediary, instead of MigProp*. I think this looks easier to parse, although it's longer.
-->8--
Froma6529d119d25ecc00f92686e2cddf1d81dc43183Mon Sep 17 00:00:00 2001
From: Fabiano Rosas <[email protected]>
Date: Wed, 10 Jun 2026 16:49:52 -0300
Subject: [PATCH] poc--- migration/options.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+)migration/options.c +12
-0@@ -90,6 +90,120 @@#define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1/* MB/s */ #define DEFAULT_MIGRATE_X_RDMA_CHUNK_SIZE MiB +#define defstr (def) QOBJECT(qstring_from_str((const char *)def)) +#define defbool (def) QOBJECT(qbool_from_bool((bool)def)) +#define defint (def) QOBJECT(qnum_from_int((int64_t)def)) +#define defuint (def) QOBJECT(qnum_from_uint(def)) + +#define defuint8 defuint +#define defuint16 defuint +#define defuint32 defuint +#define defuint64 defuint +#define defenum defstr +#define defStrOrNull defstr +#define defMigMode defenum
migration/options.c line 114
Quoted 10 lines
migration/options.c +10
-0+#define defMultiFDCompression defenum +#define defZeroPageDetection defenum + +#define DEFPROP_PTR_ACCESSOR (_t) \ + static void property_visit_type_##_t(Object *obj, Visitor *v, \ + const char *name, void *opaque, \ + Error **errp) \ + { \ + visit_type_##_t(v, name, opaque, errp); \ + } \
I'm trying to convert this Object to a QDict here. Then we could pass the name of the struct field as the opaque and set/get via dict operations and this function could be generic for all parameters.
Quoted 95 lines
migration/options.c +92
-0+ \ + static inline ObjectProperty prop_##_t(const char *name, void *opaque, \ +uint64_t def) \ + { \ +return (ObjectProperty ) { \ + .name = (char *)name, \ + .type = (char *)"##_t" , \ + .opaque = opaque, \ + .get = property_visit_type_##_t, \ + .set = property_visit_type_##_t, \ + .defval = def##_t(def), \ + }; \ + } \ + +DEFPROP_PTR_ACCESSOR (str); +DEFPROP_PTR_ACCESSOR (bool); +DEFPROP_PTR_ACCESSOR (int); +DEFPROP_PTR_ACCESSOR (uint8); +DEFPROP_PTR_ACCESSOR (uint16); +DEFPROP_PTR_ACCESSOR (uint32); +DEFPROP_PTR_ACCESSOR (uint64); +DEFPROP_PTR_ACCESSOR (StrOrNull); +DEFPROP_PTR_ACCESSOR (MigMode); +DEFPROP_PTR_ACCESSOR (MultiFDCompression); +DEFPROP_PTR_ACCESSOR (ZeroPageDetection); + +static void migration_object_init_properties (MigrationState *s) +{ +Object *obj =OBJECT (s); +ObjectProperty props_list[] = { +prop_bool ("store-global-state" , &s->store_global_state, true), +prop_bool ("send-configuration" , &s->send_configuration, true), +prop_bool ("send-section-footer" , &s->send_section_footer, true), +prop_bool ("send-switchover-start" , &s->send_switchover_start, true), +prop_bool ("x-preempt-pre-7-2" , &s->preempt_pre_7_2, false), +prop_bool ("x-cpu-throttle-tailslow" , &s->parameters.cpu_throttle_tailslow, false), +prop_bool ("multifd-clean-tls-termination" , &s->multifd_clean_tls_termination, true), +prop_bool ("multifd-flush-after-each-section" , &s->multifd_flush_after_each_section, false), + +prop_uint8 ("clear-bitmap-shift" , &s->clear_bitmap_shift,CLEAR_BITMAP_SHIFT_DEFAULT ), +prop_uint8 ("throttle-trigger-threshold" , &s->parameters.throttle_trigger_threshold,DEFAULT_MIGRATE_THROTTLE_TRIGGER_THRESHOLD ), +prop_uint8 ("cpu-throttle-initial" , &s->parameters.cpu_throttle_initial,DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL ), +prop_uint8 ("cpu-throttle-increment" , &s->parameters.cpu_throttle_increment,DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT ), +prop_uint8 ("multifd-channels" , &s->parameters.multifd_channels,DEFAULT_MIGRATE_MULTIFD_CHANNELS ), +prop_uint8 ("multifd-zlib-level" , &s->parameters.multifd_zlib_level,DEFAULT_MIGRATE_MULTIFD_ZLIB_LEVEL ), +prop_uint8 ("multifd-qatzip-level" , &s->parameters.multifd_qatzip_level,DEFAULT_MIGRATE_MULTIFD_QATZIP_LEVEL ), +prop_uint8 ("multifd-zstd-level" , &s->parameters.multifd_zstd_level,DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL ), +prop_uint8 ("max-cpu-throttle" , &s->parameters.max_cpu_throttle,DEFAULT_MIGRATE_MAX_CPU_THROTTLE ), + +prop_uint32 ("x-checkpoint-delay" , &s->parameters.x_checkpoint_delay,DEFAULT_MIGRATE_X_CHECKPOINT_DELAY ), + +prop_uint64 ("downtime-limit" , &s->parameters.downtime_limit,DEFAULT_MIGRATE_SET_DOWNTIME ), +prop_uint64 ("x-vcpu-dirty-limit-period" , &s->parameters.x_vcpu_dirty_limit_period,DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD ), +prop_uint64 ("vcpu-dirty-limit" , &s->parameters.vcpu_dirty_limit,DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT ), +prop_uint64 ("x-rdma-chunk-size" , &s->parameters.x_rdma_chunk_size,DEFAULT_MIGRATE_X_RDMA_CHUNK_SIZE ), +prop_uint64 ("xbzrle-cache-size" , &s->parameters.xbzrle_cache_size,DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE ), +prop_uint64 ("max-postcopy-bandwidth" , &s->parameters.max_postcopy_bandwidth,DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH ), +prop_uint64 ("announce-initial" , &s->parameters.announce_initial,DEFAULT_MIGRATE_ANNOUNCE_INITIAL ), +prop_uint64 ("announce-max" , &s->parameters.announce_max,DEFAULT_MIGRATE_ANNOUNCE_MAX ), +prop_uint64 ("announce-rounds" , &s->parameters.announce_rounds,DEFAULT_MIGRATE_ANNOUNCE_ROUNDS ), +prop_uint64 ("announce-step" , &s->parameters.announce_step,DEFAULT_MIGRATE_ANNOUNCE_STEP ), +prop_uint64 ("max-bandwidth" , &s->parameters.max_bandwidth,MAX_THROTTLE ), +prop_uint64 ("avail-switchover-bandwidth" , &s->parameters.avail_switchover_bandwidth,0 ), + +prop_StrOrNull ("tls-creds" , &s->parameters.tls_creds, (uint64_t )"" ), +prop_StrOrNull ("tls-hostname" , &s->parameters.tls_hostname, (uint64_t )"" ), +prop_StrOrNull ("tls-authz" , &s->parameters.tls_authz, (uint64_t )"" ), + +prop_MigMode ("mode" , &s->parameters.mode, (uint64_t )"normal" ), +prop_MultiFDCompression ("multifd-compression" , &s->parameters.multifd_compression, (uint64_t )DEFAULT_MIGRATE_MULTIFD_COMPRESSION ), +prop_ZeroPageDetection ("zero-page-detection" , &s->parameters.zero_page_detection, (uint64_t )"multifd" ), + }; + +for (int i =0 ; i <ARRAY_SIZE (props_list); i++) { +ObjectProperty *new; +ObjectProperty *in = &props_list[i]; + + new =object_property_add (obj, in->name, in->type, in->get, in->set, + in->release, in->opaque); +object_property_set_default (new, in->defval); + } + +/* Migration capabilities are always turned off by default */ +for (int i =0 ; i <MIGRATION_CAPABILITY__MAX ; i++) { +ObjectProperty prop, *new; + + prop =prop_bool (MigrationCapability_str (i), &s->capabilities[i], false); + new =object_property_add (obj, prop.name, prop.type, prop.get, prop.set, +NULL , prop.opaque); +object_property_set_default (new, prop.defval); + } +}bool migrate_auto_converge (void ) {
Re: [PATCH v2 10/10] migration: Switch to TYPE_OBJECT with object properties
In reply to Peter XuQuoted 46 lines · Peter Xu
The migration object used to depend on
TYPE_DEVICEdue to:- Usage of qdev properties
- Apply compat properties and global propertiesThis patch re-based the object to
TYPE_OBJECTwith the changes:- Switch to object properties API
- Manually apply both compat and global properties inpost_init()Note that to avoid too many property getter/setter helpers, this patch used the object_property_add_*_ptr_def() APIs so that an pointer is passed to bind to the property. Such API is used for most of the conversions.
After patch, the migration object initializes instance properties within its
instance_init()callback, inmigrate_params_init().One side effect of this change is, since we switched to a loop to add all capabilities, the name of the properties representing a migration capability may chance from previously hard-coded ones (many with x-). It's fine since it's only used in -global so it's only for debugging.
Similarly, I removed "x-" from other properites that used to start with "x-" but actually are not experimental.
After the whole conversion, we don't need
migration_propertiesor the count anymore, hence can be removed. While at it, we can also remove two DEFINE_PROP*() API that only migration uses (DEFINE_PROP_STR_OR_NULL, andDEFINE_PROP_MIG_CAP).Signed-off-by Peter Xu <[email protected]>--- migration/options.h | 8 +- migration/migration.c | 35 ++- migration/options.c | 526 ++++++++++++++++++++++++++---------------- 3 files changed, 351 insertions(+), 218 deletions(-)migration/migration.c +5
-3+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: +* +* (1) machine compat properties
migration/migration.c static bool migration_object_check(MigrationState *ms, Error **errp) · line 4033
Quoted 10 lines
migration/migration.c +4
-4+* (2) -global settings in cmdlines * -* TODO: Make this TYPE_OBJECT once QOM provides something like -* TYPE_DEVICE's "-global" properties. +* Need to be applied in order so (2) takes precedence over (1). */ - .parent = TYPE_DEVICE, - .class_init = migration_class_init, +object_apply_compat_props (obj); +object_apply_global_props (obj,global_props (), &error_fatal);
-global is/was intended for devices, primarily those which are created by default as part of the machine. For dynamically created devices the docs recommend use of -device instead of -global.
I get that -global was exposed for migration via the inappropriate use of TYPE_DEVICE as a parent for TYPE_MIGRATION, but I don't think we should be prolonging that misuse by exposing use of -global for things which are QOM rather than QDev.
If we want todo that for the sake of backcompat, IMHO it should be deprecated so it only lives for a short while after the conversion to QOM.
This makes me realize that this does not implement the UserCreatable interface on TYPE_MIGRATION, so I'm presuming the MigrationState is still created internally. Perhaps we should switch to making it a full UserCreatable, such that -object can be used to set all migration parameters on the command line and -global won't be required ?
migration/migration.c static bool migration_object_check(MigrationState *ms, Error **errp) · line 4043
Quoted 10 lines
migration/migration.c +6
-0+} + +static const TypeInfo migration_type = { + .name =TYPE_MIGRATION , + .parent =TYPE_OBJECT , .instance_size =sizeof (MigrationState), .instance_init = migration_instance_init, + .instance_post_init = migration_instance_post_init, .instance_finalize = migration_instance_finalize, };
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 v2 10/10] migration: Switch to TYPE_OBJECT with object properties
Quoted 4 lines · Daniel P. Berrangé
-global is/was intended for devices, primarily those which are created by default as part of the machine. For dynamically created devices the docs recommend use of -device instead of -global.
I wished it was called -device-global then it'll be clearer, otherwise from an API perspective it really shouldn't be limited to qdev..
It makes sense to not call it -device-global, IMHO essentially because we don't necessarily need to restrict it to -device.
Quoted 10 lines
I get that -global was exposed for migration via the inappropriate use of
TYPE_DEVICEas a parent forTYPE_MIGRATION, but I don't think we should be prolonging that misuse by exposing use of -global for things which are QOM rather than QDev.If we want todo that for the sake of backcompat, IMHO it should be deprecated so it only lives for a short while after the conversion to QOM.
Quoted 5 lines
This makes me realize that this does not implement the UserCreatable interface on
TYPE_MIGRATION, so I'm presuming the MigrationState is still created internally. Perhaps we should switch to making it a full UserCreatable, such that -object can be used to set all migration parameters on the command line and -global won't be required ?
This is what Fabiano suggested in his reply here:
https://lore.kernel.org/qemu-devel/[email protected]/
I wonder what's your view on that when put together the singleton series I used to post, where I also mentioned in the reply:
https://lore.kernel.org/qemu-devel/[email protected]/
If you think that's the right approach, we can try to have it to replace -global. -global is debug API for migration, we don't need to obsolete it. Compat property is, which is unaffected by this. So we can remove -global support for migration, but it'll always be good to have a replacement for scripts.
Thanks,
Signature · 1 line
Peter Xu
Quoted 48 lines · Peter Xu
CI: https://gitlab.com/peterx/qemu/-/pipelines/2588717620
(two irrelevant failures due to no runner)rfc: https://lore.kernel.org/r/[email protected] v1: https://lore.kernel.org/r/[email protected]This v2 is a full rewrite of v1, changelog doesn't apply.
This version majorly addressed the concern in v1 having object API exported in qdev files. Instead of trying to expose qdev properties, this patchset switched migration object to use the object property API to add properties.
Not all QOM facilities are ready for it, there're a few prior patches to improve QOM API to achieve it.
The major concept that this series introduces that does not exist previously is the default value mechanisms for object properties (rather than object class properties). Here migration object will rely on that to set default values.
Patch 1: A cleanup to use OBJECT_DECLARE_SIMPLE_TYPE for migration Patch 2-4: Qdev changes needed for the transition Patch 5-9: Improve QOM API to prepare for the property switch Patch 10: Switch migration object to use TYPE_OBJECT and object propsComments welcomed, thanks.
Peter Xu (10):
migration: UseOBJECT_DECLARE_SIMPLE_TYPE
qdev: Exportglobal_props()
qdev: Introduce DEFINE_PROP_*_NODEFAULT for bool/uint32 hw/arm: Use nodefault version of qdev props when not needed
qom: Create object-property-ptr.[ch]
qom: Addobject_property_add_bool_ptr()
qom: Addobject_property_add_size_ptr()
qom: Add object_property_add_*_ptr_def()
qom: Allow default values for instance properties
migration: Switch toTYPE_OBJECTwith object propertiesinclude/hw/core/qdev-properties.h | 7 + include/qom/object-property-ptr.h | 162 +++++++++ include/qom/object.h | 99 +----- migration/migration.h | 9 +- migration/options.h | 8 +- hw/arm/bcm2836.c | 3 +- hw/core/qdev-properties.c | 2 +- migration/migration.c | 42 ++- migration/options.c | 526 +++++++++++++++++++-----------
Quoted 8 lines
qom/object-property-ptr.c | 394 ++++++++++++++++++++++ qom/object.c | 266 ++------------- target/arm/cpu64.c | 3 +- qom/meson.build | 1 + rust/bindings/hwcore-sys/lib.rs | 2 +- 14 files changed, 957 insertions(+), 567 deletions(-) create mode 100644 include/qom/object-property-ptr.h create mode 100644 qom/object-property-ptr.c
Hi,
After we discussed your v1 I started playing with this in parallel and stumbled into pretty much all of the issues this series resolves. Nice work!
I applied a patch [0] on top of this series to allow using the command-line to create the migration object. It can set all (most) options with -object migration,id=mig1,key=val,...
$ ~/qemu-system-x86_64 -nodefaults -nographic -S \ -object migration,id=mig1,announce-initial=99,downtime-limit=99,multifd-channels=99,multifd-compression=zlib,multifd=on ... (qemu) info migrate_parameters (qemu) info migrate_capabilities ... announce-initial: 99 ms downtime-limit: 99 ms multifd-channels: 99 multifd-compression: zlib multifd: on
I'm not saying we should do that now. I just want to check with you to make sure we're not closing the door for future improvements:
1) It seems the "help" option is tied to the class. Setting options work, but the help says otherwise:
$ ~/qemu-system-x86_64 -nographic -object migration,id=mig1,help There are no options for migration.
2) user_creatable_add_qapi
The command line parsing goes through user_creatable_add_qapi() and instantiates an object. Since migrate_params_init runs from inside .instance_init, it cannot see any parameters that are set this way.
Moreover, the migration_object_init() call from vl.c will init a second migration object.
In the patch below I have hacked the current_migration assignment to first check if the object has already been created and use that instead of creating a new one.
How does this work for normal objects? I suppose most of them have the TYPE_DEVICE as a parent, so they're not hanging in the "objects" container.
3) TLS (of course)
With the patch below, setting TLS options from the cmdline asserts:
visit_start_alternate: Assertion `!(v->type & VISITOR_INPUT)' failed. (just mentioning in case it can affect the design of this series)
[0]
-->8--
From 8c6c0743f1659d9df45e80334e8dc5f068ff984e Mon Sep 17 00:00:00 2001
From: Fabiano Rosas <[email protected]>
Date: Tue, 9 Jun 2026 16:00:21 -0300
Subject: [PATCH] wip
--- migration/migration.c | 11 ++++++++++- migration/options.c | 1 + qapi/qom.json | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-)
migration/migration.c +10 -1
@@ -297,7 +297,16 @@ void migration_object_init(void) {/* This can only be called once. */ assert (!current_migration); - current_migration =MIGRATION (object_new (TYPE_MIGRATION )); + +Object *root =object_get_objects_root (); +ObjectProperty *prop =g_hash_table_lookup (root->properties,"mig1" ); + +if (prop->opaque) { + current_migration = prop->opaque; +object_ref (current_migration); + }else { + current_migration =MIGRATION (object_new (TYPE_MIGRATION )); + }/* * Init the migrate incoming object as well no matter whether
migration/options.c +1 -0
@@ -21,6 +21,7 @@#include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qerror.h" #include "qobject/qnull.h" +#include "qom/object_interfaces.h" #include "system/runstate.h" #include "migration/colo.h" #include "migration/cpr.h"
qapi/qom.json +29 -0
@@ -8,6 +8,11 @@ { 'include': 'block-core.json' } { 'include': 'common.json' } { 'include': 'crypto.json' } +# FIXME: this requires --disable-tools due to: +# /usr/bin/ld.bfd: libqemuutil.a.p/meson-generated_.._qapi_qapi-commands-migration.c.o: +# in function `qmp_marshal_query_migr: qemu/build/qapi/qapi-commands-migration.c:48:(.text+0x181c): +# undefined reference to `qmp_query_migrate' +{ 'include': 'migration.json' } ## # ***********************
@@ -1187,6 +1192,28 @@ 'data': { '*cpu-affinity': ['uint16'], '*node-affinity': ['uint16'] } } + +## +# @MigProperties: +# +# Properties for migration objects. +# +# @multifd: this is a capability and therefore is not part of +# MigrationParameters yet (WIP). (default: 0) +# +# @store-global-state: this is a compat property and therefore is not +# part of MigrationParameters. It's probably best to keep it like +# this so we don't have to deal with previously impossible +# scenarios if the user tries to set it via set-migrate (default: +# 0) +# +# Since: 11.1 +## +{ 'struct': 'MigProperties', + 'base': 'MigrationParameters', + 'data': { '*multifd': 'bool', + '*store-global-state': 'bool' } } + ## # @ObjectType: #
@@ -1237,6 +1264,7 @@ 'memory-backend-ram', { 'name': 'memory-backend-shm', 'if': 'CONFIG_POSIX' }, + 'migration', 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' },
@@ -1315,6 +1343,7 @@ 'memory-backend-ram': 'MemoryBackendProperties', 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', 'if': 'CONFIG_POSIX' }, + 'migration': 'MigProperties', 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties',
Signature · 1 line
2.53.0
Quoted 5 lines · Fabiano Rosas
Hi,
After we discussed your v1 I started playing with this in parallel and stumbled into pretty much all of the issues this series resolves. Nice work!
Good to know at least it looks reasonable for someone.. thanks. :)
Looks like Dan still has concern that I use the ptrs in obj props but I'll discuss it later separately.
Quoted 17 lines
I applied a patch [0] on top of this series to allow using the command-line to create the migration object. It can set all (most) options with -object migration,id=mig1,key=val,...
$ ~/qemu-system-x86_64 -nodefaults -nographic -S \ -object migration,id=mig1,announce-initial=99,downtime-limit=99,multifd-channels=99,multifd-compression=zlib,multifd=on ... (qemu) info migrate_parameters (qemu) info migrate_capabilities ... announce-initial: 99 ms downtime-limit: 99 ms multifd-channels: 99 multifd-compression: zlib multifd: on
Quoted 2 lines
I'm not saying we should do that now. I just want to check with you to make sure we're not closing the door for future improvements:
IIUC it works, maybe indeed it's a better way than "-incoming config:" at least in that we stick with the current APIs.
Said that, it does bypass the singleton work I did previously:
https://lore.kernel.org/r/[email protected]
Which was also unfortunately got rejected..
So, I suppose this is still fine that all the tricks resides in migration/ so far, maybe this is acceptable.
But then, we'll need to make sure the rest QEMU object code doesn't have assumption that all objects can be created more than one.. and making sure nothing crash elsewhere: when it crashes or works inproperly, we may face again that singleton problem one way or another. That's so far the only concern I have.
Quoted 6 lines
1) It seems the "help" option is tied to the class. Setting options work, but the help says otherwise:
$ ~/qemu-system-x86_64 -nographic -object migration,id=mig1,help There are no options for migration.
This one is easy, something like this should work:
bool type_print_class_properties(const char *type) {
+ g_autoptr(Object) obj = NULL;
ObjectClass *klass;
ObjectPropertyIterator iter;
ObjectProperty *prop;
@@ -134,7 +135,12 @@ bool type_print_class_properties(const char *type)
}
array = g_ptr_array_new();- object_class_property_iter_init(&iter, klass);
+ if (object_class_is_abstract(klass)) {
+ object_class_property_iter_init(&iter, klass);
+ } else {
+ obj = object_new_with_class(klass);
+ object_property_iter_init(&iter, obj);
+ }
while ((prop = object_property_iter_next(&iter))) {
if (!prop->set) {
continue;Quoted 7 lines
2)
user_creatable_add_qapiThe command line parsing goes through
user_creatable_add_qapi()and instantiates an object. Sincemigrate_params_initruns from inside .instance_init, it cannot see any parameters that are set this way.
Quoted 6 lines
Moreover, the
migration_object_init()call fromvl.cwill init a second migration object.In the patch below I have hacked the
current_migrationassignment to first check if the object has already been created and use that instead of creating a new one.
Yeah that trick should work at least for now, except the concern I raised above.
Since the tap work is unblocked (by temporarily introducing the tap flag), I plan to put aside the "-incoming config:*" work a bit. We'll need to pick it up at least when there's yet another similiar use case like tap or "mode" of CPR, but then lower priority. But let me know if you or anyone still think we should have it land earlier, I can re-prioritize that.
Quoted 4 lines
How does this work for normal objects? I suppose most of them have the
TYPE_DEVICEas a parent, so they're not hanging in the "objects" container.
I may not get the real question behind, but.. iiuc normal objects shouldn't be sub-class of TYPE_DEVICE, and they should work fine with -object *help, and they should be able to be created with multiple instances in most cases.
Quoted 6 lines
3) TLS (of course)
With the patch below, setting TLS options from the cmdline asserts:
visit_start_alternate: Assertion `!(v->type &VISITOR_INPUT)' failed. (just mentioning in case it can affect the design of this series)
Oh, I didn't really notice we'll have issue with it.. I did the string prop solution for tls* by pure accident, because we already assumed it's always strings anyway and it's trivial to use the object prop str helpers. I didn't expect it an issue when used with string inputs. So I assume for those we need to rely on JSON formats?
-object '{"qom-type": "migration", "id": "mig1", "tls-creds": "SOMETHING"}'
Quoted 23 lines
[0]
-->8--
From8c6c0743f1659d9df45e80334e8dc5f068ff984eMon Sep 17 00:00:00 2001
From: Fabiano Rosas <[email protected]>
Date: Tue, 9 Jun 2026 16:00:21 -0300
Subject: [PATCH] wip--- migration/migration.c | 11 ++++++++++- migration/options.c | 1 + qapi/qom.json | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-)migration/migration.c +0
-1@@ -297,7 +297,16 @@ void migration_object_init(void) {/* This can only be called once. */ assert (!current_migration); - current_migration =MIGRATION (object_new (TYPE_MIGRATION ));
migration/migration.c void migration_object_init(void) · line 309
Quoted 10 lines
migration/migration.c +10
-0+ +Object *root =object_get_objects_root (); +ObjectProperty *prop =g_hash_table_lookup (root->properties,"mig1" ); + +if (prop->opaque) { + current_migration = prop->opaque; +object_ref (current_migration); + }else { + current_migration =MIGRATION (object_new (TYPE_MIGRATION )); + }
A quick comment for this one; maybe better with:
Object *mig_obj = object_resolve_path_component(object_get_objects_root(),
"mig1");
Or even better:
static int find_migration_object(Object *obj, void *opaque)
{
if (object_dynamic_cast(obj, TYPE_MIGRATION)) {
*(Object **)opaque = obj;
return 1;
}
return 0;
}Then:
object_child_foreach(object_get_objects_root(),
find_migration_object, &existing);Quoted 80 lines
migration/migration.c +0
-0/* * Init the migrate incoming object as well no matter whether migration/options.c +1
-0@@ -21,6 +21,7 @@#include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qerror.h" #include "qobject/qnull.h" +#include "qom/object_interfaces.h" #include "system/runstate.h" #include "migration/colo.h" #include "migration/cpr.h" qapi/qom.json +29
-0@@ -8,6 +8,11 @@ { 'include': 'block-core.json' } { 'include': 'common.json' } { 'include': 'crypto.json' } +# FIXME: this requires --disable-tools due to: +# /usr/bin/ld.bfd: libqemuutil.a.p/meson-generated_.._qapi_qapi-commands-migration.c.o: +# in function `qmp_marshal_query_migr: qemu/build/qapi/qapi-commands-migration.c:48:(.text+0x181c): +# undefined reference to `qmp_query_migrate' +{ 'include': 'migration.json' } ## # ***********************@@ -1187,6 +1192,28 @@ 'data': { '*cpu-affinity': ['uint16'], '*node-affinity': ['uint16'] } } + +## +# @MigProperties: +# +# Properties for migration objects. +# +# @multifd: this is a capability and therefore is not part of +# MigrationParameters yet (WIP). (default: 0) +# +# @store-global-state: this is a compat property and therefore is not +# part of MigrationParameters. It's probably best to keep it like +# this so we don't have to deal with previously impossible +# scenarios if the user tries to set it via set-migrate (default: +# 0) +# +# Since: 11.1 +## +{ 'struct': 'MigProperties', + 'base': 'MigrationParameters', + 'data': { '*multifd': 'bool', + '*store-global-state': 'bool' } } + ## # @ObjectType: #@@ -1237,6 +1264,7 @@ 'memory-backend-ram', { 'name': 'memory-backend-shm', 'if': 'CONFIG_POSIX' }, + 'migration', 'pef-guest', { 'name': 'pr-manager-helper', 'if': 'CONFIG_LINUX' },@@ -1315,6 +1343,7 @@ 'memory-backend-ram': 'MemoryBackendProperties', 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', 'if': 'CONFIG_POSIX' }, + 'migration': 'MigProperties', 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties',Signature · 1 line
2.53.0
Signature · 1 line
Peter Xu
Quoted 32 lines · Peter Xu
Quoted 5 lines · Fabiano Rosas
Hi,
After we discussed your v1 I started playing with this in parallel and stumbled into pretty much all of the issues this series resolves. Nice work!
Good to know at least it looks reasonable for someone.. thanks. :)
Looks like Dan still has concern that I use the ptrs in obj props but I'll discuss it later separately.
Quoted 17 lines
I applied a patch [0] on top of this series to allow using the command-line to create the migration object. It can set all (most) options with -object migration,id=mig1,key=val,...
$ ~/qemu-system-x86_64 -nodefaults -nographic -S \ -object migration,id=mig1,announce-initial=99,downtime-limit=99,multifd-channels=99,multifd-compression=zlib,multifd=on ... (qemu) info migrate_parameters (qemu) info migrate_capabilities ... announce-initial: 99 ms downtime-limit: 99 ms multifd-channels: 99 multifd-compression: zlib multifd: onQuoted 2 lines
I'm not saying we should do that now. I just want to check with you to make sure we're not closing the door for future improvements:
Quoted 6 lines
IIUC it works, maybe indeed it's a better way than "-incoming config:" at least in that we stick with the current APIs.
Said that, it does bypass the singleton work I did previously:
You can force a QOM object into being a singleton if you like.
In the UserCreatable interface "complete" callback, for the first instance that's completed, stash its pointer in a global var, and then when subsequent instances are created have "complete" always report an error.
Quoted 7 lines
Quoted 5 lines
1) It seems the "help" option is tied to the class. Setting options work, but the help says otherwise:
$ ~/qemu-system-x86_64 -nographic -object migration,id=mig1,help There are no options for migration.This one is easy, something like this should work:
This is an example of why this needs to be using class properties, not instance properties.
Quoted 10 lines
bool
type_print_class_properties(const char *type){(quoted diff) +1
-0+ g_autoptr(Object) obj = NULL; ObjectClass *klass; ObjectPropertyIterator iter; ObjectProperty *prop;@@ -134,7 +135,12 @@ bool type_print_class_properties(const char *type) } array = g_ptr_array_new();
Review bool type_print_class_properties(const char *type) · line 146
Quoted 10 lines
(quoted diff) +6
-1- object_class_property_iter_init(&iter, klass); + if (object_class_is_abstract(klass)) { + object_class_property_iter_init(&iter, klass); + } else { + obj = object_new_with_class(klass); + object_property_iter_init(&iter, obj); + } while ((prop = object_property_iter_next(&iter))) { if (!prop->set) { continue;
No, we don't want to do that - everything intended to be used with -object needs to be using class properties.
Quoted 36 lines
Quoted 9 lines
migration/migration.c +0
-1@@ -297,7 +297,16 @@ void migration_object_init(void) {/* This can only be called once. */ assert (!current_migration); - current_migration =MIGRATION (object_new (TYPE_MIGRATION ));migration/migration.c void migration_object_init(void) · line 309
Quoted 10 lines
migration/migration.c +10
-0+ +Object *root =object_get_objects_root (); +ObjectProperty *prop =g_hash_table_lookup (root->properties,"mig1" ); + +if (prop->opaque) { + current_migration = prop->opaque; +object_ref (current_migration); + }else { + current_migration =MIGRATION (object_new (TYPE_MIGRATION )); + }A quick comment for this one; maybe better with:
Object
*mig_obj= object_resolve_path_component(object_get_objects_root(),
"mig1");Or even better:
static int
find_migration_object(Object *obj, void *opaque){ if (object_dynamic_cast(obj, TYPE_MIGRATION)) { *(Object **)opaque = obj; return 1; } return 0; }
Quoted 4 lines
Then:
object_child_foreach(object_get_objects_root(), find_migration_object, &existing);
If you want a singleton pattern, then it is simpler to just stash the "Migration" object pointer in the "complete" method, and not assume anything about the ID name the mgmt app chose to use.
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 :|