qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v3 4/8] monitor: Use argument type 'b' for migrate_set_speed
Date: Mon, 25 Jan 2010 14:23:04 +0100	[thread overview]
Message-ID: <1264425788-8245-5-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1264425788-8245-1-git-send-email-armbru@redhat.com>

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>
---
 migration.c     |   18 +++---------------
 qemu-monitor.hx |    2 +-
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/migration.c b/migration.c
index 598f8df..6abdc65 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(UINT32_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,
-- 
1.6.6

  parent reply	other threads:[~2010-01-25 13:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-25 13:23 [Qemu-devel] [PATCH v3 0/8] Convert migrate_set_speed, migrate_set_downtime to QObject Markus Armbruster
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 1/8] monitor: Document argument type 'M' Markus Armbruster
2010-02-03 18:37   ` Anthony Liguori
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 2/8] QDict: New qdict_get_double() Markus Armbruster
2010-01-26 20:58   ` Anthony Liguori
2010-01-27 16:16     ` [Qemu-devel] [PATCH v4 " Markus Armbruster
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 3/8] monitor: New argument type 'b' Markus Armbruster
2010-01-25 13:23 ` Markus Armbruster [this message]
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 5/8] monitor: convert do_migrate_set_speed() to QObject Markus Armbruster
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 6/8] monitor: New argument type 'T' Markus Armbruster
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 7/8] monitor: Use argument type 'T' for migrate_set_downtime Markus Armbruster
2010-01-25 13:23 ` [Qemu-devel] [PATCH v3 8/8] monitor: convert do_migrate_set_downtime() to QObject Markus Armbruster
2010-01-25 14:16 ` [Qemu-devel] [PATCH v3 0/8] Convert migrate_set_speed, migrate_set_downtime " Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1264425788-8245-5-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).