Patchwork [25/41] migration: eliminate last_round

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 15, 2013, 5:46 p.m.
Message ID <1360950433-17106-26-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/220833/
State New
Headers show

Comments

Paolo Bonzini - Feb. 15, 2013, 5:46 p.m.
We will go around the loop exactly once after setting last_round.
Eliminate the variable altogether.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
Orit Wasserman - Feb. 21, 2013, 7:26 a.m.
On 02/15/2013 07:46 PM, Paolo Bonzini wrote:
> We will go around the loop exactly once after setting last_round.
> Eliminate the variable altogether.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration.c |   11 +++++------
>  1 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/migration.c b/migration.c
> index bfe6be1..5e2077e 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -614,7 +614,6 @@ static void *migration_thread(void *opaque)
>      int64_t max_size = 0;
>      int64_t start_time = initial_time;
>      bool old_vm_running = false;
> -    bool last_round = false;
>  
>      DPRINTF("beginning savevm\n");
>      qemu_savevm_state_begin(s->file, &s->params);
> @@ -638,8 +637,11 @@ static void *migration_thread(void *opaque)
>                  vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
>                  s->xfer_limit = INT_MAX;
>                  qemu_savevm_state_complete(s->file);
> -                last_round = true;
>                  qemu_mutex_unlock_iothread();
> +                if (!qemu_file_get_error(s->file)) {
> +                    __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
> +                    break;
> +                }
>              }
>          }
>          if (current_time >= initial_time + BUFFER_DELAY) {
> @@ -655,14 +657,12 @@ static void *migration_thread(void *opaque)
>              s->bytes_xfer = 0;
>              initial_time = current_time;
>          }
> -        if (!last_round && (s->bytes_xfer >= s->xfer_limit)) {
> +        if (s->bytes_xfer >= s->xfer_limit) {
>              /* usleep expects microseconds */
>              g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
>          }
>          if (qemu_file_get_error(s->file)) {
>              __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
> -        } else if (last_round) {
> -            __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
>          }
>      }
>  
> @@ -674,7 +674,6 @@ static void *migration_thread(void *opaque)
>          runstate_set(RUN_STATE_POSTMIGRATE);
>      } else {
>          if (old_vm_running) {
> -            assert(last_round);
>              vm_start();
>          }
>      }
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Juan Quintela - Feb. 22, 2013, 11:14 a.m.
Paolo Bonzini <pbonzini@redhat.com> wrote:
> We will go around the loop exactly once after setting last_round.
> Eliminate the variable altogether.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

Patch

diff --git a/migration.c b/migration.c
index bfe6be1..5e2077e 100644
--- a/migration.c
+++ b/migration.c
@@ -614,7 +614,6 @@  static void *migration_thread(void *opaque)
     int64_t max_size = 0;
     int64_t start_time = initial_time;
     bool old_vm_running = false;
-    bool last_round = false;
 
     DPRINTF("beginning savevm\n");
     qemu_savevm_state_begin(s->file, &s->params);
@@ -638,8 +637,11 @@  static void *migration_thread(void *opaque)
                 vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
                 s->xfer_limit = INT_MAX;
                 qemu_savevm_state_complete(s->file);
-                last_round = true;
                 qemu_mutex_unlock_iothread();
+                if (!qemu_file_get_error(s->file)) {
+                    __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
+                    break;
+                }
             }
         }
         if (current_time >= initial_time + BUFFER_DELAY) {
@@ -655,14 +657,12 @@  static void *migration_thread(void *opaque)
             s->bytes_xfer = 0;
             initial_time = current_time;
         }
-        if (!last_round && (s->bytes_xfer >= s->xfer_limit)) {
+        if (s->bytes_xfer >= s->xfer_limit) {
             /* usleep expects microseconds */
             g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
         }
         if (qemu_file_get_error(s->file)) {
             __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
-        } else if (last_round) {
-            __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
         }
     }
 
@@ -674,7 +674,6 @@  static void *migration_thread(void *opaque)
         runstate_set(RUN_STATE_POSTMIGRATE);
     } else {
         if (old_vm_running) {
-            assert(last_round);
             vm_start();
         }
     }