Patchwork [RFC,3/5] migration: moving migration completion code to a separated routine

login
register
mail settings
Submitter Yonit Halperin
Date June 5, 2012, 5:49 a.m.
Message ID <1338875386-21051-4-git-send-email-yhalperi@redhat.com>
Download mbox | patch
Permalink /patch/163021/
State New
Headers show

Comments

Yonit Halperin - June 5, 2012, 5:49 a.m.
Preparation for asynchronous migration state change notifiers.
In the following patch the migrate_end routine will be used as
the completion callback of the "migration end" notifiers list.

Signed-off-by: Yonit Halperin <yhalperi@redhat.com>
---
 migration.c |   31 ++++++++++++++++---------------
 migration.h |    1 +
 2 files changed, 17 insertions(+), 15 deletions(-)
Gerd Hoffmann - June 5, 2012, 8:46 a.m.
> +    bool start_vm_in_error;

start_vm_on_error?

cheers,
  Gerd

Patch

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);