[RFC 4/4] A separate thread for the VM migration

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

 



This patch creates a separate thread for the guest migration on the target side.


Signed-off-by: Umesh Deshpande <udeshpan@xxxxxxxxxx>
---
 migration-exec.c |    7 +++----
 migration-fd.c   |    4 ++--
 migration-tcp.c  |    9 +++++----
 migration-unix.c |   10 ++++++----
 migration.c      |   32 ++++++++++++++++++++++++++++++--
 migration.h      |   16 +++++++++++++++-
 6 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index 4b7aad8..04140e2 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -120,12 +120,11 @@ err_after_alloc:
 static void exec_accept_incoming_migration(void *opaque)
 {
     QEMUFile *f = opaque;
-
-    process_incoming_migration(f);
+    process_incoming_migration(f, qemu_stdio_fd(f), 0, MIG_EXEC);
     qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
-    qemu_fclose(f);
 }
 
+
 int exec_start_incoming_migration(const char *command)
 {
     QEMUFile *f;
@@ -138,7 +137,7 @@ int exec_start_incoming_migration(const char *command)
     }
 
     qemu_set_fd_handler2(qemu_stdio_fd(f), NULL,
-			 exec_accept_incoming_migration, NULL, f);
+                         exec_accept_incoming_migration, NULL, f);
 
     return 0;
 }
diff --git a/migration-fd.c b/migration-fd.c
index 66d51c1..24f195f 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -100,13 +100,13 @@ err_after_alloc:
     return NULL;
 }
 
+
 static void fd_accept_incoming_migration(void *opaque)
 {
     QEMUFile *f = opaque;
 
-    process_incoming_migration(f);
+    process_incoming_migration(f, qemu_stdio_fd(f), 0, MIG_FD);
     qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
-    qemu_fclose(f);
 }
 
 int fd_start_incoming_migration(const char *infd)
diff --git a/migration-tcp.c b/migration-tcp.c
index d3d80c9..ad1b9d0 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -159,13 +159,15 @@ static void tcp_accept_incoming_migration(void *opaque)
         goto out;
     }
 
-    process_incoming_migration(f);
-    qemu_fclose(f);
+    process_incoming_migration(f, s, c, MIG_UNIX);
+    goto out3;
 out:
     close(c);
 out2:
-    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
     close(s);
+out3:
+    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+    return;
 }
 
 int tcp_start_incoming_migration(const char *host_port)
@@ -194,7 +196,6 @@ int tcp_start_incoming_migration(const char *host_port)
 
     qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
                          (void *)(intptr_t)s);
-
     return 0;
 
 err:
diff --git a/migration-unix.c b/migration-unix.c
index c8625c7..ed57d5a 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -167,12 +166,14 @@ static void unix_accept_incoming_migration(void *opaque)
         goto out;
     }
 
-    process_incoming_migration(f);
-    qemu_fclose(f);
+    process_incoming_migration(f, s, c, MIG_UNIX);
+    goto out2;
 out:
-    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
     close(s);
     close(c);
+out2:
+    qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
+    return;
 }
 
 int unix_start_incoming_migration(const char *path)
@@ -203,7 +204,7 @@ int unix_start_incoming_migration(const char *path)
     }
 
     qemu_set_fd_handler2(sock, NULL, unix_accept_incoming_migration, NULL,
-			 (void *)(intptr_t)sock);
+                         (void *)(intptr_t)sock);
 
     return 0;
 
diff --git a/migration.c b/migration.c
index af3a1f2..34b1aa6 100644
--- a/migration.c
+++ b/migration.c
@@ -61,9 +64,10 @@ int qemu_start_incoming_migration(const char *uri)
     return ret;
 }
 
-void process_incoming_migration(QEMUFile *f)
+static void *incoming_migration_thread(void *arg)
 {
-    if (qemu_loadvm_state(f) < 0) {
+    MigrationArg *p = arg;
+    if (qemu_loadvm_state(p->f) < 0) {
         fprintf(stderr, "load of migration failed\n");
         exit(0);
     }
@@ -74,6 +78,33 @@ void process_incoming_migration(QEMUFile *f)
 
     if (autostart)
         vm_start();
+
+    qemu_fclose(p->f);
+
+    if (p->type == MIG_TCP || p->type == MIG_UNIX) {
+        close(p->migration_port);
+        close(p->host_port);
+    }
+
+    qemu_free(p);
+    return NULL;
+}
+
+void process_incoming_migration(QEMUFile *f, int host_port,
+                                int migration_port, int type)
+{
+    MigrationArg *arg;
+    struct QemuThread migrate_incoming_thread;
+
+    arg = qemu_mallocz(sizeof(*arg));
+
+    arg->f = f;
+    arg->host_port = host_port;
+    arg->migration_port = migration_port;
+    arg->type = type;
+
+    qemu_thread_create(&migrate_incoming_thread,
+                       incoming_migration_thread, arg);
 }
 
 int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
diff --git a/migration.h b/migration.h
index 050c56c..33318d9 100644
--- a/migration.h
+++ b/migration.h
@@ -23,6 +23,11 @@
 #define MIG_STATE_CANCELLED	1
 #define MIG_STATE_ACTIVE	2
 
+#define MIG_TCP             1
+#define MIG_UNIX            2
+#define MIG_FD              3
+#define MIG_EXEC            4
+
 typedef struct MigrationState MigrationState;
 
 struct MigrationState
@@ -51,7 +56,16 @@ struct FdMigrationState
     void *opaque;
 };
 
-void process_incoming_migration(QEMUFile *f);
+typedef struct MigrationArg MigrationArg;
+
+struct MigrationArg {
+    QEMUFile *f;
+    int host_port;
+    int migration_port;
+    int type;
+};
+
+void process_incoming_migration(QEMUFile *f, int, int, int);
 
 int qemu_start_incoming_migration(const char *uri);
 
--
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux