From patchwork Mon Jan 25 13:23:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 43628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EDC73B7C09 for ; Tue, 26 Jan 2010 00:36:51 +1100 (EST) Received: from localhost ([127.0.0.1]:38180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZP6q-0004lv-9R for incoming@patchwork.ozlabs.org; Mon, 25 Jan 2010 08:36:04 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZOuY-00011I-PY for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZOuQ-0000sW-GA for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:19 -0500 Received: from [199.232.76.173] (port=42838 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZOuP-0000sB-Fb for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:13 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:60565) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NZOuO-0003TN-Ml for qemu-devel@nongnu.org; Mon, 25 Jan 2010 08:23:12 -0500 Received: from blackfin.pond.sub.org (pD9E3A875.dip.t-dialin.net [217.227.168.117]) by oxygen.pond.sub.org (Postfix) with ESMTPA id D7B1B2DD30B for ; Mon, 25 Jan 2010 14:22:56 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 32B5042A; Mon, 25 Jan 2010 14:23:09 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 25 Jan 2010 14:23:04 +0100 Message-Id: <1264425788-8245-5-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1264425788-8245-1-git-send-email-armbru@redhat.com> References: <1264425788-8245-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH v3 4/8] monitor: Use argument type 'b' for migrate_set_speed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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,