migration: failover: continue to wait card unplug on error
cover migration: failover: continue to wait card unplug on error
We need to wait the end of the unplug phase to be able to plug back the card.
Laurent Vivier (2):
migration: move wait-unplug loop to its own function
migration: failover: continue to wait card unplug on error
migration/migration.c | 65 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 28 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 migration: move wait-unplug loop to its own function
The loop is used in migration_thread() and bg_migration_thread(), so we can move it to its own function and call it from these both places.
Moreover, in migration_thread() we have a wrong state transition from SETUP to ACTIVE while state could be WAIT_UNPLUG. This is correctly managed in bg_migration_thread() so use this code instead.
--- migration/migration.c | 54 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-)
migration/migration.c +26 -28
@@ -3664,6 +3664,28 @@ bool migration_rate_limit(void)return urgent; } +/* +* if failover devices are present, wait they are completely +* unplugged +*/ + +static void qemu_savevm_wait_unplug (MigrationState *s,int old_state, +int new_state) +{ +if (qemu_savevm_state_guest_unplug_pending ()) { +migrate_set_state (&s->state, old_state,MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + +migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); + }else { +migrate_set_state (&s->state, old_state, new_state); + } +} +/* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel.
@@ -3710,22 +3732,10 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); -if (qemu_savevm_state_guest_unplug_pending ()) { -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_WAIT_UNPLUG ); - -while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && -qemu_savevm_state_guest_unplug_pending ()) { -qemu_sem_timedwait (&s->wait_unplug_sem,250 ); - } - -migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , -MIGRATION_STATUS_ACTIVE ); - } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_ACTIVE ); s->setup_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ) - setup_start; -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_ACTIVE );trace_migration_thread_setup_complete ();
@@ -3833,21 +3843,9 @@ static void *bg_migration_thread(void *opaque)qemu_savevm_state_header (s->to_dst_file);qemu_savevm_state_setup (s->to_dst_file); -if (qemu_savevm_state_guest_unplug_pending ()) { -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_WAIT_UNPLUG ); - -while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && -qemu_savevm_state_guest_unplug_pending ()) { -qemu_sem_timedwait (&s->wait_unplug_sem,250 ); - } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_ACTIVE ); -migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , -MIGRATION_STATUS_ACTIVE ); - }else { -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_ACTIVE ); - } s->setup_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ) - setup_start;trace_migration_thread_setup_complete ();
Signature · 1 line
2.31.1
Re: [PATCH 1/2] migration: move wait-unplug loop to its own function
Quoted 8 lines · * Laurent Vivier ([email protected]) wrote:
The loop is used in
migration_thread()andbg_migration_thread(), so we can move it to its own function and call it from these both places.Moreover, in
migration_thread()we have a wrong state transition from SETUP to ACTIVE while state could beWAIT_UNPLUG. This is correctly managed inbg_migration_thread()so use this code instead.Signed-off-by Laurent Vivier <[email protected]>
Quoted 89 lines
--- migration/migration.c | 54 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-)migration/migration.c +26
-28@@ -3664,6 +3664,28 @@ bool migration_rate_limit(void)return urgent; } +/* +* if failover devices are present, wait they are completely +* unplugged +*/ + +static void qemu_savevm_wait_unplug (MigrationState *s,int old_state, +int new_state) +{ +if (qemu_savevm_state_guest_unplug_pending ()) { +migrate_set_state (&s->state, old_state,MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + +migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); + }else { +migrate_set_state (&s->state, old_state, new_state); + } +} +/* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel. @@ -3710,22 +3732,10 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); -if (qemu_savevm_state_guest_unplug_pending ()) { -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_WAIT_UNPLUG ); - -while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && -qemu_savevm_state_guest_unplug_pending ()) { -qemu_sem_timedwait (&s->wait_unplug_sem,250 ); - } - -migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , -MIGRATION_STATUS_ACTIVE ); - } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_ACTIVE ); s->setup_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ) - setup_start; -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_ACTIVE );trace_migration_thread_setup_complete ();@@ -3833,21 +3843,9 @@ static void *bg_migration_thread(void *opaque)qemu_savevm_state_header (s->to_dst_file);qemu_savevm_state_setup (s->to_dst_file); -if (qemu_savevm_state_guest_unplug_pending ()) { -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_WAIT_UNPLUG ); - -while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && -qemu_savevm_state_guest_unplug_pending ()) { -qemu_sem_timedwait (&s->wait_unplug_sem,250 ); - } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_ACTIVE ); -migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , -MIGRATION_STATUS_ACTIVE ); - }else { -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_ACTIVE ); - } s->setup_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ) - setup_start;trace_migration_thread_setup_complete ();Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 1/2] migration: move wait-unplug loop to its own function
In reply to Laurent VivierQuoted 8 lines · Laurent Vivier
The loop is used in
migration_thread()andbg_migration_thread(), so we can move it to its own function and call it from these both places.Moreover, in
migration_thread()we have a wrong state transition from SETUP to ACTIVE while state could beWAIT_UNPLUG. This is correctly managed inbg_migration_thread()so use this code instead.Signed-off-by Laurent Vivier <[email protected]>
If you have to repost:
migration/migration.c bool migration_rate_limit(void) · line 3673
Quoted 7 lines
migration/migration.c +7
-0+/* +* if failover devices are present, wait they are completely +* unplugged +*/ + +static void qemu_savevm_wait_unplug (MigrationState *s,int old_state, +int new_state)
old_state and new state are always the same. SETUP -> ACTIVE. I think we can hardcode them.
migration/migration.c bool migration_rate_limit(void) · line 3680
Quoted 7 lines
migration/migration.c +7
-0+{ +if (qemu_savevm_state_guest_unplug_pending ()) { +migrate_set_state (&s->state, old_state,MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 );
I still don't understand why are we using a semaphore when we just want a timer :-(
Yes, this is independent of this patch.
Re: [PATCH 1/2] migration: move wait-unplug loop to its own function
Quoted 38 lines · * Juan Quintela ([email protected]) wrote:
Quoted 8 lines · Laurent Vivier
The loop is used in
migration_thread()andbg_migration_thread(), so we can move it to its own function and call it from these both places.Moreover, in
migration_thread()we have a wrong state transition from SETUP to ACTIVE while state could beWAIT_UNPLUG. This is correctly managed inbg_migration_thread()so use this code instead.Signed-off-by Laurent Vivier <[email protected]>Reviewed-by Juan Quintela <[email protected]>If you have to repost:
migration/migration.c bool migration_rate_limit(void) · line 3673
Quoted 7 lines
migration/migration.c +7
-0+/* +* if failover devices are present, wait they are completely +* unplugged +*/ + +static void qemu_savevm_wait_unplug (MigrationState *s,int old_state, +int new_state)
old_stateand new state are always the same. SETUP -> ACTIVE. I think we can hardcode them.migration/migration.c bool migration_rate_limit(void) · line 3680
Quoted 7 lines
migration/migration.c +7
-0+{ +if (qemu_savevm_state_guest_unplug_pending ()) { +migrate_set_state (&s->state, old_state,MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 );I still don't understand why are we using a semaphore when we just want a timer :-(
Quoted 1 line
Yes, this is independent of this patch.
So yes I was going to ask on the 2nd patch; no one anywhere seems to set that semaphore?
Dave
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 2/2 migration: failover: continue to wait card unplug on error
In reply to Laurent VivierIf the user cancels the migration in the unplug-wait state, QEMU will try to plug back the card and this fails because the card is partially unplugged.
To avoid the problem, continue to wait the card unplug, but to allow the migration to be canceled if the card never finishes to unplug use a timeout.
--- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
migration/migration.c +11 -0
@@ -3679,6 +3679,17 @@ static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, qemu_savevm_state_guest_unplug_pending()) {qemu_sem_timedwait (&s->wait_unplug_sem,250 ); } +if (s->state !=MIGRATION_STATUS_WAIT_UNPLUG ) { +int timeout =120 ;/* 30 seconds */ +/* +* migration has been canceled +* but as we have started an unplug we must wait the end +* to be able to plug back the card +*/ +while (timeout-- &&qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + }migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); }else {
Signature · 1 line
2.31.1
Quoted 25 lines · Laurent Vivier
If the user cancels the migration in the unplug-wait state, QEMU will try to plug back the card and this fails because the card is partially unplugged.
To avoid the problem, continue to wait the card unplug, but to allow the migration to be canceled if the card never finishes to unplug use a timeout.Signed-off-by Laurent Vivier <[email protected]>--- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+)migration/migration.c +4
-0@@ -3679,6 +3679,17 @@ static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, qemu_savevm_state_guest_unplug_pending()) {qemu_sem_timedwait (&s->wait_unplug_sem,250 ); } +if (s->state !=MIGRATION_STATUS_WAIT_UNPLUG ) { +int timeout =120 ;/* 30 seconds */ +/* +* migration has been canceled
migration/migration.c static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, · line 3695
Quoted 10 lines
migration/migration.c +7
-0+* but as we have started an unplug we must wait the end +* to be able to plug back the card +*/ +while (timeout-- &&qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + }migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); }else {
I agree with the idea. But if we are getting out due to timeout == 0, shouldn't we return some error, warning, whatever?
Later, Juan.
Quoted 34 lines · Juan Quintela
Quoted 33 lines · Laurent Vivier
If the user cancels the migration in the unplug-wait state, QEMU will try to plug back the card and this fails because the card is partially unplugged.
To avoid the problem, continue to wait the card unplug, but to allow the migration to be canceled if the card never finishes to unplug use a timeout.Signed-off-by Laurent Vivier <[email protected]>--- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+)migration/migration.c +11
-0@@ -3679,6 +3679,17 @@ static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, qemu_savevm_state_guest_unplug_pending()) {qemu_sem_timedwait (&s->wait_unplug_sem,250 ); } +if (s->state !=MIGRATION_STATUS_WAIT_UNPLUG ) { +int timeout =120 ;/* 30 seconds */ +/* +* migration has been canceled +* but as we have started an unplug we must wait the end +* to be able to plug back the card +*/ +while (timeout-- &&qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + }
Quoted 4 lines
migration/migration.c static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, · line 3695
Quoted 2 lines
migration/migration.c +0
-0migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); }else {I agree with the idea. But if we are getting out due to timeout == 0, shouldn't we return some error, warning, whatever?
In that case, we keep the current behaviour: guest kernel will report an error when it will try to plug back the card that has not been unplugged. This is a corner case: if it happens we have something really wrong with the machine. Perhaps we can remove the timeout, but I don't like to block the user, or increase it to be sure.
Thanks,
Laurent
Quoted 40 lines · Laurent Vivier
Quoted 34 lines · Juan Quintela
Quoted 33 lines · Laurent Vivier
If the user cancels the migration in the unplug-wait state, QEMU will try to plug back the card and this fails because the card is partially unplugged.
To avoid the problem, continue to wait the card unplug, but to allow the migration to be canceled if the card never finishes to unplug use a timeout.Signed-off-by Laurent Vivier <[email protected]>--- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+)migration/migration.c +11
-0@@ -3679,6 +3679,17 @@ static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, qemu_savevm_state_guest_unplug_pending()) {qemu_sem_timedwait (&s->wait_unplug_sem,250 ); } +if (s->state !=MIGRATION_STATUS_WAIT_UNPLUG ) { +int timeout =120 ;/* 30 seconds */ +/* +* migration has been canceled +* but as we have started an unplug we must wait the end +* to be able to plug back the card +*/ +while (timeout-- &&qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + }Quoted 4 lines
migration/migration.c static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, · line 3695
Quoted 2 lines
migration/migration.c +0
-0migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); }else {I agree with the idea. But if we are getting out due to timeout == 0, shouldn't we return some error, warning, whatever?
Quoted 6 lines
In that case, we keep the current behaviour: guest kernel will report an error when it
will try to plug back the card that has not been unplugged. This is a corner case: if it
happens we have something really wrong with the machine. Perhaps we can remove the timeout, but I don't like to block the user, or increase it to be sure.
Oh, I whole agree that it is a corner case, and that it shouldn't happen.
But if it happens, we don't log it anywhere. That was my complaint.
Later, Juan.
Quoted 9 lines · * Laurent Vivier ([email protected]) wrote:
If the user cancels the migration in the unplug-wait state, QEMU will try to plug back the card and this fails because the card is partially unplugged.
To avoid the problem, continue to wait the card unplug, but to allow the migration to be canceled if the card never finishes to unplug use a timeout.
I'll take this for now, but as Juan says, we could really do with some diags when this happens, so when someone comes and tells us that the hotplug has failed we can see. Please send something to add it.
Quoted 30 lines
--- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+)migration/migration.c +11
-0@@ -3679,6 +3679,17 @@ static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, qemu_savevm_state_guest_unplug_pending()) {qemu_sem_timedwait (&s->wait_unplug_sem,250 ); } +if (s->state !=MIGRATION_STATUS_WAIT_UNPLUG ) { +int timeout =120 ;/* 30 seconds */ +/* +* migration has been canceled +* but as we have started an unplug we must wait the end +* to be able to plug back the card +*/ +while (timeout-- &&qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + }migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , new_state); }else {Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 4 lines · * Laurent Vivier ([email protected]) wrote:
We need to wait the end of the unplug phase to be able to plug back the card.
Queued
Quoted 13 lines
Laurent Vivier (2):
migration: move wait-unplug loop to its own function
migration: failover: continue to wait card unplug on errormigration/migration.c | 65 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 28 deletions(-)Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK