Patchwork [03/41] migration: move more error handling to migrate_fd_cleanup

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 15, 2013, 5:46 p.m.
Message ID <1360950433-17106-4-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/220784/
State New
Headers show

Comments

Paolo Bonzini - Feb. 15, 2013, 5:46 p.m.
The next patch will add more cases where qemu_savevm_state_cancel
needs to be called; prepare for that already, the function can be
called twice with no ill effect.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
Orit Wasserman - Feb. 18, 2013, 9:13 a.m.
On 02/15/2013 07:46 PM, Paolo Bonzini wrote:
> The next patch will add more cases where qemu_savevm_state_cancel
> needs to be called; prepare for that already, the function can be
> called twice with no ill effect.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration.c |   16 ++++++++++------
>  1 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/migration.c b/migration.c
> index 2b44268..0f3cb5d 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -260,7 +260,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
>  
>  /* shared migration helpers */
>  
> -static int migrate_fd_cleanup(MigrationState *s)
> +static void migrate_fd_cleanup(MigrationState *s)
>  {
>      int ret = 0;
>  
> @@ -271,7 +271,13 @@ static int migrate_fd_cleanup(MigrationState *s)
>      }
>  
>      assert(s->fd == -1);
> -    return ret;
> +    if (ret < 0 && s->state == MIG_STATE_ACTIVE) {
> +        s->state = MIG_STATE_ERROR;
> +    }
> +
> +    if (s->state != MIG_STATE_ACTIVE) {
> +        qemu_savevm_state_cancel();
> +    }
>  }
>  
>  void migrate_fd_error(MigrationState *s)
> @@ -285,9 +291,8 @@ void migrate_fd_error(MigrationState *s)
>  static void migrate_fd_completed(MigrationState *s)
>  {
>      DPRINTF("setting completed state\n");
> -    if (migrate_fd_cleanup(s) < 0) {
> -        s->state = MIG_STATE_ERROR;
> -    } else {
> +    migrate_fd_cleanup(s);
> +    if (s->state == MIG_STATE_ACTIVE) {
>          s->state = MIG_STATE_COMPLETED;
>          runstate_set(RUN_STATE_POSTMIGRATE);
>      }
> @@ -322,7 +327,6 @@ static void migrate_fd_cancel(MigrationState *s)
>  
>      s->state = MIG_STATE_CANCELLED;
>      notifier_list_notify(&migration_state_notifiers, s);
> -    qemu_savevm_state_cancel();
>  
>      migrate_fd_cleanup(s);
>  }
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Juan Quintela - Feb. 21, 2013, 5:10 p.m.
Paolo Bonzini <pbonzini@redhat.com> wrote:
> The next patch will add more cases where qemu_savevm_state_cancel
> needs to be called; prepare for that already, the function can be
> called twice with no ill effect.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

Patch

diff --git a/migration.c b/migration.c
index 2b44268..0f3cb5d 100644
--- a/migration.c
+++ b/migration.c
@@ -260,7 +260,7 @@  void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 
 /* shared migration helpers */
 
-static int migrate_fd_cleanup(MigrationState *s)
+static void migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
 
@@ -271,7 +271,13 @@  static int migrate_fd_cleanup(MigrationState *s)
     }
 
     assert(s->fd == -1);
-    return ret;
+    if (ret < 0 && s->state == MIG_STATE_ACTIVE) {
+        s->state = MIG_STATE_ERROR;
+    }
+
+    if (s->state != MIG_STATE_ACTIVE) {
+        qemu_savevm_state_cancel();
+    }
 }
 
 void migrate_fd_error(MigrationState *s)
@@ -285,9 +291,8 @@  void migrate_fd_error(MigrationState *s)
 static void migrate_fd_completed(MigrationState *s)
 {
     DPRINTF("setting completed state\n");
-    if (migrate_fd_cleanup(s) < 0) {
-        s->state = MIG_STATE_ERROR;
-    } else {
+    migrate_fd_cleanup(s);
+    if (s->state == MIG_STATE_ACTIVE) {
         s->state = MIG_STATE_COMPLETED;
         runstate_set(RUN_STATE_POSTMIGRATE);
     }
@@ -322,7 +327,6 @@  static void migrate_fd_cancel(MigrationState *s)
 
     s->state = MIG_STATE_CANCELLED;
     notifier_list_notify(&migration_state_notifiers, s);
-    qemu_savevm_state_cancel();
 
     migrate_fd_cleanup(s);
 }