All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, leobras@redhat.com, peterx@redhat.com,
	quintela@redhat.com, vsementsov@yandex-team.ru,
	yc-core@yandex-team.ru
Subject: [PATCH 4/5] migration: switch from .vm_was_running to .vm_old_state
Date: Wed, 17 May 2023 15:37:51 +0300	[thread overview]
Message-ID: <20230517123752.21615-5-vsementsov@yandex-team.ru> (raw)
In-Reply-To: <20230517123752.21615-1-vsementsov@yandex-team.ru>

No logic change here, only refactoring. That's a preparation for next
commit where we finally restore the stopped vm state on migration
failure or cancellation.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 migration/migration.c | 11 ++++++-----
 migration/migration.h |  9 ++++++---
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index b42d028191..4ccb9f9f3b 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1422,7 +1422,7 @@ void migrate_init(MigrationState *s)
 
     s->start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
     s->total_time = 0;
-    s->vm_was_running = false;
+    s->vm_old_state = -1;
     s->iteration_initial_bytes = 0;
     s->threshold_size = 0;
 }
@@ -2312,7 +2312,8 @@ static void migration_completion(MigrationState *s)
         qemu_mutex_lock_iothread();
         s->downtime_start = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
         qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
-        s->vm_was_running = runstate_is_running();
+
+        s->vm_old_state = runstate_get();
         global_state_store();
 
         ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
@@ -2792,12 +2793,12 @@ static void migration_iteration_finish(MigrationState *s)
     case MIGRATION_STATUS_COLO:
         assert(migrate_colo());
         migrate_start_colo_process(s);
-        s->vm_was_running = true;
+        s->vm_old_state = RUN_STATE_RUNNING;
         /* Fallthrough */
     case MIGRATION_STATUS_FAILED:
     case MIGRATION_STATUS_CANCELLED:
     case MIGRATION_STATUS_CANCELLING:
-        if (s->vm_was_running) {
+        if (s->vm_old_state == RUN_STATE_RUNNING) {
             if (!runstate_check(RUN_STATE_SHUTDOWN)) {
                 vm_start();
             }
@@ -3117,7 +3118,7 @@ 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_was_running = runstate_is_running();
+    s->vm_old_state = runstate_get();
 
     global_state_store();
     /* Forcibly stop VM before saving state of vCPUs and devices */
diff --git a/migration/migration.h b/migration/migration.h
index 7721c7658b..a786778c9d 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -25,6 +25,7 @@
 #include "net/announce.h"
 #include "qom/object.h"
 #include "postcopy-ram.h"
+#include "sysemu/runstate.h"
 
 struct PostcopyBlocktimeContext;
 
@@ -310,12 +311,14 @@ struct MigrationState {
     int64_t expected_downtime;
     bool capabilities[MIGRATION_CAPABILITY__MAX];
     int64_t setup_time;
+
     /*
-     * Whether guest was running when we enter the completion stage.
+     * State before stopping the vm by vm_stop_force_state().
      * If migration is interrupted by any reason, we need to continue
-     * running the guest on source.
+     * running the guest on source if it was running or restore its stopped
+     * state.
      */
-    bool vm_was_running;
+    RunState vm_old_state;
 
     /* Flag set once the migration has been asked to enter postcopy */
     bool start_postcopy;
-- 
2.34.1



  parent reply	other threads:[~2023-05-17 12:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 12:37 [PATCH 0/5] Restore vmstate on cancelled/failed migration Vladimir Sementsov-Ogievskiy
2023-05-17 12:37 ` [PATCH 1/5] runstate: add runstate_get() Vladimir Sementsov-Ogievskiy
2023-05-18 11:13   ` Juan Quintela
2023-05-17 12:37 ` [PATCH 2/5] migration: never fail in global_state_store() Vladimir Sementsov-Ogievskiy
2023-05-18 11:18   ` Juan Quintela
2023-05-18 14:43     ` Vladimir Sementsov-Ogievskiy
2023-05-26  8:28   ` Juan Quintela
2023-05-17 12:37 ` [PATCH 3/5] runstate: drop unused runstate_store() Vladimir Sementsov-Ogievskiy
2023-05-18 11:19   ` Juan Quintela
2023-05-17 12:37 ` Vladimir Sementsov-Ogievskiy [this message]
2023-05-18 11:20   ` [PATCH 4/5] migration: switch from .vm_was_running to .vm_old_state Juan Quintela
2023-05-17 12:37 ` [PATCH 5/5] migration: restore vmstate on migration failure Vladimir Sementsov-Ogievskiy
2023-05-18 11:22   ` Juan Quintela
2023-05-18 11:23 ` [PATCH 0/5] Restore vmstate on cancelled/failed migration Juan Quintela
2023-05-18 14:49   ` Vladimir Sementsov-Ogievskiy
2023-05-26  7:59     ` Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230517123752.21615-5-vsementsov@yandex-team.ru \
    --to=vsementsov@yandex-team.ru \
    --cc=leobras@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=yc-core@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.