Patchwork [v3,resend/cleanup,6/8] rdma: allow state transitions between other states besides ACTIVE

mail settings
Date July 12, 2013, 2:40 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/258757/
State New
Headers show

Comments - July 12, 2013, 2:40 p.m.
From: "Michael R. Hines" <>

This patch is in preparation for the next ones: Until now the MIG_STATE_SETUP
state was not really a 'formal' state. It has been used as a 'zero' state
and QEMU has been unconditionally transitioning into this state when
the QMP migrate command was called. In preparation for timing this state,
we have to make this state a a 'real' state which actually gets transitioned
from later in the migration_thread() from SETUP => ACTIVE, rather than just
automatically dropping into this state at the beginninig of the migration.

This means that the state transition function (migration_finish_set_state())
needs to be capable of transitioning from valid states _other_ than just

The function is in fact already capable of doing that, but was not allowing the
old state to be a parameter specified as an input.

This patch fixes that and only makes the transition if the current state
matches the old state that the caller intended to transition from.

Reviewed-by: Juan Quintela <>
Tested-by: Michael R. Hines <>
Signed-off-by: Michael R. Hines <>
 migration.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)


diff --git a/migration.c b/migration.c
index 2bfe245..d212871 100644
--- a/migration.c
+++ b/migration.c
@@ -295,9 +295,9 @@  static void migrate_fd_cleanup(void *opaque)
     notifier_list_notify(&migration_state_notifiers, s);
-static void migrate_finish_set_state(MigrationState *s, int new_state)
+static void migrate_set_state(MigrationState *s, int old_state, int new_state)
-    if (atomic_cmpxchg(&s->state, MIG_STATE_ACTIVE, new_state) == new_state) {
+    if (atomic_cmpxchg(&s->state, old_state, new_state) == new_state) {
@@ -315,7 +315,7 @@  static void migrate_fd_cancel(MigrationState *s)
     DPRINTF("cancelling migration\n");
-    migrate_finish_set_state(s, MIG_STATE_CANCELLED);
+    migrate_set_state(s, s->state, MIG_STATE_CANCELLED);
 void add_migration_state_change_notifier(Notifier *notify)
@@ -545,14 +545,14 @@  static void *migration_thread(void *opaque)
                 if (!qemu_file_get_error(s->file)) {
-                    migrate_finish_set_state(s, MIG_STATE_COMPLETED);
+                    migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
         if (qemu_file_get_error(s->file)) {
-            migrate_finish_set_state(s, MIG_STATE_ERROR);
+            migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
         current_time = qemu_get_clock_ms(rt_clock);