From owner-svn-src-all@FreeBSD.ORG Sun Mar 13 19:23:33 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 393711065689; Sun, 13 Mar 2011 19:23:33 +0000 (UTC) (envelope-from trociny@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0E0E78FC14; Sun, 13 Mar 2011 19:23:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2DJNWK0063749; Sun, 13 Mar 2011 19:23:32 GMT (envelope-from trociny@svn.freebsd.org) Received: (from trociny@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2DJNWhw063746; Sun, 13 Mar 2011 19:23:32 GMT (envelope-from trociny@svn.freebsd.org) Message-Id: <201103131923.p2DJNWhw063746@svn.freebsd.org> From: Mikolaj Golub Date: Sun, 13 Mar 2011 19:23:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219620 - head/sbin/hastctl X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Mar 2011 19:23:33 -0000 Author: trociny Date: Sun Mar 13 19:23:32 2011 New Revision: 219620 URL: http://svn.freebsd.org/changeset/base/219620 Log: In command line options allow size to be specified using k/M/G/T suffixes. Approved by: pjd (mentor) MFC after: 1 week Modified: head/sbin/hastctl/hastctl.8 head/sbin/hastctl/hastctl.c Modified: head/sbin/hastctl/hastctl.8 ============================================================================== --- head/sbin/hastctl/hastctl.8 Sun Mar 13 19:07:58 2011 (r219619) +++ head/sbin/hastctl/hastctl.8 Sun Mar 13 19:23:32 2011 (r219620) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 1, 2010 +.Dd March 13, 2011 .Dt HASTCTL 8 .Os .Sh NAME @@ -113,6 +113,9 @@ Size of the smaller provider used as bac This option can be omitted if node providers have the same size on both sides. .El +.Pp +If size is suffixed with a k, M, G or T, it is taken as a kilobyte, +megabyte, gigabyte or terabyte measurement respectively. .It Cm role Change role of the given resource. The role can be one of: Modified: head/sbin/hastctl/hastctl.c ============================================================================== --- head/sbin/hastctl/hastctl.c Sun Mar 13 19:07:58 2011 (r219619) +++ head/sbin/hastctl/hastctl.c Sun Mar 13 19:23:32 2011 (r219620) @@ -40,7 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include #include @@ -342,30 +342,11 @@ control_status(struct nv *nv) return (ret); } -static int -numfromstr(const char *str, intmax_t *nump) -{ - intmax_t num; - char *suffix; - int rerrno; - - rerrno = errno; - errno = 0; - num = strtoimax(str, &suffix, 0); - if (errno == 0 && *suffix != '\0') - errno = EINVAL; - if (errno != 0) - return (-1); - *nump = num; - errno = rerrno; - return (0); -} - int main(int argc, char *argv[]) { struct nv *nv; - intmax_t mediasize, extentsize, keepdirty; + int64_t mediasize, extentsize, keepdirty; int cmd, debug, error, ii; const char *optstr; @@ -407,15 +388,15 @@ main(int argc, char *argv[]) debug++; break; case 'e': - if (numfromstr(optarg, &extentsize) < 0) + if (expand_number(optarg, &extentsize) < 0) err(1, "Invalid extentsize"); break; case 'k': - if (numfromstr(optarg, &keepdirty) < 0) + if (expand_number(optarg, &keepdirty) < 0) err(1, "Invalid keepdirty"); break; case 'm': - if (numfromstr(optarg, &mediasize) < 0) + if (expand_number(optarg, &mediasize) < 0) err(1, "Invalid mediasize"); break; case 'h':