From patchwork Tue Mar 20 08:01:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 147762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CB75CB6EE7 for ; Tue, 20 Mar 2012 19:45:45 +1100 (EST) Received: from localhost ([::1]:43689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9u1k-0008Vs-9E for incoming@patchwork.ozlabs.org; Tue, 20 Mar 2012 04:02:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9u1H-0007Lc-Ip for qemu-devel@nongnu.org; Tue, 20 Mar 2012 04:02:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9u0r-0004NB-46 for qemu-devel@nongnu.org; Tue, 20 Mar 2012 04:02:15 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:42808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9u0q-0004Ml-RM for qemu-devel@nongnu.org; Tue, 20 Mar 2012 04:01:49 -0400 Received: by eeit10 with SMTP id t10so3380176eei.4 for ; Tue, 20 Mar 2012 01:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=8ctwNuVr137d2C9+EjfvN0eMk+KlIPji4kFs2cOeNfY=; b=W5lL6XlOpgv5MPfxwT/C9RQne0NtwFSKXYTe7DmLfjhoEa+HdvnrQLv8d/XteixXkh kXejFmmbBDd3mCDTYYmeIg+Ol70NMM1AnQu8bl8Ptu2GJCbZKu/JEKmPMmyg+tM+IJDj VX+MI8Wv9CYoRoYJsfZfFcQcW4tu4fTvYbHKsHE09zHcaBvsWHsEOICvZQL7p+l0BZrw aPRUG60CTTcmcYrkM190uwNkBdjGtts6BiVt66QrMuQAzmgfwhgM9a1RV4X7tTvzhKBq IxDpBRJd1BCTSVLWjBH9+2vWCnbWH5C+tswrMbbc6LPDf1Q1J56ssbLVRxnJEIr1MlC8 FcDQ== Received: by 10.14.200.132 with SMTP id z4mr1840783een.122.1332230506732; Tue, 20 Mar 2012 01:01:46 -0700 (PDT) Received: from yakj.lan (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id n56sm2565509eeb.4.2012.03.20.01.01.45 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Mar 2012 01:01:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 20 Mar 2012 09:01:28 +0100 Message-Id: <1332230498-20684-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1332230498-20684-1-git-send-email-pbonzini@redhat.com> References: <1332230498-20684-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.83.45 Subject: [Qemu-devel] [PATCH 02/12] QemuOpts: use strtosz X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This will simplify conversion of -numa node,mem=... and -m to QemuOpts. Signed-off-by: Paolo Bonzini --- qemu-option.c | 41 ++++++++++------------------------------- 1 files changed, 10 insertions(+), 31 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 35cd609..55cbee8 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -204,41 +204,20 @@ static int parse_option_number(const char *name, const char *value, uint64_t *re return 0; } -static int parse_option_size(const char *name, const char *value, uint64_t *ret) +static int parse_option_size(const char *name, const char *value, + const char default_suffix, uint64_t *ret) { char *postfix; - double sizef; + int64_t size; - if (value != NULL) { - sizef = strtod(value, &postfix); - switch (*postfix) { - case 'T': - sizef *= 1024; - /* fall through */ - case 'G': - sizef *= 1024; - /* fall through */ - case 'M': - sizef *= 1024; - /* fall through */ - case 'K': - case 'k': - sizef *= 1024; - /* fall through */ - case 'b': - case '\0': - *ret = (uint64_t) sizef; - break; - default: - qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size"); - error_printf_unless_qmp("You may use k, M, G or T suffixes for " - "kilobytes, megabytes, gigabytes and terabytes.\n"); - return -1; - } - } else { + size = strtosz_suffix(value, &postfix, default_suffix); + if (size < 0 || *postfix) { qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size"); + error_printf_unless_qmp("You may use k, M, G or T suffixes for " + "kilobytes, megabytes, gigabytes and terabytes.\n"); return -1; } + *ret = size; return 0; } @@ -289,7 +268,7 @@ int set_option_parameter(QEMUOptionParameter *list, const char *name, break; case OPT_SIZE: - if (parse_option_size(name, value, &list->value.n) == -1) + if (parse_option_size(name, value, 'B', &list->value.n) == -1) return -1; break; @@ -589,7 +568,7 @@ static int qemu_opt_parse(QemuOpt *opt) case QEMU_OPT_NUMBER: return parse_option_number(opt->name, opt->str, &opt->value.uint); case QEMU_OPT_SIZE: - return parse_option_size(opt->name, opt->str, &opt->value.uint); + return parse_option_size(opt->name, opt->str, 'M', &opt->value.uint); default: abort(); }