[Spice-devel] [RFC PATCH 3/4] migration: moving migration completion code to a separated routine

Yonit Halperin yhalperi at redhat.com
Wed May 30 02:02:38 PDT 2012


Preparation for asynchronous migration state change notifiers.

Signed-off-by: Yonit Halperin <yhalperi at redhat.com>
---
 migration.c |   31 ++++++++++++++++---------------
 migration.h |    1 +
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/migration.c b/migration.c
index 91c807d..c86611d 100644
--- a/migration.c
+++ b/migration.c
@@ -187,24 +187,32 @@ static int migrate_fd_cleanup(MigrationState *s)
     return ret;
 }
 
+static void migrate_end(MigrationState *s, int end_state)
+{
+    s->state = end_state;
+    if (s->state == MIG_STATE_COMPLETED) {
+        runstate_set(RUN_STATE_POSTMIGRATE);
+    } else if (s->state == MIG_STATE_ERROR && s->start_vm_in_error) {
+        vm_start();
+    }
+    notifier_list_notify(&migration_state_notifiers, s);
+}
+
 void migrate_fd_error(MigrationState *s)
 {
     DPRINTF("setting error state\n");
-    s->state = MIG_STATE_ERROR;
-    notifier_list_notify(&migration_state_notifiers, s);
     migrate_fd_cleanup(s);
+    migrate_end(s, MIG_STATE_ERROR);
 }
 
 static void migrate_fd_completed(MigrationState *s)
 {
     DPRINTF("setting completed state\n");
     if (migrate_fd_cleanup(s) < 0) {
-        s->state = MIG_STATE_ERROR;
+        migrate_end(s, MIG_STATE_ERROR);
     } else {
-        s->state = MIG_STATE_COMPLETED;
-        runstate_set(RUN_STATE_POSTMIGRATE);
+        migrate_end(s, MIG_STATE_COMPLETED);
     }
-    notifier_list_notify(&migration_state_notifiers, s);
 }
 
 static void migrate_fd_put_notify(void *opaque)
@@ -257,7 +265,7 @@ static void migrate_fd_put_ready(void *opaque)
     if (ret < 0) {
         migrate_fd_error(s);
     } else if (ret == 1) {
-        int old_vm_running = runstate_is_running();
+        s->start_vm_in_error = runstate_is_running();
 
         DPRINTF("done iterating\n");
         qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
@@ -268,11 +276,6 @@ static void migrate_fd_put_ready(void *opaque)
         } else {
             migrate_fd_completed(s);
         }
-        if (s->state != MIG_STATE_COMPLETED) {
-            if (old_vm_running) {
-                vm_start();
-            }
-        }
     }
 }
 
@@ -283,11 +286,9 @@ static void migrate_fd_cancel(MigrationState *s)
 
     DPRINTF("cancelling migration\n");
 
-    s->state = MIG_STATE_CANCELLED;
-    notifier_list_notify(&migration_state_notifiers, s);
     qemu_savevm_state_cancel(s->file);
-
     migrate_fd_cleanup(s);
+    migrate_end(s, MIG_STATE_CANCELLED);
 }
 
 static void migrate_fd_wait_for_unfreeze(void *opaque)
diff --git a/migration.h b/migration.h
index 5ad67d7..6a0f49f 100644
--- a/migration.h
+++ b/migration.h
@@ -35,6 +35,7 @@ struct MigrationState
     int shared;
     int protocol;
     char *protocol_param;
+    bool start_vm_in_error;
 };
 
 void process_incoming_migration(QEMUFile *f);
-- 
1.7.7.6



More information about the Spice-devel mailing list