Patchwork [v2,4/8] monitor: Use argument type 'b' for migrate_set_speed()

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 20, 2010, 4:08 p.m.
Message ID <1264003702-17329-5-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/43299/
State New
Headers show

Comments

Markus Armbruster - Jan. 20, 2010, 4:08 p.m.
Before, it used type 's', which strips quotes and interprets escapes,
and is quite inappropriate for QMP.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 migration.c     |   18 +++---------------
 qemu-monitor.hx |    2 +-
 2 files changed, 4 insertions(+), 16 deletions(-)

Patch

diff --git a/migration.c b/migration.c
index 598f8df..4e7a1ea 100644
--- a/migration.c
+++ b/migration.c
@@ -109,23 +109,11 @@  void do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)
 void do_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
     double d;
-    char *ptr;
     FdMigrationState *s;
-    const char *value = qdict_get_str(qdict, "value");
-
-    d = strtod(value, &ptr);
-    switch (*ptr) {
-    case 'G': case 'g':
-        d *= 1024;
-    case 'M': case 'm':
-        d *= 1024;
-    case 'K': case 'k':
-        d *= 1024;
-    default:
-        break;
-    }
 
-    max_throttle = (uint32_t)d;
+    d = qdict_get_double(qdict, "value");
+    d = MAX(0, MIN(INT32_MAX, d));
+    max_throttle = d;
 
     s = migrate_to_fms(current_migration);
     if (s && s->file) {
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 415734a..9d2359d 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -761,7 +761,7 @@  ETEXI
 
     {
         .name       = "migrate_set_speed",
-        .args_type  = "value:s",
+        .args_type  = "value:b",
         .params     = "value",
         .help       = "set maximum speed (in bytes) for migrations",
         .mhandler.cmd = do_migrate_set_speed,