From owner-freebsd-scsi@FreeBSD.ORG Mon Nov 11 02:16:42 2013 Return-Path: Delivered-To: scsi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 76AD07E5 for ; Mon, 11 Nov 2013 02:16:42 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-qe0-x235.google.com (mail-qe0-x235.google.com [IPv6:2607:f8b0:400d:c02::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 33DCB218C for ; Mon, 11 Nov 2013 02:16:42 +0000 (UTC) Received: by mail-qe0-f53.google.com with SMTP id cy11so3892860qeb.40 for ; Sun, 10 Nov 2013 18:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3Lza0SUORtbC+LPRffo3yaq32awtIbIu0/saWCSwsAc=; b=gI0H1ymhl+Yu0l+9soKPe3C4/cU8UtysdLyVxraaUfmEUIPtsk0xWpxXkBczZsrjzf Aepito6Qj30+VG2AV1C4MUcTkEgsuCKu3ciX0RgrctFsPK3jYekuO1JMWABZ6sogob+y DXDhkYg5bMRbnMwpT0WAFGiVBb7pi6d2nKmj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=3Lza0SUORtbC+LPRffo3yaq32awtIbIu0/saWCSwsAc=; b=BIJCulHaf6VEj6ksZ6VSwaZNbkiLBEcuKaxxf3fzfBuV0GiAn/zFW3OOj7ymrYo/q+ zIkqblkL/xe+PZlROqF1pgK0Z82n2cObQMUHnHfkt6xUO0EbDTfbOoOISwJ2pFaG0Zm0 JVy0YgFZz+7qyjmrdGi9LiMCgCEVAwXohTeMqYglUVJ5KA8Qf1afdvV7rF84ZZz4baRD DhxnuIMiZCbq/pQqbruP9qhpUEmoABudIDBIDKtWnddtLcV/NZK5FghvJfZYV1p1jqKC z3068SCKPuiW6/HZIpCXyp9vuEbY9gOAayBPwNRU+HJJZif6d9gZmdeu2fPfesps+kLK vL1A== X-Gm-Message-State: ALoCoQnKgZIr4rXJLDSd+tPPXd3vh4nRs6AYaSmVy17j7uxiP22POwpdVBSIprJNk4MRpxvR1Eq8 X-Received: by 10.224.69.132 with SMTP id z4mr45024607qai.78.1384136201437; Sun, 10 Nov 2013 18:16:41 -0800 (PST) MIME-Version: 1.0 Received: by 10.96.63.101 with HTTP; Sun, 10 Nov 2013 18:16:11 -0800 (PST) In-Reply-To: <20131110161359.S1474@besplex.bde.org> References: <20131110161359.S1474@besplex.bde.org> From: Eitan Adler Date: Sun, 10 Nov 2013 21:16:11 -0500 Message-ID: Subject: Re: mptutil, mfitil, expand_number To: Bruce Evans Content-Type: text/plain; charset=UTF-8 Cc: scsi@freebsd.org X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Nov 2013 02:16:42 -0000 On Sun, Nov 10, 2013 at 1:25 AM, Bruce Evans wrote: > On Sat, 9 Nov 2013, Eitan Adler wrote: Lets see if I understand everything you wanted me to do. I am not intending to fix any bugs in expand_number at the moment if any. In case the patch below is mangled the following should be identical: http://people.freebsd.org/~eadler/files/expand_number.diff commit 55c7ba2c76c9719617f0e76cb781fad0e26eba74 Author: Eitan Adler Date: Sat Nov 9 22:09:17 2013 -0500 Convert from a hand-rolled function to expand_number. diff --git a/usr.sbin/mptutil/mpt_config.c b/usr.sbin/mptutil/mpt_config.c index 17b9945..0d34d16 100644 --- a/usr.sbin/mptutil/mpt_config.c +++ b/usr.sbin/mptutil/mpt_config.c @@ -50,35 +50,6 @@ __RCSID("$FreeBSD$"); static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol); #endif -static long -dehumanize(const char *value) -{ - char *vtp; - long iv; - - if (value == NULL) - return (0); - iv = strtoq(value, &vtp, 0); - if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) { - return (0); - } - switch (vtp[0]) { - case 't': case 'T': - iv *= 1024; - case 'g': case 'G': - iv *= 1024; - case 'm': case 'M': - iv *= 1024; - case 'k': case 'K': - iv *= 1024; - case '\0': - break; - default: - return (0); - } - return (iv); -} - /* * Lock the volume by opening its /dev device read/write. This will * only work if nothing else has it opened (including mounts). We @@ -615,7 +586,7 @@ create_volume(int ac, char **av) CONFIG_PAGE_RAID_VOL_0 *vol; struct config_id_state state; struct volume_info *info; - long stripe_size; + uint64_t stripe_size; int ch, error, fd, i, quick, raid_type, verbose; #ifdef DEBUG int dump; @@ -666,7 +637,11 @@ create_volume(int ac, char **av) quick = 1; break; case 's': - stripe_size = dehumanize(optarg); + error = expand_number(optarg, &stripe_size); + if (error == -1) { + warnx("Invalid stripe size %s", optarg); + return (errno); + } if ((stripe_size < 512) || (!powerof2(stripe_size))) { warnx("Invalid stripe size %s", optarg); return (EINVAL); commit fdca0b483f9184f0a6de420086a81cfa34652a5f Author: Eitan Adler Date: Sat Nov 9 22:09:17 2013 -0500 Convert from a hand-rolled function to expand_number. Reviewed by: sbruno diff --git a/usr.sbin/mfiutil/mfi_config.c b/usr.sbin/mfiutil/mfi_config.c index a919214..abecb7d 100644 --- a/usr.sbin/mfiutil/mfi_config.c +++ b/usr.sbin/mfiutil/mfi_config.c @@ -47,35 +47,6 @@ static int add_spare(int ac, char **av); static int remove_spare(int ac, char **av); -static long -dehumanize(const char *value) -{ - char *vtp; - long iv; - - if (value == NULL) - return (0); - iv = strtoq(value, &vtp, 0); - if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) { - return (0); - } - switch (vtp[0]) { - case 't': case 'T': - iv *= 1024; - case 'g': case 'G': - iv *= 1024; - case 'm': case 'M': - iv *= 1024; - case 'k': case 'K': - iv *= 1024; - case '\0': - break; - default: - return (0); - } - return (iv); -} - int mfi_config_read(int fd, struct mfi_config_data **configp) { @@ -629,7 +600,11 @@ create_volume(int ac, char **av) break; #endif case 's': - stripe_size = dehumanize(optarg); + error = expand_number(optarg, &stripe_size); + if (error == -1) { + error = errno; + goto error; + } if ((stripe_size < 512) || (!powerof2(stripe_size))) stripe_size = 64 * 1024; break; commit 20ad9d0a2bd9aea4aaf7c5ae9253978ae0aed75c Author: Eitan Adler Date: Sat Nov 9 22:19:41 2013 -0500 Indicate that expand_number is case-insensitive. diff --git a/lib/libutil/expand_number.3 b/lib/libutil/expand_number.3 index f78223b..2f5871f 100644 --- a/lib/libutil/expand_number.3 +++ b/lib/libutil/expand_number.3 @@ -51,12 +51,13 @@ argument. The .Fn expand_number function +is case-insensitive and follows the SI power of two convention. .Pp The prefixes are: .Bl -column "Prefix" "Description" "1000000000000000000" -offset indent .It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier" -.It Li k Ta No kilo Ta 1024 +.It Li K Ta No kilo Ta 1024 .It Li M Ta No mega Ta 1048576 .It Li G Ta No giga Ta 1073741824 .It Li T Ta No tera Ta 1099511627776 -- Eitan Adler