From patchwork Thu Mar 27 02:51:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 3896131 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 48F7C9F2E8 for ; Thu, 27 Mar 2014 02:55:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E13CE202F8 for ; Thu, 27 Mar 2014 02:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EE0320303 for ; Thu, 27 Mar 2014 02:55:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752882AbaC0CzQ (ORCPT ); Wed, 26 Mar 2014 22:55:16 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:47785 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752114AbaC0CzP (ORCPT ); Wed, 26 Mar 2014 22:55:15 -0400 X-IronPort-AV: E=Sophos;i="4.97,739,1389715200"; d="scan'208";a="9774948" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 27 Mar 2014 10:51:18 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s2R2tBvn021461 for ; Thu, 27 Mar 2014 10:55:11 +0800 Received: from localhost.localdomain ([10.167.226.111]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014032710520386-831040 ; Thu, 27 Mar 2014 10:52:03 +0800 From: Gui Hecheng To: linux-btrfs@vger.kernel.org Cc: Gui Hecheng Subject: [PATCH] btrfs: add btrfs resize unit t/p/e support Date: Thu, 27 Mar 2014 10:51:12 +0800 Message-Id: <1395888673-28433-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/03/27 10:52:03, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/03/27 10:52:04, Serialize complete at 2014/03/27 10:52:04 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For Btrfs with 16E fs size support, resize by unit t/p/e is desired. The request comes from redhat bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1058608. Originally, # btrfs resize -1T : prompt 'invalid argument' while, # btrfs resize -1024G : will work We add t/p/e support by replacing lib/cmdline.c:memparse with btrfs_memparse. The btrfs_memparse copies memparse's code and add unit t/p/e parsing. Signed-off-by: Gui Hecheng --- fs/btrfs/ioctl.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index e174770..357b706 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1448,6 +1448,47 @@ out_ra: return ret; } +/* + * The memparse only supports k/m/g suffixes + * For Btrfs with 16E fs size support, t/p/e support is desired + * This function copies the memparse and adds t/p/e suffixes parsing + */ +static int btrfs_memparse(const char *ptr, u64 *retval) +{ + int ret = 0; + char *endptr; /* local pointer to end of parsed string */ + + *retval = simple_strtoull(ptr, &endptr, 0); + if (*(endptr + 1) != '\0') + return -EINVAL; + + switch (*endptr) { + case 'E': + case 'e': + *retval <<= 10; + case 'P': + case 'p': + *retval <<= 10; + case 'T': + case 't': + *retval <<= 10; + case 'G': + case 'g': + *retval <<= 10; + case 'M': + case 'm': + *retval <<= 10; + case 'K': + case 'k': + *retval <<= 10; + break; + default: + ret = -EINVAL; + } + + return ret; +} + static noinline int btrfs_ioctl_resize(struct file *file, void __user *arg) { @@ -1526,8 +1567,8 @@ static noinline int btrfs_ioctl_resize(struct file *file, mod = 1; sizestr++; } - new_size = memparse(sizestr, NULL); - if (new_size == 0) { + ret = btrfs_memparse(sizestr, &new_size); + if (ret < 0 || new_size == 0) { ret = -EINVAL; goto out_free; }