diff mbox

avoid a bogus COMPLETED->CANCELLED transition

Message ID D3E216785288A145B7BC975F83A2ED1043EF348D@szxeml556-mbx.china.huawei.com
State New
Headers show

Commit Message

Zhanghaoyu (A) Nov. 7, 2013, 8:21 a.m. UTC
Avoid a bogus COMPLETED->CANCELLED transition.
There is a period of time from the timing of setting COMPLETED state to that of migration thread exits, so during which it's problematic in COMPLETED->CANCELLED transition.

Signed-off-by: Zeng Junliang <zengjunliang@huawei.com>
Signed-off-by: Zhang Haoyu <haoyu.zhang@huawei.com>
---
 migration.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

Comments

Paolo Bonzini Nov. 7, 2013, 9:54 a.m. UTC | #1
Il 07/11/2013 09:21, Zhanghaoyu (A) ha scritto:
> Avoid a bogus COMPLETED->CANCELLED transition.
> There is a period of time from the timing of setting COMPLETED state to that of migration thread exits, so during which it's problematic in COMPLETED->CANCELLED transition.
> 
> Signed-off-by: Zeng Junliang <zengjunliang@huawei.com>
> Signed-off-by: Zhang Haoyu <haoyu.zhang@huawei.com>
> ---
>  migration.c |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/migration.c b/migration.c
> index 2b1ab20..fd73b97 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -326,9 +326,16 @@ void migrate_fd_error(MigrationState *s)
>  
>  static void migrate_fd_cancel(MigrationState *s)
>  {
> +    int old_state ;
>      DPRINTF("cancelling migration\n");
>  
> -    migrate_set_state(s, s->state, MIG_STATE_CANCELLED);
> +    do {
> +        old_state = s->state;
> +        if (old_state != MIG_STATE_SETUP && old_state != MIG_STATE_ACTIVE) {
> +            break;
> +        }
> +        migrate_set_state(s, old_state, MIG_STATE_CANCELLED);
> +    } while (s->state != MIG_STATE_CANCELLED);
>  }
>  
>  void add_migration_state_change_notifier(Notifier *notify)
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox

Patch

diff --git a/migration.c b/migration.c
index 2b1ab20..fd73b97 100644
--- a/migration.c
+++ b/migration.c
@@ -326,9 +326,16 @@  void migrate_fd_error(MigrationState *s)
 
 static void migrate_fd_cancel(MigrationState *s)
 {
+    int old_state ;
     DPRINTF("cancelling migration\n");
 
-    migrate_set_state(s, s->state, MIG_STATE_CANCELLED);
+    do {
+        old_state = s->state;
+        if (old_state != MIG_STATE_SETUP && old_state != MIG_STATE_ACTIVE) {
+            break;
+        }
+        migrate_set_state(s, old_state, MIG_STATE_CANCELLED);
+    } while (s->state != MIG_STATE_CANCELLED);
 }
 
 void add_migration_state_change_notifier(Notifier *notify)