From patchwork Wed Jan 20 16:08:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 43303 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 B07F1B7CC1 for ; Thu, 21 Jan 2010 03:24:04 +1100 (EST) Received: from localhost ([127.0.0.1]:56561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXd9v-0004BZ-Jr for incoming@patchwork.ozlabs.org; Wed, 20 Jan 2010 11:11:55 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXd6f-0002iG-9S for qemu-devel@nongnu.org; Wed, 20 Jan 2010 11:08:33 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXd6Z-0002cT-Im for qemu-devel@nongnu.org; Wed, 20 Jan 2010 11:08:31 -0500 Received: from [199.232.76.173] (port=38147 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXd6Y-0002cH-Sj for qemu-devel@nongnu.org; Wed, 20 Jan 2010 11:08:26 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:57850) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NXd6X-0002cR-68 for qemu-devel@nongnu.org; Wed, 20 Jan 2010 11:08:25 -0500 Received: from blackfin.pond.sub.org (pD9E3BC04.dip.t-dialin.net [217.227.188.4]) by oxygen.pond.sub.org (Postfix) with ESMTPA id CD9F4276CEC for ; Wed, 20 Jan 2010 17:08:22 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 45788F2; Wed, 20 Jan 2010 17:08:22 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 20 Jan 2010 17:08:17 +0100 Message-Id: <1264003702-17329-4-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1264003702-17329-1-git-send-email-armbru@redhat.com> References: <1264003702-17329-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 v2 3/8] monitor: New argument type 'b' 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 This is a double value with optional suffixes G, g, M, m, K, k. We'll need this to get migrate_set_speed() QMP-ready. Signed-off-by: Markus Armbruster --- monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index 775fe3f..ce97e7b 100644 --- a/monitor.c +++ b/monitor.c @@ -47,6 +47,7 @@ #include "kvm.h" #include "acl.h" #include "qint.h" +#include "qfloat.h" #include "qlist.h" #include "qdict.h" #include "qbool.h" @@ -70,6 +71,10 @@ * 'l' target long (32 or 64 bit) * 'M' just like 'l', except in user mode the value is * multiplied by 2^20 (think Mebibyte) + * 'b' double + * user mode accepts an optional G, g, M, m, K, k suffix, + * which multiplies the value by 2^30 for suffixes G and + * g, 2^20 for M and m, 2^10 for K and k * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp) return 0; } +static int get_double(Monitor *mon, double *pval, const char **pp) +{ + const char *p = *pp; + char *tailp; + double d; + + errno = 0; + d = strtod(p, &tailp); + if (tailp == p) { + monitor_printf(mon, "Number expected\n"); + return -1; + } + if (errno) { + monitor_printf(mon, "Bad number (%s)\n", strerror(errno)); + return -1; + } + *pval = d; + *pp = tailp; + return 0; +} + static int get_str(char *buf, int buf_size, const char **pp) { const char *p; @@ -3517,6 +3543,38 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, qdict_put(qdict, key, qint_from_int(val)); } break; + case 'b': + { + double val; + + while (qemu_isspace(*p)) + p++; + if (*typestr == '?') { + typestr++; + if (*p == '\0') { + break; + } + } + if (get_double(mon, &val, &p) < 0) { + goto fail; + } + if (*p) { + switch (*p) { + case 'K': case 'k': + val *= 1 << 10; p++; break; + case 'M': case 'm': + val *= 1 << 20; p++; break; + case 'G': case 'g': + val *= 1 << 30; p++; break; + } + } + if (*p && !qemu_isspace(*p)) { + monitor_printf(mon, "Unknown unit suffix\n"); + goto fail; + } + qdict_put(qdict, key, qfloat_from_double(val)); + } + break; case '-': { const char *tmp = p;