There is a pattern of calling runstate_get() to store the current
runstate and calling global_state_store() to save the current runstate
for migration. Since global_state_store() also calls runstate_get(),
make it return the runstate instead.

Signed-off-by: Fabiano Rosas <faro...@suse.de>
---
 include/migration/global_state.h | 2 +-
 migration/global_state.c         | 7 +++++--
 migration/migration.c            | 6 ++----
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/migration/global_state.h b/include/migration/global_state.h
index d7c2cd3216..e268dc1f18 100644
--- a/include/migration/global_state.h
+++ b/include/migration/global_state.h
@@ -16,7 +16,7 @@
 #include "qapi/qapi-types-run-state.h"
 
 void register_global_state(void);
-void global_state_store(void);
+RunState global_state_store(void);
 void global_state_store_running(void);
 bool global_state_received(void);
 RunState global_state_get_runstate(void);
diff --git a/migration/global_state.c b/migration/global_state.c
index 4e2a9d8ec0..d094af6198 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -37,9 +37,12 @@ static void global_state_do_store(RunState state)
               state_str, '\0');
 }
 
-void global_state_store(void)
+RunState global_state_store(void)
 {
-    global_state_do_store(runstate_get());
+    RunState r = runstate_get();
+
+    global_state_do_store(r);
+    return r;
 }
 
 void global_state_store_running(void)
diff --git a/migration/migration.c b/migration/migration.c
index 67547eb6a1..0c23117369 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2344,8 +2344,7 @@ static int migration_completion_precopy(MigrationState *s,
     s->downtime_start = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
     qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
 
-    s->vm_old_state = runstate_get();
-    global_state_store();
+    s->vm_old_state = global_state_store();
 
     ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
     trace_migration_completion_vm_stop(ret);
@@ -3201,9 +3200,8 @@ static void *bg_migration_thread(void *opaque)
      * transition in vm_stop_force_state() we need to wakeup it up.
      */
     qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
-    s->vm_old_state = runstate_get();
+    s->vm_old_state = global_state_store();
 
-    global_state_store();
     /* Forcibly stop VM before saving state of vCPUs and devices */
     if (vm_stop_force_state(RUN_STATE_PAUSED)) {
         goto fail;
-- 
2.35.3


Reply via email to