diff mbox series

[RFC,v2,6/7] migration: Make migration object a singleton object

Message ID 20241029211607.2114845-7-peterx@redhat.com (mailing list archive)
State New
Headers show
Series QOM: Singleton interface | expand

Commit Message

Peter Xu Oct. 29, 2024, 9:16 p.m. UTC
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 mbox series

Patch

diff --git a/migration/migration.c b/migration/migration.c
index 021faee2f3..f4456f7142 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"
@@ -3833,11 +3834,19 @@  fail:
     migrate_fd_cleanup(s);
 }
 
+static Object *migration_get_instance(void)
+{
+    return object_ref(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);
 }
 
@@ -3910,6 +3919,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)