9ae3a8
From 8495376b2f1376da64faa0a62a8ec06a4499d735 Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <8495376b2f1376da64faa0a62a8ec06a4499d735.1387382496.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
From: Nigel Croxon <ncroxon@redhat.com>
9ae3a8
Date: Thu, 14 Nov 2013 22:52:54 +0100
9ae3a8
Subject: [PATCH 18/46] rdma: introduce MIG_STATE_NONE and change
9ae3a8
 MIG_STATE_SETUP state transition
9ae3a8
9ae3a8
RH-Author: Nigel Croxon <ncroxon@redhat.com>
9ae3a8
Message-id: <1384469598-13137-19-git-send-email-ncroxon@redhat.com>
9ae3a8
Patchwork-id: 55699
9ae3a8
O-Subject: [RHEL7.0 PATCH 18/42] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition
9ae3a8
Bugzilla: 1011720
9ae3a8
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1011720
9ae3a8
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
9ae3a8
9ae3a8
>From commit ID:
9ae3a8
commit 29ae8a4133082e16970c9d4be09f4b6a15034617
9ae3a8
Author: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
Date:   Mon Jul 22 10:01:57 2013 -0400
9ae3a8
9ae3a8
    rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition
9ae3a8
9ae3a8
    As described in the previous patch, until now, the MIG_STATE_SETUP
9ae3a8
    state was not really a 'formal' state. It has been used as a 'zero' state
9ae3a8
    (what we're calling 'NONE' here) and QEMU has been unconditionally transitioning
9ae3a8
    into this state when the QMP migration command was called. Instead we want to
9ae3a8
    introduce MIG_STATE_NONE, which is our starting state in the state machine, and
9ae3a8
    then immediately transition into the MIG_STATE_SETUP state when the QMP migrate
9ae3a8
    command is issued.
9ae3a8
9ae3a8
    In order to do this, we must delay the transition into MIG_STATE_ACTIVE until
9ae3a8
    later in the migration_thread(). This is done to be able to timestamp the amount of
9ae3a8
    time spent in the SETUP state for proper accounting to the user during
9ae3a8
    an RDMA migration.
9ae3a8
9ae3a8
    Furthermore, the management software, until now, has never been aware of the
9ae3a8
    existence of the SETUP state whatsoever. This must change, because, timing of this
9ae3a8
    state implies that the state actually exists.
9ae3a8
9ae3a8
    These two patches cannot be separated because the 'query_migrate' QMP
9ae3a8
    switch statement needs to know how to handle this new state transition.
9ae3a8
9ae3a8
    Reviewed-by: Juan Quintela <quintela@redhat.com>
9ae3a8
    Tested-by: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
    Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
    Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
---
9ae3a8
 migration.c |   21 ++++++++++++++-------
9ae3a8
 1 files changed, 14 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 migration.c | 21 ++++++++++++++-------
9ae3a8
 1 file changed, 14 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
diff --git a/migration.c b/migration.c
9ae3a8
index e885bb7..ddbfd45 100644
9ae3a8
--- a/migration.c
9ae3a8
+++ b/migration.c
9ae3a8
@@ -36,7 +36,8 @@
9ae3a8
 #endif
9ae3a8
 
9ae3a8
 enum {
9ae3a8
-    MIG_STATE_ERROR,
9ae3a8
+    MIG_STATE_ERROR = -1,
9ae3a8
+    MIG_STATE_NONE,
9ae3a8
     MIG_STATE_SETUP,
9ae3a8
     MIG_STATE_CANCELLED,
9ae3a8
     MIG_STATE_ACTIVE,
9ae3a8
@@ -63,7 +64,7 @@ static NotifierList migration_state_notifiers =
9ae3a8
 MigrationState *migrate_get_current(void)
9ae3a8
 {
9ae3a8
     static MigrationState current_migration = {
9ae3a8
-        .state = MIG_STATE_SETUP,
9ae3a8
+        .state = MIG_STATE_NONE,
9ae3a8
         .bandwidth_limit = MAX_THROTTLE,
9ae3a8
         .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
9ae3a8
         .mbps = -1,
9ae3a8
@@ -184,9 +185,13 @@ MigrationInfo *qmp_query_migrate(Error **errp)
9ae3a8
     MigrationState *s = migrate_get_current();
9ae3a8
 
9ae3a8
     switch (s->state) {
9ae3a8
-    case MIG_STATE_SETUP:
9ae3a8
+    case MIG_STATE_NONE:
9ae3a8
         /* no migration has happened ever */
9ae3a8
         break;
9ae3a8
+    case MIG_STATE_SETUP:
9ae3a8
+        info->has_status = true;
9ae3a8
+        info->status = g_strdup("setup");
9ae3a8
+        break;
9ae3a8
     case MIG_STATE_ACTIVE:
9ae3a8
         info->has_status = true;
9ae3a8
         info->status = g_strdup("active");
9ae3a8
@@ -258,7 +263,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
9ae3a8
     MigrationState *s = migrate_get_current();
9ae3a8
     MigrationCapabilityStatusList *cap;
9ae3a8
 
9ae3a8
-    if (s->state == MIG_STATE_ACTIVE) {
9ae3a8
+    if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
9ae3a8
         error_set(errp, QERR_MIGRATION_ACTIVE);
9ae3a8
         return;
9ae3a8
     }
9ae3a8
@@ -401,7 +406,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
9ae3a8
     }
9ae3a8
 #endif
9ae3a8
 
9ae3a8
-    if (s->state == MIG_STATE_ACTIVE) {
9ae3a8
+    if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
9ae3a8
         error_set(errp, QERR_MIGRATION_ACTIVE);
9ae3a8
         return;
9ae3a8
     }
9ae3a8
@@ -551,6 +556,8 @@ static void *migration_thread(void *opaque)
9ae3a8
     DPRINTF("beginning savevm\n");
9ae3a8
     qemu_savevm_state_begin(s->file, &s->params);
9ae3a8
 
9ae3a8
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE);
9ae3a8
+
9ae3a8
     while (s->state == MIG_STATE_ACTIVE) {
9ae3a8
         int64_t current_time;
9ae3a8
         uint64_t pending_size;
9ae3a8
@@ -641,8 +648,8 @@ static void *migration_thread(void *opaque)
9ae3a8
 
9ae3a8
 void migrate_fd_connect(MigrationState *s)
9ae3a8
 {
9ae3a8
-    s->state = MIG_STATE_ACTIVE;
9ae3a8
-    trace_migrate_set_state(MIG_STATE_ACTIVE);
9ae3a8
+    s->state = MIG_STATE_SETUP;
9ae3a8
+    trace_migrate_set_state(MIG_STATE_SETUP);
9ae3a8
 
9ae3a8
     /* This is a best 1st approximation. ns to ms */
9ae3a8
     s->expected_downtime = max_downtime/1000000;
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8