[PATCH 4/4] migration: Remove dependency to TYPE_DEVICE

Peter Xu posted 4 patches 2 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>
[PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Posted by Peter Xu 2 months ago
While doing that, we still want to keep the Property list that migration
object used to use.  Apply them directly to ObjectClass instead of setting
them with a DeviceClass.

Manually apply the two extra properties (compat properties, global
settings) in an instance_post_init() hook, just like most of the rest
users, see callers of object_apply_compat_props().

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/migration.h |  2 +-
 migration/migration.c | 33 +++++++++++++++++++--------------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/migration/migration.h b/migration/migration.h
index 841f49b215..8bdb8e8e6b 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -274,7 +274,7 @@ struct MigrationClass {
 
 struct MigrationState {
     /*< private >*/
-    DeviceState parent_obj;
+    Object parent_obj;
 
     /*< public >*/
     QemuThread thread;
diff --git a/migration/migration.c b/migration/migration.c
index 074d3f2c69..f9f102e78a 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3966,11 +3966,9 @@ fail:
 
 static void migration_class_init(ObjectClass *klass, const void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
-
-    dc->user_creatable = false;
-    device_class_set_props_n(dc, migration_properties,
-                             migration_properties_count);
+    for (int i = 0; i < migration_properties_count; i++) {
+        object_class_add_property(klass, &migration_properties[i]);
+    }
 }
 
 static void migration_instance_finalize(Object *obj)
@@ -4028,21 +4026,28 @@ static bool migration_object_check(MigrationState *ms, Error **errp)
     return migrate_caps_check(old_caps, ms->capabilities, errp);
 }
 
-static const TypeInfo migration_type = {
-    .name = TYPE_MIGRATION,
+static void migration_instance_post_init(Object *obj)
+{
     /*
-     * NOTE: TYPE_MIGRATION is not really a device, as the object is
-     * not created using qdev_new(), it is not attached to the qdev
-     * device tree, and it is never realized.
+     * Apply these properties on top of default values:
      *
-     * TODO: Make this TYPE_OBJECT once QOM provides something like
-     * TYPE_DEVICE's "-global" properties.
+     * (1) machine compat properties
+     * (2) -global settings in cmdlines
+     *
+     * Need to be applied in order so (2) takes precedence over (1).
      */
-    .parent = TYPE_DEVICE,
+    object_apply_compat_props(obj);
+    object_apply_globals(obj);
+}
+
+static const TypeInfo migration_type = {
+    .name = TYPE_MIGRATION,
+    .parent = TYPE_OBJECT,
     .class_init = migration_class_init,
-    .class_size = sizeof(MigrationClass),
+    .class_size = sizeof(ObjectClass),
     .instance_size = sizeof(MigrationState),
     .instance_init = migration_instance_init,
+    .instance_post_init = migration_instance_post_init,
     .instance_finalize = migration_instance_finalize,
 };
 
-- 
2.53.0
Re: [PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Posted by Marc-André Lureau 2 months ago
Hi

On Fri, Jun 5, 2026 at 3:12 AM Peter Xu <peterx@redhat.com> wrote:
>
> While doing that, we still want to keep the Property list that migration
> object used to use.  Apply them directly to ObjectClass instead of setting
> them with a DeviceClass.
>
> Manually apply the two extra properties (compat properties, global
> settings) in an instance_post_init() hook, just like most of the rest
> users, see callers of object_apply_compat_props().
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  migration/migration.h |  2 +-
>  migration/migration.c | 33 +++++++++++++++++++--------------
>  2 files changed, 20 insertions(+), 15 deletions(-)
>
> diff --git a/migration/migration.h b/migration/migration.h
> index 841f49b215..8bdb8e8e6b 100644
> --- a/migration/migration.h
> +++ b/migration/migration.h
> @@ -274,7 +274,7 @@ struct MigrationClass {
>
>  struct MigrationState {
>      /*< private >*/
> -    DeviceState parent_obj;
> +    Object parent_obj;
>

You need to change MigrationClass.parent_class too

>      /*< public >*/
>      QemuThread thread;
> diff --git a/migration/migration.c b/migration/migration.c
> index 074d3f2c69..f9f102e78a 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -3966,11 +3966,9 @@ fail:
>
>  static void migration_class_init(ObjectClass *klass, const void *data)
>  {
> -    DeviceClass *dc = DEVICE_CLASS(klass);
> -
> -    dc->user_creatable = false;
> -    device_class_set_props_n(dc, migration_properties,
> -                             migration_properties_count);
> +    for (int i = 0; i < migration_properties_count; i++) {
> +        object_class_add_property(klass, &migration_properties[i]);
> +    }
>  }
>
>  static void migration_instance_finalize(Object *obj)
> @@ -4028,21 +4026,28 @@ static bool migration_object_check(MigrationState *ms, Error **errp)
>      return migrate_caps_check(old_caps, ms->capabilities, errp);
>  }
>
> -static const TypeInfo migration_type = {
> -    .name = TYPE_MIGRATION,
> +static void migration_instance_post_init(Object *obj)
> +{
>      /*
> -     * NOTE: TYPE_MIGRATION is not really a device, as the object is
> -     * not created using qdev_new(), it is not attached to the qdev
> -     * device tree, and it is never realized.
> +     * Apply these properties on top of default values:
>       *
> -     * TODO: Make this TYPE_OBJECT once QOM provides something like
> -     * TYPE_DEVICE's "-global" properties.
> +     * (1) machine compat properties
> +     * (2) -global settings in cmdlines
> +     *
> +     * Need to be applied in order so (2) takes precedence over (1).
>       */
> -    .parent = TYPE_DEVICE,
> +    object_apply_compat_props(obj);
> +    object_apply_globals(obj);
> +}
> +
> +static const TypeInfo migration_type = {
> +    .name = TYPE_MIGRATION,
> +    .parent = TYPE_OBJECT,
>      .class_init = migration_class_init,
> -    .class_size = sizeof(MigrationClass),
> +    .class_size = sizeof(ObjectClass),

and this should still be MigrationClass

>      .instance_size = sizeof(MigrationState),
>      .instance_init = migration_instance_init,
> +    .instance_post_init = migration_instance_post_init,
>      .instance_finalize = migration_instance_finalize,
>  };
>
> --
> 2.53.0
>
>

Otherwise, the series is good to me!
Re: [PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Posted by Daniel P. Berrangé 2 months ago
On Fri, Jun 05, 2026 at 12:30:01PM +0400, Marc-André Lureau wrote:
> Hi
> 
> On Fri, Jun 5, 2026 at 3:12 AM Peter Xu <peterx@redhat.com> wrote:
> >
> > While doing that, we still want to keep the Property list that migration
> > object used to use.  Apply them directly to ObjectClass instead of setting
> > them with a DeviceClass.
> >
> > Manually apply the two extra properties (compat properties, global
> > settings) in an instance_post_init() hook, just like most of the rest
> > users, see callers of object_apply_compat_props().
> >
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  migration/migration.h |  2 +-
> >  migration/migration.c | 33 +++++++++++++++++++--------------
> >  2 files changed, 20 insertions(+), 15 deletions(-)
> >
> > diff --git a/migration/migration.h b/migration/migration.h
> > index 841f49b215..8bdb8e8e6b 100644
> > --- a/migration/migration.h
> > +++ b/migration/migration.h
> > @@ -274,7 +274,7 @@ struct MigrationClass {
> >
> >  struct MigrationState {
> >      /*< private >*/
> > -    DeviceState parent_obj;
> > +    Object parent_obj;
> >
> 
> You need to change MigrationClass.parent_class too

Do we even need a MigrationClass struct ? It has nothing except
the parent_class field, so feels redundant. Could the code just
use  OBJECT_DECLARE_SIMPLE_TYPE instead.

> 
> >      /*< public >*/
> >      QemuThread thread;
> > diff --git a/migration/migration.c b/migration/migration.c
> > index 074d3f2c69..f9f102e78a 100644
> > --- a/migration/migration.c
> > +++ b/migration/migration.c
> > @@ -3966,11 +3966,9 @@ fail:
> >
> >  static void migration_class_init(ObjectClass *klass, const void *data)
> >  {
> > -    DeviceClass *dc = DEVICE_CLASS(klass);
> > -
> > -    dc->user_creatable = false;
> > -    device_class_set_props_n(dc, migration_properties,
> > -                             migration_properties_count);
> > +    for (int i = 0; i < migration_properties_count; i++) {
> > +        object_class_add_property(klass, &migration_properties[i]);
> > +    }

This could get rid of migration_properties array indirection and call
object_class_property_add directly, avoiding the need for the previous
patch.

> > +static const TypeInfo migration_type = {
> > +    .name = TYPE_MIGRATION,
> > +    .parent = TYPE_OBJECT,
> >      .class_init = migration_class_init,
> > -    .class_size = sizeof(MigrationClass),
> > +    .class_size = sizeof(ObjectClass),
> 
> and this should still be MigrationClass

Not if we use OBJECT_DECLARE_SIMPLE_TYPE

> 
> >      .instance_size = sizeof(MigrationState),
> >      .instance_init = migration_instance_init,
> > +    .instance_post_init = migration_instance_post_init,
> >      .instance_finalize = migration_instance_finalize,
> >  };
> >
> > --
> > 2.53.0
> >
> >
> 
> Otherwise, the series is good to me!
> 

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


Re: [PATCH 4/4] migration: Remove dependency to TYPE_DEVICE
Posted by Peter Xu 2 months ago
On Fri, Jun 05, 2026 at 09:49:20AM +0100, Daniel P. Berrangé wrote:
> Do we even need a MigrationClass struct ? It has nothing except
> the parent_class field, so feels redundant. Could the code just
> use  OBJECT_DECLARE_SIMPLE_TYPE instead.

True, I'll add a small patch at the beginning.

Thanks,

-- 
Peter Xu