Skip to content

Commit 7815f69

Browse files
xzpeterFabiano Rosas
authored andcommitted
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 <[email protected]> Signed-off-by: Peter Xu <[email protected]> Message-Id: <[email protected]> Signed-off-by: Fabiano Rosas <[email protected]>
1 parent b93d897 commit 7815f69

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

migration/migration.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ static bool migration_needs_multiple_sockets(void)
135135
return migrate_multifd() || migrate_postcopy_preempt();
136136
}
137137

138+
static RunState migration_get_target_runstate(void)
139+
{
140+
/*
141+
* When the global state is not migrated, it means we don't know the
142+
* runstate of the src QEMU. We don't have much choice but assuming
143+
* the VM is running. NOTE: this is pretty rare case, so far only Xen
144+
* uses it.
145+
*/
146+
if (!global_state_received()) {
147+
return RUN_STATE_RUNNING;
148+
}
149+
150+
return global_state_get_runstate();
151+
}
152+
138153
static bool transport_supports_multi_channels(MigrationAddress *addr)
139154
{
140155
if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {
@@ -735,8 +750,7 @@ static void process_incoming_migration_bh(void *opaque)
735750
* unless we really are starting the VM.
736751
*/
737752
if (!migrate_late_block_activate() ||
738-
(autostart && (!global_state_received() ||
739-
runstate_is_live(global_state_get_runstate())))) {
753+
(autostart && runstate_is_live(migration_get_target_runstate()))) {
740754
/* Make sure all file formats throw away their mutable metadata.
741755
* If we get an error here, just don't restart the VM yet. */
742756
bdrv_activate_all(&local_err);
@@ -759,8 +773,7 @@ static void process_incoming_migration_bh(void *opaque)
759773

760774
dirty_bitmap_mig_before_vm_start();
761775

762-
if (!global_state_received() ||
763-
runstate_is_live(global_state_get_runstate())) {
776+
if (runstate_is_live(migration_get_target_runstate())) {
764777
if (autostart) {
765778
vm_start();
766779
} else {

0 commit comments

Comments
 (0)