mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-31 14:02:05 -06:00
migration: Implement switchover ack logic
Implement switchover ack logic. This prevents the source from stopping the VM and completing the migration until an ACK is received from the destination that it's OK to do so. To achieve this, a new SaveVMHandlers handler switchover_ack_needed() and a new return path message MIG_RP_MSG_SWITCHOVER_ACK are added. The switchover_ack_needed() handler is called during migration setup in the destination to check if switchover ack is used by the migrated device. When switchover is approved by all migrated devices in the destination that support this capability, the MIG_RP_MSG_SWITCHOVER_ACK return path message is sent to the source to notify it that it's OK to do switchover. Signed-off-by: Avihai Horon <avihaih@nvidia.com> Reviewed-by: Peter Xu <peterx@redhat.com> Tested-by: YangHang Liu <yanghliu@redhat.com> Acked-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
6574232fff
commit
1b4adb10f8
6 changed files with 104 additions and 2 deletions
|
@ -78,6 +78,7 @@ enum mig_rp_message_type {
|
|||
MIG_RP_MSG_REQ_PAGES, /* data (start: be64, len: be32) */
|
||||
MIG_RP_MSG_RECV_BITMAP, /* send recved_bitmap back to source */
|
||||
MIG_RP_MSG_RESUME_ACK, /* tell source that we are ready to resume */
|
||||
MIG_RP_MSG_SWITCHOVER_ACK, /* Tell source it's OK to do switchover */
|
||||
|
||||
MIG_RP_MSG_MAX
|
||||
};
|
||||
|
@ -760,6 +761,11 @@ bool migration_has_all_channels(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
int migrate_send_rp_switchover_ack(MigrationIncomingState *mis)
|
||||
{
|
||||
return migrate_send_rp_message(mis, MIG_RP_MSG_SWITCHOVER_ACK, 0, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a 'SHUT' message on the return channel with the given value
|
||||
* to indicate that we've finished with the RP. Non-0 value indicates
|
||||
|
@ -1405,6 +1411,7 @@ void migrate_init(MigrationState *s)
|
|||
s->vm_old_state = -1;
|
||||
s->iteration_initial_bytes = 0;
|
||||
s->threshold_size = 0;
|
||||
s->switchover_acked = false;
|
||||
}
|
||||
|
||||
int migrate_add_blocker_internal(Error *reason, Error **errp)
|
||||
|
@ -1721,6 +1728,7 @@ static struct rp_cmd_args {
|
|||
[MIG_RP_MSG_REQ_PAGES_ID] = { .len = -1, .name = "REQ_PAGES_ID" },
|
||||
[MIG_RP_MSG_RECV_BITMAP] = { .len = -1, .name = "RECV_BITMAP" },
|
||||
[MIG_RP_MSG_RESUME_ACK] = { .len = 4, .name = "RESUME_ACK" },
|
||||
[MIG_RP_MSG_SWITCHOVER_ACK] = { .len = 0, .name = "SWITCHOVER_ACK" },
|
||||
[MIG_RP_MSG_MAX] = { .len = -1, .name = "MAX" },
|
||||
};
|
||||
|
||||
|
@ -1959,6 +1967,11 @@ retry:
|
|||
}
|
||||
break;
|
||||
|
||||
case MIG_RP_MSG_SWITCHOVER_ACK:
|
||||
ms->switchover_acked = true;
|
||||
trace_source_return_path_thread_switchover_acked();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -2693,6 +2706,20 @@ static void migration_update_counters(MigrationState *s,
|
|||
bandwidth, s->threshold_size);
|
||||
}
|
||||
|
||||
static bool migration_can_switchover(MigrationState *s)
|
||||
{
|
||||
if (!migrate_switchover_ack()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* No reason to wait for switchover ACK if VM is stopped */
|
||||
if (!runstate_is_running()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return s->switchover_acked;
|
||||
}
|
||||
|
||||
/* Migration thread iteration status */
|
||||
typedef enum {
|
||||
MIG_ITERATE_RESUME, /* Resume current iteration */
|
||||
|
@ -2708,6 +2735,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)
|
|||
{
|
||||
uint64_t must_precopy, can_postcopy;
|
||||
bool in_postcopy = s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE;
|
||||
bool can_switchover = migration_can_switchover(s);
|
||||
|
||||
qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy);
|
||||
uint64_t pending_size = must_precopy + can_postcopy;
|
||||
|
@ -2720,14 +2748,14 @@ static MigIterateState migration_iteration_run(MigrationState *s)
|
|||
trace_migrate_pending_exact(pending_size, must_precopy, can_postcopy);
|
||||
}
|
||||
|
||||
if (!pending_size || pending_size < s->threshold_size) {
|
||||
if ((!pending_size || pending_size < s->threshold_size) && can_switchover) {
|
||||
trace_migration_thread_low_pending(pending_size);
|
||||
migration_completion(s);
|
||||
return MIG_ITERATE_BREAK;
|
||||
}
|
||||
|
||||
/* Still a significant amount to transfer */
|
||||
if (!in_postcopy && must_precopy <= s->threshold_size &&
|
||||
if (!in_postcopy && must_precopy <= s->threshold_size && can_switchover &&
|
||||
qatomic_read(&s->start_postcopy)) {
|
||||
if (postcopy_start(s)) {
|
||||
error_report("%s: postcopy failed to start", __func__);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue