Skip to contentSkip to conversation

v1] Keeping the Source side alive incase of network failure (Migration recover from network failure)

RFC In review Md Haris Iqbal 2 participants 3 messages May 31, 2016 – Jun 2, 2016

lore
Share & tools
lore
#0 lore raw

RFC 1/1 v1] Keeping the Source side alive incase of network failure (Migration recover from network failure)

---
 include/migration/migration.h |  1 +
 migration/migration.c         | 41 ++++++++++++++++++++++++++++++++++++-----
 vl.c                          |  4 ++++
 3 files changed, 41 insertions(+), 5 deletions(-)
include/migration/migration.h +1 -0
index ac2c12c..33da695 100644
@@ -325,6 +325,7 @@ void global_state_store_running(void);
 void flush_page_queue(MigrationState *ms);
 int ram_save_queue_pages(MigrationState *ms, const char *rbname,
                          ram_addr_t start, ram_addr_t len);
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState *ms);
 
 PostcopyState postcopy_state_get(void);
 /* Set the state and return the old state */
migration/migration.c +36 -5

65 lines not on this page · raw message

vl.c +4 -0
index 5fd22cb..c237140 100644
@@ -618,6 +618,10 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE_RECOVERY },
+
+    { RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_SHUTDOWN },
 
     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
     { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
Signature · 1 line
2.7.4
#1 lore raw

* Md Haris Iqbal ([email protected]) wrote:

Remember to add a more detailed comment about what the patch is doing. (And possibly split it up a bit more)

Quoted 31 lines
---
 include/migration/migration.h |  1 +
 migration/migration.c         | 41 ++++++++++++++++++++++++++++++++++++-----
 vl.c                          |  4 ++++
 3 files changed, 41 insertions(+), 5 deletions(-)
include/migration/migration.h +1 -0
index ac2c12c..33da695 100644
@@ -325,6 +325,7 @@ void global_state_store_running(void);
 void flush_page_queue(MigrationState *ms);
 int ram_save_queue_pages(MigrationState *ms, const char *rbname,
                          ram_addr_t start, ram_addr_t len);
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState *ms);
 
 PostcopyState postcopy_state_get(void);
 /* Set the state and return the old state */
migration/migration.c +1 -0
index 991313a..ee0c2a8 100644
@@ -539,6 +539,7 @@ static bool migration_is_setup_or_active(int state)
     case MIGRATION_STATUS_ACTIVE:
     case MIGRATION_STATUS_POSTCOPY_ACTIVE:
     case MIGRATION_STATUS_SETUP:
+    case MIGRATION_STATUS_POSTCOPY_RECOVERY:
         return true;
 
     default:

migration/migration.c static void *migration_thread(void *opaque) · line 1638

Quoted 4 lines
migration/migration.c +1 -0
@@ -1634,6 +1635,8 @@ static void *migration_thread(void *opaque)
     /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */
     enum MigrationStatus current_active_state = MIGRATION_STATUS_ACTIVE;
 
+    int32_t ret;

The return type of qemu_file_get_error is int not int32_t.

Quoted 4 lines
migration/migration.c +0 -0
     rcu_register_thread();
 
     qemu_savevm_state_header(s->to_dst_file);

migration/migration.c static void *migration_thread(void *opaque) · line 1707

Quoted 10 lines
migration/migration.c +2 -5
@@ -1700,11 +1703,26 @@ static void *migration_thread(void *opaque)
             }
         }
 
-        if (qemu_file_get_error(s->to_dst_file)) {
-            migrate_set_state(&s->state, current_active_state,
-                              MIGRATION_STATUS_FAILED);
-            trace_migration_thread_file_err();
-            break;
+        if ((ret = qemu_file_get_error(s->to_dst_file))) {
+            fprintf(stderr, "1 : Error %s %d\n", strerror(-ret), -ret);

Remember to clean those fprintf's out at the end; although it can be useful to leave some trace_ calls in; so for example modify
the trace_migrate_thread_file_err to take an error number.

migration/migration.c static void *migration_thread(void *opaque) · line 1709

Quoted 2 lines
migration/migration.c +2 -0
+            if(ret != -EIO && s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
+                /* Network Failure during postcopy */

That probably needs commenting as to why it's not -EIO - since that's probably what people might expect from a network error; we'll have to keep an eye out to see if that's realyl a reliable check.
(Also qemu normally puts a space after the 'if')

migration/migration.c static void *migration_thread(void *opaque) · line 1711

Quoted 1 line
migration/migration.c +1 -0
+                current_active_state = MIGRATION_STATUS_POSTCOPY_RECOVERY;

That probably needs a migrate_set_state .

Quoted 54 lines
migration/migration.c +27 -0
+                runstate_set(RUN_STATE_POSTMIGRATE_RECOVERY);
+                fprintf(stderr, "1.1 : Error %s %d\n", strerror(-ret), -ret);
+                ret = qemu_migrate_postcopy_outgoing_recovery(s);
+                if(ret < 0) {
+                    break;
+                }
+
+            } else {
+                migrate_set_state(&s->state, current_active_state,
+                                             MIGRATION_STATUS_FAILED);
+                fprintf(stderr, "1.2 : Error %s %d\n", strerror(-ret), -ret);
+                trace_migration_thread_file_err();
+                break;
+            }
         }
         current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
         if (current_time >= initial_time + BUFFER_DELAY) {
@@ -1797,6 +1815,19 @@ void migrate_fd_connect(MigrationState *s)
     s->migration_thread_running = true;
 }
 
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState* ms)
+{
+    migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE,
+                                  MIGRATION_STATUS_POSTCOPY_RECOVERY);
+
+    /* Code for network recovery to be added here */
+    while(1) {
+        fprintf(stderr, "Not letting it fail\n");
+        sleep(2);
+    }
+
+}
+
 PostcopyState  postcopy_state_get(void)
 {
     return atomic_mb_read(&incoming_postcopy_state);
vl.c +4 -0
index 5fd22cb..c237140 100644
@@ -618,6 +618,10 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE_RECOVERY },
+
+    { RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_SHUTDOWN },
 
     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
     { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
Signature · 1 line
2.7.4

Try to keep your patches together in a patch series; I find
git format-patch -n --cover-letter and then the range of patches to generate
produces the nices result and then use git send-email.

Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#2 lore raw
Quoted 3 lines · Dr. David Alan Gilbert

* Md Haris Iqbal ([email protected]) wrote:

Remember to add a more detailed comment about what the patch is doing.

Sure. I will do that in for the upcoming patches.

Quoted 1 line

(And possibly split it up a bit more)

Done, I will split it according to files.

Quoted 30 lines
Quoted 30 lines
---
 include/migration/migration.h |  1 +
 migration/migration.c         | 41 ++++++++++++++++++++++++++++++++++++-----
 vl.c                          |  4 ++++
 3 files changed, 41 insertions(+), 5 deletions(-)
include/migration/migration.h +1 -0
index ac2c12c..33da695 100644
@@ -325,6 +325,7 @@ void global_state_store_running(void);
 void flush_page_queue(MigrationState *ms);
 int ram_save_queue_pages(MigrationState *ms, const char *rbname,
                          ram_addr_t start, ram_addr_t len);
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState *ms);
 
 PostcopyState postcopy_state_get(void);
 /* Set the state and return the old state */
migration/migration.c +1 -0
index 991313a..ee0c2a8 100644
@@ -539,6 +539,7 @@ static bool migration_is_setup_or_active(int state)
     case MIGRATION_STATUS_ACTIVE:
     case MIGRATION_STATUS_POSTCOPY_ACTIVE:
     case MIGRATION_STATUS_SETUP:
+    case MIGRATION_STATUS_POSTCOPY_RECOVERY:
         return true;
 
Quoted 8 lines

migration/migration.c static void *migration_thread(void *opaque) · line 1638

Quoted 6 lines
migration/migration.c +1 -0
     default:
@@ -1634,6 +1635,8 @@ static void *migration_thread(void *opaque)
     /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */
     enum MigrationStatus current_active_state = MIGRATION_STATUS_ACTIVE;
 
+    int32_t ret;

The return type of qemu_file_get_error is int not int32_t.

But, isn't signed int typedef'd to int32_t? And signed int is the same as int.

Quoted 8 lines
Quoted 8 lines
migration/migration.c +0 -0
     rcu_register_thread();
 
     qemu_savevm_state_header(s->to_dst_file);
@@ -1700,11 +1703,26 @@ static void *migration_thread(void *opaque)
             }
         }
 
Quoted 9 lines

migration/migration.c static void *migration_thread(void *opaque) · line 1707

Quoted 7 lines
migration/migration.c +2 -5
-        if (qemu_file_get_error(s->to_dst_file)) {
-            migrate_set_state(&s->state, current_active_state,
-                              MIGRATION_STATUS_FAILED);
-            trace_migration_thread_file_err();
-            break;
+        if ((ret = qemu_file_get_error(s->to_dst_file))) {
+            fprintf(stderr, "1 : Error %s %d\n", strerror(-ret), -ret);

Remember to clean those fprintf's out at the end;

Yes, I will do that while preparing the final patch. These are good for now, because I can see things happening when I run.

Quoted 3 lines

although it can be useful
to leave some trace_ calls in; so for example modify the trace_migrate_thread_file_err to take an error number.

Yes, I will add trace_ calls.

Quoted 8 lines

migration/migration.c static void *migration_thread(void *opaque) · line 1709

Quoted 3 lines
migration/migration.c +2 -0
+            if(ret != -EIO && s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
+                /* Network Failure during postcopy */

That probably needs commenting as to why it's not -EIO - since that's probably what people might expect from a network error; we'll have to keep an eye out to see if that's realyl a reliable check.
(Also qemu normally puts a space after the 'if')

Done.

Quoted 55 lines

migration/migration.c static void *migration_thread(void *opaque) · line 1711

Quoted 2 lines
migration/migration.c +1 -0
+                current_active_state = MIGRATION_STATUS_POSTCOPY_RECOVERY;

That probably needs a migrate_set_state .

Quoted 50 lines
migration/migration.c +27 -0
+                runstate_set(RUN_STATE_POSTMIGRATE_RECOVERY);
+                fprintf(stderr, "1.1 : Error %s %d\n", strerror(-ret), -ret);
+                ret = qemu_migrate_postcopy_outgoing_recovery(s);
+                if(ret < 0) {
+                    break;
+                }
+
+            } else {
+                migrate_set_state(&s->state, current_active_state,
+                                             MIGRATION_STATUS_FAILED);
+                fprintf(stderr, "1.2 : Error %s %d\n", strerror(-ret), -ret);
+                trace_migration_thread_file_err();
+                break;
+            }
         }
         current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
         if (current_time >= initial_time + BUFFER_DELAY) {
@@ -1797,6 +1815,19 @@ void migrate_fd_connect(MigrationState *s)
     s->migration_thread_running = true;
 }
 
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState* ms)
+{
+    migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE,
+                                  MIGRATION_STATUS_POSTCOPY_RECOVERY);
+
+    /* Code for network recovery to be added here */
+    while(1) {
+        fprintf(stderr, "Not letting it fail\n");
+        sleep(2);
+    }
+
+}
+
 PostcopyState  postcopy_state_get(void)
 {
     return atomic_mb_read(&incoming_postcopy_state);
vl.c +4 -0
index 5fd22cb..c237140 100644
@@ -618,6 +618,10 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE_RECOVERY },
+
+    { RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_SHUTDOWN },
 
Quoted 8 lines
Quoted 4 lines
vl.c +0 -1
     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
     { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
--

2.7.4

Try to keep your patches together in a patch series; I find
git format-patch -n --cover-letter and then the range of patches to generate
produces the nices result and then use git send-email.

Ok. I will use this from next time.

Quoted 4 lines

Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 6 lines
With regards,

Md Haris Iqbal,
Placement Coordinator, MTech IT
NITK Surathkal,
Contact: +91 8861996962