Firstly, qdev_class_add_property() function almost has nothing to do with
DeviceClass, it's a bridge between Property and object properties.
Change the 1st parameter of it, so that it can be used without DeviceClass
context at all. When at it, remove the "name" field because it's always
prop->name.
Export it for non-qdev use cases.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/hw/core/qdev-properties.h | 10 ++++++++++
hw/core/qdev-properties.c | 7 +++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h
index 779acb31b6..fec2aaac4d 100644
--- a/include/hw/core/qdev-properties.h
+++ b/include/hw/core/qdev-properties.h
@@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
*/
void qdev_property_add_static(DeviceState *dev, const Property *prop);
+/**
+ * object_class_add_property:
+ * @oc: Object class to operate on.
+ * @prop: The qdev property definition.
+ *
+ * Add a Property to @oc. This is the bridge to convert a Property into
+ * an object class property (as in ObjectClass.properties).
+ */
+void object_class_add_property(ObjectClass *oc, const Property *prop);
+
/**
* qdev_alias_all_properties: Create aliases on source for all target properties
* @target: Device which has properties to be aliased
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index a91c2ad101..ab828bb612 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1188,10 +1188,9 @@ void qdev_property_add_static(DeviceState *dev, const Property *prop)
}
}
-static void qdev_class_add_property(DeviceClass *klass, const char *name,
- const Property *prop)
+void object_class_add_property(ObjectClass *oc, const Property *prop)
{
- ObjectClass *oc = OBJECT_CLASS(klass);
+ const char *name = prop->name;
ObjectProperty *op;
if (prop->info->create) {
@@ -1222,7 +1221,7 @@ void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n)
for (size_t i = 0; i < n; ++i) {
const Property *prop = &props[i];
assert(prop->name);
- qdev_class_add_property(dc, prop->name, prop);
+ object_class_add_property(OBJECT_CLASS(dc), prop);
}
}
--
2.53.0
On Thu, Jun 04, 2026 at 07:11:17PM -0400, Peter Xu wrote: > Firstly, qdev_class_add_property() function almost has nothing to do with > DeviceClass, it's a bridge between Property and object properties. > > Change the 1st parameter of it, so that it can be used without DeviceClass > context at all. When at it, remove the "name" field because it's always > prop->name. > > Export it for non-qdev use cases. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > include/hw/core/qdev-properties.h | 10 ++++++++++ > hw/core/qdev-properties.c | 7 +++---- > 2 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h > index 779acb31b6..fec2aaac4d 100644 > --- a/include/hw/core/qdev-properties.h > +++ b/include/hw/core/qdev-properties.h > @@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, > */ > void qdev_property_add_static(DeviceState *dev, const Property *prop); > > +/** > + * object_class_add_property: > + * @oc: Object class to operate on. > + * @prop: The qdev property definition. > + * > + * Add a Property to @oc. This is the bridge to convert a Property into > + * an object class property (as in ObjectClass.properties). > + */ > +void object_class_add_property(ObjectClass *oc, const Property *prop); I'm really not a fan of this. Having both object_class_add_property and object_class_property_add methods is horrendous naming. Methods named with an "object_class_" prefix must live in qom/object.c & include/qom/object.h not in qdev. If doing that though, then the entire "Property" concept would need to live in QOM code too, but I don't think that is either desirable or neccessary. AFAICT, the MigrationState class init method could just call the existing object_class_property_add methods as any other non-qdev Object impl does. With regards, Daniel -- |: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
On Fri, Jun 05, 2026 at 09:43:28AM +0100, Daniel P. Berrangé wrote: > On Thu, Jun 04, 2026 at 07:11:17PM -0400, Peter Xu wrote: > > Firstly, qdev_class_add_property() function almost has nothing to do with > > DeviceClass, it's a bridge between Property and object properties. > > > > Change the 1st parameter of it, so that it can be used without DeviceClass > > context at all. When at it, remove the "name" field because it's always > > prop->name. > > > > Export it for non-qdev use cases. > > > > Signed-off-by: Peter Xu <peterx@redhat.com> > > --- > > include/hw/core/qdev-properties.h | 10 ++++++++++ > > hw/core/qdev-properties.c | 7 +++---- > > 2 files changed, 13 insertions(+), 4 deletions(-) > > > > diff --git a/include/hw/core/qdev-properties.h b/include/hw/core/qdev-properties.h > > index 779acb31b6..fec2aaac4d 100644 > > --- a/include/hw/core/qdev-properties.h > > +++ b/include/hw/core/qdev-properties.h > > @@ -283,6 +283,16 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj, > > */ > > void qdev_property_add_static(DeviceState *dev, const Property *prop); > > > > +/** > > + * object_class_add_property: > > + * @oc: Object class to operate on. > > + * @prop: The qdev property definition. > > + * > > + * Add a Property to @oc. This is the bridge to convert a Property into > > + * an object class property (as in ObjectClass.properties). > > + */ > > +void object_class_add_property(ObjectClass *oc, const Property *prop); > > I'm really not a fan of this. > > Having both object_class_add_property and object_class_property_add > methods is horrendous naming. > > Methods named with an "object_class_" prefix must live in qom/object.c & > include/qom/object.h not in qdev. If doing that though, then the entire > "Property" concept would need to live in QOM code too, but I don't think > that is either desirable or neccessary. > > AFAICT, the MigrationState class init method could just call the > existing object_class_property_add methods as any other non-qdev > Object impl does. I think I somehow missed the fact that qom does actually support setters/getters for some default types too.. with default val API: object_property_add_uint64_ptr() object_property_set_default_uint() ... I'll give it a shot. -- Peter Xu
© 2016 - 2026 Red Hat, Inc.