Patchwork [37/41] migration: small changes around rate-limiting

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

Comments

Paolo Bonzini - Feb. 15, 2013, 5:47 p.m.
This patch extracts a few small changes from the next patch, which
are unrelated to adding generic rate-limiting functionality to
QEMUFile.  Make migration_set_rate_limit a simple accessor, and
use qemu_file_set_rate_limit consistently.  Also fix a typo where
INT_MAX should have been SIZE_MAX.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
Juan Quintela - Feb. 22, 2013, 11:34 a.m.
Paolo Bonzini <pbonzini@redhat.com> wrote:
> This patch extracts a few small changes from the next patch, which
> are unrelated to adding generic rate-limiting functionality to
> QEMUFile.  Make migration_set_rate_limit a simple accessor, and
> use qemu_file_set_rate_limit consistently.  Also fix a typo where
> INT_MAX should have been SIZE_MAX.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
Orit Wasserman - Feb. 22, 2013, 12:27 p.m.
On 02/15/2013 07:47 PM, Paolo Bonzini wrote:
> This patch extracts a few small changes from the next patch, which
> are unrelated to adding generic rate-limiting functionality to
> QEMUFile.  Make migration_set_rate_limit a simple accessor, and
> use qemu_file_set_rate_limit consistently.  Also fix a typo where
> INT_MAX should have been SIZE_MAX.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration.c |   19 +++++++++++--------
>  1 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/migration.c b/migration.c
> index d636c59..308214f 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -451,10 +451,15 @@ void qmp_migrate_set_speed(int64_t value, Error **errp)
>      if (value < 0) {
>          value = 0;
>      }
> +    if (value > SIZE_MAX) {
> +        value = SIZE_MAX;
> +    }
>  
>      s = migrate_get_current();
>      s->bandwidth_limit = value;
> -    qemu_file_set_rate_limit(s->file, s->bandwidth_limit);
> +    if (s->file) {
> +        qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO);
> +    }
>  }
>  
>  void qmp_migrate_set_downtime(double value, Error **errp)
> @@ -554,11 +559,8 @@ static int64_t migration_set_rate_limit(void *opaque, int64_t new_rate)
>      if (qemu_file_get_error(s->file)) {
>          goto out;
>      }
> -    if (new_rate > SIZE_MAX) {
> -        new_rate = SIZE_MAX;
> -    }
>  
> -    s->xfer_limit = new_rate / XFER_LIMIT_RATIO;
> +    s->xfer_limit = new_rate;
>  
>  out:
>      return s->xfer_limit;
> @@ -600,7 +602,7 @@ static void *migration_thread(void *opaque)
>                  qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
>                  old_vm_running = runstate_is_running();
>                  vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
> -                s->xfer_limit = INT_MAX;
> +                qemu_file_set_rate_limit(s->file, INT_MAX);
>                  qemu_savevm_state_complete(s->file);
>                  qemu_mutex_unlock_iothread();
>                  if (!qemu_file_get_error(s->file)) {
> @@ -663,11 +665,12 @@ void migrate_fd_connect(MigrationState *s)
>  {
>      s->state = MIG_STATE_ACTIVE;
>      s->bytes_xfer = 0;
> -    s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO;
> -
>      s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
>      s->file = qemu_fopen_ops(s, &migration_file_ops);
>  
> +    qemu_file_set_rate_limit(s->file,
> +                             s->bandwidth_limit / XFER_LIMIT_RATIO);
> +
>      qemu_thread_create(&s->thread, migration_thread, s,
>                         QEMU_THREAD_JOINABLE);
>      notifier_list_notify(&migration_state_notifiers, s);
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>

Patch

diff --git a/migration.c b/migration.c
index d636c59..308214f 100644
--- a/migration.c
+++ b/migration.c
@@ -451,10 +451,15 @@  void qmp_migrate_set_speed(int64_t value, Error **errp)
     if (value < 0) {
         value = 0;
     }
+    if (value > SIZE_MAX) {
+        value = SIZE_MAX;
+    }
 
     s = migrate_get_current();
     s->bandwidth_limit = value;
-    qemu_file_set_rate_limit(s->file, s->bandwidth_limit);
+    if (s->file) {
+        qemu_file_set_rate_limit(s->file, s->bandwidth_limit / XFER_LIMIT_RATIO);
+    }
 }
 
 void qmp_migrate_set_downtime(double value, Error **errp)
@@ -554,11 +559,8 @@  static int64_t migration_set_rate_limit(void *opaque, int64_t new_rate)
     if (qemu_file_get_error(s->file)) {
         goto out;
     }
-    if (new_rate > SIZE_MAX) {
-        new_rate = SIZE_MAX;
-    }
 
-    s->xfer_limit = new_rate / XFER_LIMIT_RATIO;
+    s->xfer_limit = new_rate;
 
 out:
     return s->xfer_limit;
@@ -600,7 +602,7 @@  static void *migration_thread(void *opaque)
                 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
                 old_vm_running = runstate_is_running();
                 vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
-                s->xfer_limit = INT_MAX;
+                qemu_file_set_rate_limit(s->file, INT_MAX);
                 qemu_savevm_state_complete(s->file);
                 qemu_mutex_unlock_iothread();
                 if (!qemu_file_get_error(s->file)) {
@@ -663,11 +665,12 @@  void migrate_fd_connect(MigrationState *s)
 {
     s->state = MIG_STATE_ACTIVE;
     s->bytes_xfer = 0;
-    s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO;
-
     s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
     s->file = qemu_fopen_ops(s, &migration_file_ops);
 
+    qemu_file_set_rate_limit(s->file,
+                             s->bandwidth_limit / XFER_LIMIT_RATIO);
+
     qemu_thread_create(&s->thread, migration_thread, s,
                        QEMU_THREAD_JOINABLE);
     notifier_list_notify(&migration_state_notifiers, s);