qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 2/5] migration: moving migration start code to a


From: Yonit Halperin
Subject: [Qemu-devel] [RFC PATCH 2/5] migration: moving migration start code to a separated routine
Date: Tue, 5 Jun 2012 08:49:43 +0300

Preparation for asynchronous migration state change notifiers.
In a following patch the migrate_start routine will be used as
the completion callback of the "migration start" notifiers list.

Signed-off-by: Yonit Halperin <address@hidden>
---
 migration.c |   73 +++++++++++++++++++++++++++++++++++++++++++++-------------
 migration.h |    2 +
 2 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/migration.c b/migration.c
index acaf293..91c807d 100644
--- a/migration.c
+++ b/migration.c
@@ -41,6 +41,14 @@ enum {
     MIG_STATE_COMPLETED,
 };
 
+enum {
+   MIGRATION_PROTOCOL_ERROR,
+   MIGRATION_PROTOCOL_TCP,
+   MIGRATION_PROTOCOL_EXEC,
+   MIGRATION_PROTOCOL_UNIX,
+   MIGRATION_PROTOCOL_FD,
+};
+
 #define MAX_THROTTLE  (32 << 20)      /* Migration speed throttling */
 
 static NotifierList migration_state_notifiers =
@@ -361,13 +369,16 @@ void migrate_fd_connect(MigrationState *s)
     migrate_fd_put_ready(s);
 }
 
-static MigrationState *migrate_init(int blk, int inc)
+static MigrationState *migrate_init(int protocol, const char *protocol_param,
+                                    int blk, int inc)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
+    s->protocol = protocol;
+    s->protocol_param = g_strdup(protocol_param);
     s->blk = blk;
     s->shared = inc;
 
@@ -389,13 +400,50 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
+static void migrate_start(MigrationState *s, Error **errp)
+{
+    int ret;
+
+    switch (s->protocol) {
+    case MIGRATION_PROTOCOL_TCP:
+        ret = tcp_start_outgoing_migration(s, s->protocol_param, errp);
+        break;
+#if !defined(WIN32)
+    case MIGRATION_PROTOCOL_EXEC:
+        ret = exec_start_outgoing_migration(s, s->protocol_param);
+        break;
+    case MIGRATION_PROTOCOL_UNIX:
+        ret = unix_start_outgoing_migration(s, s->protocol_param);
+        break;
+    case MIGRATION_PROTOCOL_FD:
+        ret = fd_start_outgoing_migration(s, s->protocol_param);
+        break;
+#endif
+    default:
+        ret = -EPROTONOSUPPORT;
+    }
+
+    g_free(s->protocol_param);
+    s->protocol_param = NULL;
+
+    if (ret < 0) {
+        if (!error_is_set(errp)) {
+            DPRINTF("migration failed: %s\n", strerror(-ret));
+            /* FIXME: we should return meaningful errors */
+            error_set(errp, QERR_UNDEFINED_ERROR);
+        }
+        return;
+    }
+    notifier_list_notify(&migration_state_notifiers, s);
+}
+
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
                  bool has_inc, bool inc, bool has_detach, bool detach,
                  Error **errp)
 {
     MigrationState *s = migrate_get_current();
     const char *p;
-    int ret;
+    int migrate_protocol;
 
     if (s->state == MIG_STATE_ACTIVE) {
         error_set(errp, QERR_MIGRATION_ACTIVE);
@@ -411,33 +459,24 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         return;
     }
 
-    s = migrate_init(blk, inc);
-
     if (strstart(uri, "tcp:", &p)) {
-        ret = tcp_start_outgoing_migration(s, p, errp);
+        migrate_protocol = MIGRATION_PROTOCOL_TCP;
 #if !defined(WIN32)
     } else if (strstart(uri, "exec:", &p)) {
-        ret = exec_start_outgoing_migration(s, p);
+        migrate_protocol = MIGRATION_PROTOCOL_EXEC;
     } else if (strstart(uri, "unix:", &p)) {
-        ret = unix_start_outgoing_migration(s, p);
+        migrate_protocol = MIGRATION_PROTOCOL_UNIX;
     } else if (strstart(uri, "fd:", &p)) {
-        ret = fd_start_outgoing_migration(s, p);
+        migrate_protocol = MIGRATION_PROTOCOL_FD;
 #endif
     } else {
         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid 
migration protocol");
         return;
     }
+    s = migrate_init(migrate_protocol, p, blk, inc);
 
-    if (ret < 0) {
-        if (!error_is_set(errp)) {
-            DPRINTF("migration failed: %s\n", strerror(-ret));
-            /* FIXME: we should return meaningful errors */
-            error_set(errp, QERR_UNDEFINED_ERROR);
-        }
-        return;
-    }
+    migrate_start(s, errp);
 
-    notifier_list_notify(&migration_state_notifiers, s);
 }
 
 void qmp_migrate_cancel(Error **errp)
diff --git a/migration.h b/migration.h
index 2e9ca2e..5ad67d7 100644
--- a/migration.h
+++ b/migration.h
@@ -33,6 +33,8 @@ struct MigrationState
     void *opaque;
     int blk;
     int shared;
+    int protocol;
+    char *protocol_param;
 };
 
 void process_incoming_migration(QEMUFile *f);
-- 
1.7.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]