monitor: Use argument type 'b' for migrate_set_speed

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>
This commit is contained in:
Markus Armbruster 2010-01-25 14:23:04 +01:00 committed by Anthony Liguori
parent 3350a4dd07
commit 5667c493c4
2 changed files with 4 additions and 16 deletions

View File

@ -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) void do_migrate_set_speed(Monitor *mon, const QDict *qdict)
{ {
double d; double d;
char *ptr;
FdMigrationState *s; FdMigrationState *s;
const char *value = qdict_get_str(qdict, "value");
d = strtod(value, &ptr); d = qdict_get_double(qdict, "value");
switch (*ptr) { d = MAX(0, MIN(UINT32_MAX, d));
case 'G': case 'g': max_throttle = d;
d *= 1024;
case 'M': case 'm':
d *= 1024;
case 'K': case 'k':
d *= 1024;
default:
break;
}
max_throttle = (uint32_t)d;
s = migrate_to_fms(current_migration); s = migrate_to_fms(current_migration);
if (s && s->file) { if (s && s->file) {

View File

@ -761,7 +761,7 @@ ETEXI
{ {
.name = "migrate_set_speed", .name = "migrate_set_speed",
.args_type = "value:s", .args_type = "value:b",
.params = "value", .params = "value",
.help = "set maximum speed (in bytes) for migrations", .help = "set maximum speed (in bytes) for migrations",
.mhandler.cmd = do_migrate_set_speed, .mhandler.cmd = do_migrate_set_speed,