[PATCH 3/4] migration: Make migration object a singleton object

Peter Xu posted 4 patches 1 month ago
There is a newer version of this series
[PATCH 3/4] migration: Make migration object a singleton object
Posted by Peter Xu 1 month ago
This makes the migration object a singleton unit.  After this, we can do
something slightly tricky later on with the guarantee that nobody will be
able to create the object twice.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/migration.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/migration/migration.c b/migration/migration.c
index bcb735869b..1b5285af95 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -45,6 +45,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qnull.h"
 #include "qemu/rcu.h"
+#include "qom/object_interfaces.h"
 #include "postcopy-ram.h"
 #include "qemu/thread.h"
 #include "trace.h"
@@ -3855,11 +3856,19 @@ fail:
     migrate_fd_cleanup(s);
 }
 
+static Object* migration_get_instance(Error **errp)
+{
+    return OBJECT(current_migration);
+}
+
 static void migration_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    SingletonClass *singleton = SINGLETON_CLASS(klass);
 
     dc->user_creatable = false;
+    singleton->get_instance = migration_get_instance;
+
     device_class_set_props(dc, migration_properties);
 }
 
@@ -3932,6 +3941,10 @@ static const TypeInfo migration_type = {
     .instance_size = sizeof(MigrationState),
     .instance_init = migration_instance_init,
     .instance_finalize = migration_instance_finalize,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_SINGLETON },
+        { }
+    }
 };
 
 static void register_migration_types(void)
-- 
2.45.0
Re: [PATCH 3/4] migration: Make migration object a singleton object
Posted by Fabiano Rosas 4 weeks, 1 day ago
Peter Xu <peterx@redhat.com> writes:

> This makes the migration object a singleton unit.  After this, we can do
> something slightly tricky later on with the guarantee that nobody will be
> able to create the object twice.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  migration/migration.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/migration/migration.c b/migration/migration.c
> index bcb735869b..1b5285af95 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -45,6 +45,7 @@
>  #include "qapi/qmp/qerror.h"
>  #include "qapi/qmp/qnull.h"
>  #include "qemu/rcu.h"
> +#include "qom/object_interfaces.h"
>  #include "postcopy-ram.h"
>  #include "qemu/thread.h"
>  #include "trace.h"
> @@ -3855,11 +3856,19 @@ fail:
>      migrate_fd_cleanup(s);
>  }
>  
> +static Object* migration_get_instance(Error **errp)

static Object *migration_get_instance(Error **errp)
              ^

> +{
> +    return OBJECT(current_migration);
> +}
> +
>  static void migration_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> +    SingletonClass *singleton = SINGLETON_CLASS(klass);
>  
>      dc->user_creatable = false;
> +    singleton->get_instance = migration_get_instance;
> +
>      device_class_set_props(dc, migration_properties);
>  }
>  
> @@ -3932,6 +3941,10 @@ static const TypeInfo migration_type = {
>      .instance_size = sizeof(MigrationState),
>      .instance_init = migration_instance_init,
>      .instance_finalize = migration_instance_finalize,
> +    .interfaces = (InterfaceInfo[]) {
> +        { TYPE_SINGLETON },
> +        { }
> +    }
>  };
>  
>  static void register_migration_types(void)