Blob Blame Raw
From cfa096accd51fe9b1dfa9693ce6f4628a4e83fe6 Mon Sep 17 00:00:00 2001
From: Stefan Hajnoczi <>
Date: Tue, 13 Aug 2013 09:06:35 +0200
Subject: migration: notify migration state before starting thread

RH-Author: Stefan Hajnoczi <>
Message-id: <>
Patchwork-id: 53209
O-Subject: [PATCH v2 4/6] migration: notify migration state before starting thread
Bugzilla: 995030
RH-Acked-by: Laszlo Ersek <>
RH-Acked-by: Kevin Wolf <>
RH-Acked-by: Michael S. Tsirkin <>

The migration thread runs outside the QEMU global mutex when possible.
Therefore we must notify migration state change *before* starting the
migration thread.

This allows registered listeners to act before live migration iterations
begin.  Therefore they can get into a state that allows for live
migration.  When the migration thread starts everything will be ready.

Without this patch there is a race condition during migration setup,
depending on whether the migration thread has already transitioned from
SETUP to ACTIVE state.

Acked-by: Paolo Bonzini <>
Reviewed-by: Kevin Wolf <>
Signed-off-by: Stefan Hajnoczi <>
(cherry picked from commit 9287ac271d83166f99e050a0e0a4ebd462f7eb2b)

Signed-off-by: Stefan Hajnoczi <>

diff --git a/migration.c b/migration.c
index 6e29f72..177fc22 100644
--- a/migration.c
+++ b/migration.c
@@ -601,7 +601,9 @@ void migrate_fd_connect(MigrationState *s)
                              s->bandwidth_limit / XFER_LIMIT_RATIO);
+    /* Notify before starting migration thread */
+    notifier_list_notify(&migration_state_notifiers, s);
     qemu_thread_create(&s->thread, migration_thread, s,
-    notifier_list_notify(&migration_state_notifiers, s);