diff mbox

[v3,34/47] mig fd_connect: open return path

Message ID 1409238244-31720-35-git-send-email-dgilbert@redhat.com
State New
Headers show

Commit Message

Dr. David Alan Gilbert Aug. 28, 2014, 3:03 p.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Open the return path before migration thread creation.
Since this can fail, guard the fd cleanup so it doesn't
try and destroy the potentially non-existent thread.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/migration/migration.h |  3 +++
 migration.c                   | 18 +++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 91269c8..dbdf785 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -121,6 +121,9 @@  struct MigrationState
 
     /* Flag set once the migration has been asked to enter postcopy */
     volatile bool start_postcopy;
+    /* Flag set once the migration thread is running (and needs joining) */
+    volatile bool started_migration_thread;
+
 };
 
 void process_incoming_migration(QEMUFile *f);
diff --git a/migration.c b/migration.c
index 623a056..8ab378f 100644
--- a/migration.c
+++ b/migration.c
@@ -468,7 +468,10 @@  static void migrate_fd_cleanup(void *opaque)
     if (s->file) {
         trace_migrate_fd_cleanup();
         qemu_mutex_unlock_iothread();
-        qemu_thread_join(&s->thread);
+        if (s->started_migration_thread) {
+            qemu_thread_join(&s->thread);
+            s->started_migration_thread = false;
+        }
         qemu_mutex_lock_iothread();
 
         qemu_fclose(s->file);
@@ -1177,6 +1180,19 @@  void migrate_fd_connect(MigrationState *s)
     /* Notify before starting migration thread */
     notifier_list_notify(&migration_state_notifiers, s);
 
+    /* Open the return path; currently for postcopy but other things might
+     * also want it.
+     */
+    if (migrate_postcopy_ram()) {
+        if (open_outgoing_return_path(s)) {
+            error_report("Unable to open return-path for postcopy");
+            migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ERROR);
+            migrate_fd_cleanup(s);
+            return;
+        }
+    }
+
     qemu_thread_create(&s->thread, "migration", migration_thread, s,
                        QEMU_THREAD_JOINABLE);
+    s->started_migration_thread = true;
 }