Migration 20230601 patches
[PULL 3/6] runstate: drop unused runstate_store()
In reply to Juan QuintelaFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
The function is unused since previous commit. Drop it.
Message-Id: <[email protected]>
--- include/sysemu/runstate.h | 1 - softmmu/runstate.c | 12 ------------ 2 files changed, 13 deletions(-)
include/sysemu/runstate.h +0 -1
@@ -9,7 +9,6 @@ void runstate_set(RunState new_state);RunState runstate_get (void );bool runstate_is_running (void );bool runstate_needs_reset (void ); -bool runstate_store (char *str,size_t size);typedef void VMChangeStateHandler (void *opaque,bool running,RunState state);
softmmu/runstate.c +0 -12
@@ -175,18 +175,6 @@ bool runstate_check(RunState state)return current_run_state == state; } -bool runstate_store (char *str,size_t size) -{ -const char *state =RunState_str (current_run_state); -size_t len =strlen (state) +1 ; - -if (len > size) { -return false; - } -memcpy (str, state, len); -return true; -} -static void runstate_init (void ) {const RunStateTransition *p;
Signature · 1 line
2.40.1
[PULL 1/6] runstate: add runstate_get()
In reply to Juan QuintelaFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
It's necessary to restore the state after failed/cancelled migration in further commit.
Message-Id: <[email protected]>
--- include/sysemu/runstate.h | 1 + softmmu/runstate.c | 5 +++++ 2 files changed, 6 insertions(+)
include/sysemu/runstate.h +1 -0
@@ -6,6 +6,7 @@bool runstate_check (RunState state);void runstate_set (RunState new_state); +RunState runstate_get (void );bool runstate_is_running (void );bool runstate_needs_reset (void );bool runstate_store (char *str,size_t size);
softmmu/runstate.c +5 -0
@@ -221,6 +221,11 @@ void runstate_set(RunState new_state) current_run_state = new_state; } +RunState runstate_get (void ) +{ +return current_run_state; +} +bool runstate_is_running (void ) {return runstate_check (RUN_STATE_RUNNING );
Signature · 1 line
2.40.1
[PULL 4/6] migration: switch from .vm_was_running to .vm_old_state
In reply to Juan QuintelaFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
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.
Message-Id: <[email protected]>
--- migration/migration.h | 9 ++++++--- migration/migration.c | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-)
migration/migration.h +6 -3
@@ -25,6 +25,7 @@#include "net/announce.h" #include "qom/object.h" #include "postcopy-ram.h" +#include "sysemu/runstate.h" struct PostcopyBlocktimeContext ;
@@ -317,12 +318,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;
migration/migration.c +6 -5
@@ -1402,7 +1402,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 ; }
@@ -2287,7 +2287,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 );
@@ -2760,12 +2761,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 (); }
@@ -3085,7 +3086,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 */
Signature · 1 line
2.40.1
[PULL 6/6] migration: stop tracking ram writes when cancelling background migration
In reply to Juan QuintelaFrom: Fiona Ebner <[email protected]>
Currently, it is only done when the iteration finishes successfully. Not cleaning up the userfaultfd write protection can lead to symptoms/issues such as the process hanging in memmove or GDB not being able to attach.
Message-Id: <[email protected]>
--- migration/migration.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
migration/migration.c +7 -7
@@ -2400,13 +2400,6 @@ static void bg_migration_completion(MigrationState *s) {int current_active_state = s->state; -/* -* Stop tracking RAM writes - un-protect memory, un-register UFFD -* memory ranges, flush kernel wait queues and wake up threads -* waiting for write fault to be resolved. -*/ -ram_write_tracking_stop (); -if (s->state ==MIGRATION_STATUS_ACTIVE ) {/* * By this moment we have RAM content saved into the migration stream.
@@ -2788,6 +2781,13 @@ static void migration_iteration_finish(MigrationState *s)static void bg_migration_iteration_finish (MigrationState *s) { +/* +* Stop tracking RAM writes - un-protect memory, un-register UFFD +* memory ranges, flush kernel wait queues and wake up threads +* waiting for write fault to be resolved. +*/ +ram_write_tracking_stop (); +qemu_mutex_lock_iothread ();switch (s->state) {case MIGRATION_STATUS_COMPLETED :
Signature · 1 line
2.40.1
The following changes since commit 9eb400cdd7b0940bd696aa01462dd53004ae04e9:
Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2023-06-01 11:47:58 -0700)
are available in the Git repository at:
https://gitlab.com/juan.quintela/qemu.git tags/migration-20230601-pull-request
for you to fetch changes up to 3a8b81f2e6393828589699bb0b8ef557b9ae5937:
migration: stop tracking ram writes when cancelling background migration (2023-06-02 01:03:19 +0200)
----------------------------------------------------------------
Migration Pull request (20230601)
Hi
In this series:
- improve background migration (fiona)
- improve vmstate failure states (vladimir)
- dropped all the RDMA cleanups
Please, apply.
----------------------------------------------------------------
Fiona Ebner (1):
migration: stop tracking ram writes when cancelling background
migration
Vladimir Sementsov-Ogievskiy (5):
runstate: add runstate_get()
migration: never fail in global_state_store()
runstate: drop unused runstate_store()
migration: switch from .vm_was_running to .vm_old_state
migration: restore vmstate on migration failure
include/migration/global_state.h | 2 +- include/sysemu/runstate.h | 2 +- migration/migration.h | 9 +++-- migration/global_state.c | 29 +++++++------- migration/migration.c | 68 ++++++++++++++++---------------- migration/savevm.c | 6 +-- softmmu/runstate.c | 25 ++++++------ 7 files changed, 68 insertions(+), 73 deletions(-)
Signature · 1 line
2.40.1
[PULL 5/6] migration: restore vmstate on migration failure
From: Vladimir Sementsov-Ogievskiy <[email protected]>
1. Otherwise failed migration just drops guest-panicked state, which is not good for management software.
2. We do keep different paused states like guest-panicked during migration with help of global_state state.
3. We do restore running state on source when migration is cancelled or failed.
4. "postmigrate" state is documented as "guest is paused following a successful 'migrate'", so originally it's only for successful path and we never documented current behavior.
Let's restore paused states like guest-panicked in case of cancel or fail too. Allow same transitions like for inmigrate state.
This commit changes the behavior that was introduced by commit 42da5550d6 "migration: set state to post-migrate on failure" and provides a bit different fix on related
https://bugzilla.redhat.com/show_bug.cgi?id=1355683
Message-Id: <[email protected]>
--- migration/migration.c | 2 +- softmmu/runstate.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-)
migration/migration.c +1 -1
@@ -2772,7 +2772,7 @@ static void migration_iteration_finish(MigrationState *s) } }else {if (runstate_check (RUN_STATE_FINISH_MIGRATE )) { -runstate_set (RUN_STATE_POSTMIGRATE ); +runstate_set (s->vm_old_state); } }break ;
softmmu/runstate.c +7 -1
@@ -121,7 +121,13 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH }, - { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO}, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_INTERNAL_ERROR }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_IO_ERROR }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_SHUTDOWN }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_SUSPENDED }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_WATCHDOG }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_GUEST_PANICKED }, { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
Signature · 1 line
2.40.1
[PULL 2/6] migration: never fail in global_state_store()
In reply to Juan QuintelaFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Actually global_state_store() can never fail. Let's get rid of extra error paths.
To make things clear, use new runstate_get() and use same approach for global_state_store() and global_state_store_running().
Message-Id: <[email protected]>
--- include/migration/global_state.h | 2 +- migration/global_state.c | 29 +++++++++++----------- migration/migration.c | 41 +++++++++++++++----------------- migration/savevm.c | 6 +---- 4 files changed, 35 insertions(+), 43 deletions(-)
include/migration/global_state.h +1 -1
@@ -16,7 +16,7 @@#include "qapi/qapi-types-run-state.h" void register_global_state (void ); -int global_state_store (void ); +void global_state_store (void );void global_state_store_running (void );bool global_state_received (void );RunState global_state_get_runstate (void );
migration/global_state.c +14 -15
@@ -29,23 +29,22 @@ typedef struct {static GlobalState global_state; -int global_state_store (void ) +static void global_state_do_store (RunState state) { -if (!runstate_store ((char *)global_state.runstate, -sizeof (global_state.runstate))) { -error_report ("runstate name too big: %s" , global_state.runstate); -trace_migrate_state_too_big (); -return -EINVAL ; - } -return 0 ; -} - -void global_state_store_running (void ) -{ -const char *state =RunState_str (RUN_STATE_RUNNING ); -assert (strlen (state) <sizeof (global_state.runstate)); +const char *state_str =RunState_str (state); +assert (strlen (state_str) <sizeof (global_state.runstate));strpadcpy ((char *)global_state.runstate,sizeof (global_state.runstate), - state,'\0' ); + state_str,'\0' ); +} + +void global_state_store (void ) +{ +global_state_do_store (runstate_get ()); +} + +void global_state_store_running (void ) +{ +global_state_do_store (RUN_STATE_RUNNING ); }bool global_state_received (void )
migration/migration.c +19 -22
55 lines not on this page · raw message
migration/savevm.c +1 -5
@@ -2919,11 +2919,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate, saved_vm_running =runstate_is_running (); - ret =global_state_store (); -if (ret) { -error_setg (errp,"Error saving global state" ); -return false; - } +global_state_store ();vm_stop (RUN_STATE_SAVE_VM );bdrv_drain_all_begin ();
Signature · 1 line
2.40.1
Richard Henderson
AppliedQuoted 17 lines · Juan Quintela
The following changes since commit
9eb400cdd7b0940bd696aa01462dd53004ae04e9:Merge tag 'block-pull-request' ofhttps://gitlab.com/stefanha/qemu into staging (2023-06-01 11:47:58 -0700)are available in the Git repository at:
https://gitlab.com/juan.quintela/qemu.git tags/migration-20230601-pull-requestfor you to fetch changes up to
3a8b81f2e6393828589699bb0b8ef557b9ae5937:migration: stop tracking ram writes when cancelling background migration (2023-06-02 01:03:19 +0200)
----------------------------------------------------------------
Migration Pull request (20230601)Hi
Quoted 8 lines
In this series:
- improve background migration (fiona)
- improve vmstate failure states (vladimir)
- dropped all the RDMA cleanupsPlease, apply.
----------------------------------------------------------------
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~