diff options
author | Peter Xu <peterx@redhat.com> | 2024-12-06 18:08:33 -0500 |
---|---|---|
committer | Fabiano Rosas <farosas@suse.de> | 2025-01-09 17:38:41 -0300 |
commit | 7815f69867da92335055d4b5248430b0f122ce4e (patch) | |
tree | 7350cdb885970df8e9c20dcf952d7a6c45225993 | |
parent | b93d897ea2f0abbe7fc341a9ac176b5ecd0f3c93 (diff) | |
download | qemu-7815f69867da92335055d4b5248430b0f122ce4e.zip qemu-7815f69867da92335055d4b5248430b0f122ce4e.tar.gz qemu-7815f69867da92335055d4b5248430b0f122ce4e.tar.bz2 |
migration: Add helper to get target runstate
In 99% cases, after QEMU migrates to dest host, it tries to detect the
target VM runstate using global_state_get_runstate().
There's one outlier so far which is Xen that won't send global state.
That's the major reason why global_state_received() check was always there
together with global_state_get_runstate().
However it's utterly confusing why global_state_received() has anything to
do with "let's start VM or not".
Provide a helper to explain it, then we have an unified entry for getting
the target dest QEMU runstate after migration.
Suggested-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20241206230838.1111496-2-peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
-rw-r--r-- | migration/migration.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/migration/migration.c b/migration/migration.c index df61ca4..969b03c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -135,6 +135,21 @@ static bool migration_needs_multiple_sockets(void) return migrate_multifd() || migrate_postcopy_preempt(); } +static RunState migration_get_target_runstate(void) +{ + /* + * When the global state is not migrated, it means we don't know the + * runstate of the src QEMU. We don't have much choice but assuming + * the VM is running. NOTE: this is pretty rare case, so far only Xen + * uses it. + */ + if (!global_state_received()) { + return RUN_STATE_RUNNING; + } + + return global_state_get_runstate(); +} + static bool transport_supports_multi_channels(MigrationAddress *addr) { if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) { @@ -735,8 +750,7 @@ static void process_incoming_migration_bh(void *opaque) * unless we really are starting the VM. */ if (!migrate_late_block_activate() || - (autostart && (!global_state_received() || - runstate_is_live(global_state_get_runstate())))) { + (autostart && runstate_is_live(migration_get_target_runstate()))) { /* Make sure all file formats throw away their mutable metadata. * If we get an error here, just don't restart the VM yet. */ bdrv_activate_all(&local_err); @@ -759,8 +773,7 @@ static void process_incoming_migration_bh(void *opaque) dirty_bitmap_mig_before_vm_start(); - if (!global_state_received() || - runstate_is_live(global_state_get_runstate())) { + if (runstate_is_live(migration_get_target_runstate())) { if (autostart) { vm_start(); } else { |