diff mbox series

[3/3] hw/s390x/s390-stattrib: Don't call register_savevm_live() during instance_init()

Message ID 20231020125728.579747-4-thuth@redhat.com
State New
Headers show
Series hw/s390x: Don't call register_savevm_live() during instance_init() | expand

Commit Message

Thomas Huth Oct. 20, 2023, 12:57 p.m. UTC
We must not call register_savevm_live() from an instance_init() function
(since this could be called multiple times during device introspection).
Move this to the realize() function instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/s390x/s390-stattrib.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

Comments

Thomas Huth Oct. 20, 2023, 1:27 p.m. UTC | #1
On 20/10/2023 14.57, Thomas Huth wrote:
> We must not call register_savevm_live() from an instance_init() function
> (since this could be called multiple times during device introspection).
> Move this to the realize() function instead.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   hw/s390x/s390-stattrib.c | 28 ++++++++++++++--------------
>   1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
> index 52f9fc036e..3217263418 100644
> --- a/hw/s390x/s390-stattrib.c
> +++ b/hw/s390x/s390-stattrib.c
> @@ -331,6 +331,17 @@ static const TypeInfo qemu_s390_stattrib_info = {
>   
>   /* Generic abstract object: */
>   
> +static SaveVMHandlers savevm_s390_stattrib_handlers = {
> +    .save_setup = cmma_save_setup,
> +    .save_live_iterate = cmma_save_iterate,
> +    .save_live_complete_precopy = cmma_save_complete,
> +    .state_pending_exact = cmma_state_pending,
> +    .state_pending_estimate = cmma_state_pending,
> +    .save_cleanup = cmma_save_cleanup,
> +    .load_state = cmma_load,
> +    .is_active = cmma_active,
> +};
> +
>   static void s390_stattrib_realize(DeviceState *dev, Error **errp)
>   {
>       bool ambiguous = false;
> @@ -339,6 +350,9 @@ static void s390_stattrib_realize(DeviceState *dev, Error **errp)
>       if (ambiguous) {
>           error_setg(errp, "storage_attributes device already exists");
>       }
> +
> +    register_savevm_live(TYPE_S390_STATTRIB, 0, 0,
> +                         &savevm_s390_stattrib_handlers, sas);
>   }

Oh, drat, I forgot to "git commit --amend" one remaining change: it should 
be "dev" instead of "sas" in above line, sorry for the confusion!

  Thomas
diff mbox series

Patch

diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 52f9fc036e..3217263418 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -331,6 +331,17 @@  static const TypeInfo qemu_s390_stattrib_info = {
 
 /* Generic abstract object: */
 
+static SaveVMHandlers savevm_s390_stattrib_handlers = {
+    .save_setup = cmma_save_setup,
+    .save_live_iterate = cmma_save_iterate,
+    .save_live_complete_precopy = cmma_save_complete,
+    .state_pending_exact = cmma_state_pending,
+    .state_pending_estimate = cmma_state_pending,
+    .save_cleanup = cmma_save_cleanup,
+    .load_state = cmma_load,
+    .is_active = cmma_active,
+};
+
 static void s390_stattrib_realize(DeviceState *dev, Error **errp)
 {
     bool ambiguous = false;
@@ -339,6 +350,9 @@  static void s390_stattrib_realize(DeviceState *dev, Error **errp)
     if (ambiguous) {
         error_setg(errp, "storage_attributes device already exists");
     }
+
+    register_savevm_live(TYPE_S390_STATTRIB, 0, 0,
+                         &savevm_s390_stattrib_handlers, sas);
 }
 
 static Property s390_stattrib_props[] = {
@@ -355,24 +369,10 @@  static void s390_stattrib_class_init(ObjectClass *oc, void *data)
     device_class_set_props(dc, s390_stattrib_props);
 }
 
-static SaveVMHandlers savevm_s390_stattrib_handlers = {
-    .save_setup = cmma_save_setup,
-    .save_live_iterate = cmma_save_iterate,
-    .save_live_complete_precopy = cmma_save_complete,
-    .state_pending_exact = cmma_state_pending,
-    .state_pending_estimate = cmma_state_pending,
-    .save_cleanup = cmma_save_cleanup,
-    .load_state = cmma_load,
-    .is_active = cmma_active,
-};
-
 static void s390_stattrib_instance_init(Object *obj)
 {
     S390StAttribState *sas = S390_STATTRIB(obj);
 
-    register_savevm_live(TYPE_S390_STATTRIB, 0, 0,
-                         &savevm_s390_stattrib_handlers, sas);
-
     sas->migration_cur_gfn = 0;
 }