diff mbox

[4/6] rdma: allow state transitions between other states besides ACTIVE

Message ID 1372373098-5877-5-git-send-email-mrhines@linux.vnet.ibm.com
State New
Headers show

Commit Message

mrhines@linux.vnet.ibm.com June 27, 2013, 10:44 p.m. UTC
From: "Michael R. Hines" <mrhines@us.ibm.com>

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
MIG_STATE_ACTIVE.

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 <quintela@redhat.com>
Tested-by: Michael R. Hines <mrhines@us.ibm.com>
Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
---
 migration.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Eric Blake June 27, 2013, 11:10 p.m. UTC | #1
On 06/27/2013 04:44 PM, mrhines@linux.vnet.ibm.com wrote:
> From: "Michael R. Hines" <mrhines@us.ibm.com>
> 
> 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.

Isn't this a repeat from your earlier series v12?
Paolo Bonzini June 28, 2013, 7:34 a.m. UTC | #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 28/06/2013 01:10, Eric Blake ha scritto:
> Isn't this a repeat from your earlier series v12?

Juan didn't apply all the patches because he had some issues with the
later ones.

Paolo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRzTxuAAoJEBvWZb6bTYbySDAP/juOl4y2lzl3z6GBUVtZ5HbF
vC/a9PSl7RM4COMw1nOCsXHR4P+WfdnnBlENnYy/IqYEWlS/uISQLXWFZTxYnB2R
04pzkHVE5YRw/6ZIxDT9nFFOyOtSeNtCI2P0FWJ4Ef2ssshZEqZaRGhIKeHonzN5
QMzcVPZAqWn4C9Z+lIdb/g/ebMilLbyVnADVI9ThcamzifxDRUC/eF5e4ja4HWkq
uf+QhtXMLDgv/+YCdOfjQMGBYwbbhxI8xp86gMUOLjzoz7XCy1HlQQwwb7b470l4
+eK5JZEHW9teRJeHftBAjopQaUS27y0RXpyBHcFl0FXpRoW+iwhxAJg7oFxqnPv2
Fejp1yvMja9/IpqGsjOQGsaxUn+CqowJZuagNYkIeD6gh9L/Cd5IwChbPFwqG7xb
+ux5Bl3eyZG1f4JaxcgBf8drroxKkFdVhKCsal+L+0l6VKOP0K28r/nGFMfQQXBr
KT1hjIngBXVY1mWGPhbmRvO+69VD1gx2xRKs3j/1J6EmR8350YuTjKBzMmAd+e1D
lZq6e8dJLqMq5EkD3hNyRFMNCWctfuu5NGRji3r843xgu/dffAaIFeVuDRJDh1cD
Dc1law/NO+k3jqfAvIHiZOjFY+Yy/kSL3wWi+7b27TDxnCl2VR4cvJaYcFD5eMEF
q9/3/Ebn2/xho1xl5M2R
=XxMh
-----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/migration.c b/migration.c
index 62c6b85..cbfdb2c 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 (__sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE,
+    if (__sync_val_compare_and_swap(&s->state, old_state,
                                     new_state) == new_state) {
         trace_migrate_set_state(new_state);
     }
@@ -316,7 +316,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)
@@ -546,14 +546,14 @@  static void *migration_thread(void *opaque)
                 qemu_savevm_state_complete(s->file);
                 qemu_mutex_unlock_iothread();
                 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);
                     break;
                 }
             }
         }
 
         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);
             break;
         }
         current_time = qemu_get_clock_ms(rt_clock);