OSDN Git Service

monitor: Use argument type 'T' for migrate_set_downtime
authorMarkus Armbruster <armbru@redhat.com>
Mon, 25 Jan 2010 13:23:07 +0000 (14:23 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 3 Feb 2010 18:36:26 +0000 (12:36 -0600)
Before, it used type 's', which strips quotes and interprets escapes,
and is quite inappropriate for QMP.

Negative arguments are no flushed to zero.  Before, they were cast to
uint32_t, which wrecked the sign.

Ridiculously large arguments including infinities are now rejected.
Before, they were interpreted as zero.  Same for NaN.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
migration.c
qemu-monitor.hx

index cd8d9e6..7551953 100644 (file)
@@ -134,21 +134,10 @@ uint64_t migrate_max_downtime(void)
 
 void do_migrate_set_downtime(Monitor *mon, const QDict *qdict)
 {
-    char *ptr;
     double d;
-    const char *value = qdict_get_str(qdict, "value");
-
-    d = strtod(value, &ptr);
-    if (!strcmp(ptr,"ms")) {
-        d *= 1000000;
-    } else if (!strcmp(ptr,"us")) {
-        d *= 1000;
-    } else if (!strcmp(ptr,"ns")) {
-    } else {
-        /* all else considered to be seconds */
-        d *= 1000000000;
-    }
 
+    d = qdict_get_double(qdict, "value") * 1e9;
+    d = MAX(0, MIN(UINT64_MAX, d));
     max_downtime = (uint64_t)d;
 }
 
index 6d47d49..2bf89c7 100644 (file)
@@ -775,7 +775,7 @@ ETEXI
 
     {
         .name       = "migrate_set_downtime",
-        .args_type  = "value:s",
+        .args_type  = "value:T",
         .params     = "value",
         .help       = "set maximum tolerated downtime (in seconds) for migrations",
         .mhandler.cmd = do_migrate_set_downtime,