Patchwork [20/30] migration: move begining stage to the migration thread

login
register
mail settings
Submitter Juan Quintela
Date Oct. 18, 2012, 7:30 a.m.
Message ID <1350545426-23172-21-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/192208/
State New
Headers show

Comments

Juan Quintela - Oct. 18, 2012, 7:30 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Patch

diff --git a/migration.c b/migration.c
index 65f96b7..8cacbc3 100644
--- a/migration.c
+++ b/migration.c
@@ -647,7 +647,6 @@  static int64_t buffered_get_rate_limit(void *opaque)
 static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
 {
     int ret;
-    static bool first_time = true;
     uint64_t pending_size;
     bool last_round = false;

@@ -657,17 +656,6 @@  static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
         qemu_mutex_unlock_iothread();
         return false;
     }
-    if (first_time) {
-        first_time = false;
-        DPRINTF("beginning savevm\n");
-        ret = qemu_savevm_state_begin(s->file, &s->params);
-        if (ret < 0) {
-            DPRINTF("failed, %d\n", ret);
-            migrate_fd_error(s);
-            qemu_mutex_unlock_iothread();
-            return false;
-        }
-    }

     DPRINTF("iterate\n");
     pending_size = qemu_savevm_state_pending(s->file, max_size);
@@ -716,9 +704,21 @@  static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
 static void *buffered_file_thread(void *opaque)
 {
     QEMUFileBuffered *s = opaque;
+    MigrationState *m = s->migration_state;
     int64_t initial_time = qemu_get_clock_ms(rt_clock);
     int64_t max_size = 0;
     bool last_round = false;
+    int ret;
+
+    qemu_mutex_lock_iothread();
+    DPRINTF("beginning savevm\n");
+    ret = qemu_savevm_state_begin(m->file, &m->params);
+    if (ret < 0) {
+        DPRINTF("failed, %d\n", ret);
+        qemu_mutex_unlock_iothread();
+        goto out;
+    }
+    qemu_mutex_unlock_iothread();

     while (true) {
         int64_t current_time = qemu_get_clock_ms(rt_clock);
@@ -748,10 +748,14 @@  static void *buffered_file_thread(void *opaque)
         DPRINTF("file is ready\n");
         if (s->bytes_xfer < s->xfer_limit) {
             DPRINTF("notifying client\n");
-            last_round = migrate_fd_put_ready(s->migration_state, max_size);
+            last_round = migrate_fd_put_ready(m, max_size);
         }
     }

+out:
+    if (ret < 0) {
+        migrate_fd_error(m);
+    }
     g_free(s->buffer);
     g_free(s);
     return NULL;