diff mbox

[RFC,04/13] migration: Create a snapshot thread to realize saving memory snapshot

Message ID 1452169208-840-5-git-send-email-zhang.zhanghailiang@huawei.com
State New
Headers show

Commit Message

Zhanghailiang Jan. 7, 2016, 12:19 p.m. UTC
If users use migrate file:url command, we consider it as creating
live memory snapshot command.
Besides, we only support tcg accel for now.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 include/migration/migration.h |  2 ++
 migration/fd.c                |  4 ++++
 migration/migration.c         | 30 ++++++++++++++++++++++++++++--
 3 files changed, 34 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 3f372a5..1316d22 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -171,6 +171,7 @@  struct MigrationState
     QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;
     /* The RAMBlock used in the last src_page_request */
     RAMBlock *last_req_rb;
+    bool in_snapshot; /* for snapshot */
 };
 
 void process_incoming_migration(QEMUFile *f);
@@ -215,6 +216,7 @@  void add_migration_state_change_notifier(Notifier *notify);
 void remove_migration_state_change_notifier(Notifier *notify);
 MigrationState *migrate_init(const MigrationParams *params);
 bool migration_in_setup(MigrationState *);
+bool migration_in_snapshot(MigrationState *);
 bool migration_has_finished(MigrationState *);
 bool migration_has_failed(MigrationState *);
 /* True if outgoing migration has entered postcopy phase */
diff --git a/migration/fd.c b/migration/fd.c
index ac38256..6036560 100644
--- a/migration/fd.c
+++ b/migration/fd.c
@@ -69,6 +69,10 @@  void file_start_outgoing_migration(MigrationState *s, const char *filename,
         error_setg_errno(errp, errno, "Failed to open file: %s", filename);
         return;
     }
+    /* Fix me: just for test
+    *  we shouldn't use this to identify if we are do snapshot.
+    */
+    s->in_snapshot = true;
     fd_start_outgoing_migration(s, NULL, fd, errp);
 }
 
diff --git a/migration/migration.c b/migration/migration.c
index e54910d..7633043 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -33,6 +33,7 @@ 
 #include "qom/cpu.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
+#include "hw/boards.h" /* Fix me: Remove this if we support snapshot for KVM */
 
 #define MAX_THROTTLE  (32 << 20)      /* Migration transfer speed throttling */
 
@@ -901,6 +902,11 @@  bool migration_in_postcopy(MigrationState *s)
     return (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);
 }
 
+bool migration_in_snapshot(MigrationState *s)
+{
+    return s->in_snapshot;
+}
+
 MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
@@ -1732,6 +1738,21 @@  static void *migration_thread(void *opaque)
     return NULL;
 }
 
+static void *snapshot_thread(void *opaque)
+{
+    rcu_register_thread();
+    /* Fix me: Remove this if we support snapshot for KVM */
+    if (strcmp(current_machine->accel, "tcg")) {
+        error_report("snapshot only support 'tcg' accel for now");
+        goto error;
+    }
+
+    /* TODO: create memory snapshot */
+
+error:
+    rcu_unregister_thread();
+    return NULL;
+}
 void migrate_fd_connect(MigrationState *s)
 {
     /* This is a best 1st approximation. ns to ms */
@@ -1759,8 +1780,13 @@  void migrate_fd_connect(MigrationState *s)
     }
 
     migrate_compress_threads_create();
-    qemu_thread_create(&s->thread, "migration", migration_thread, s,
-                       QEMU_THREAD_JOINABLE);
+    if (!s->in_snapshot) {
+        qemu_thread_create(&s->thread, "migration", migration_thread, s,
+                           QEMU_THREAD_JOINABLE);
+    } else {
+       qemu_thread_create(&s->thread, "snapshot", snapshot_thread, s,
+                          QEMU_THREAD_JOINABLE);
+   }
     s->migration_thread_running = true;
 }