All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Subject: [PATCH] btrfs: add btrfs resize unit t/p/e support
Date: Thu, 27 Mar 2014 10:51:12 +0800	[thread overview]
Message-ID: <1395888673-28433-1-git-send-email-guihc.fnst@cn.fujitsu.com> (raw)

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 <path> 	: prompt 'invalid argument'
while,
	# btrfs resize -1024G <path>	: 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 <guihc.fnst@cn.fujitsu.com>
---
 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;
 		}
-- 
1.8.1.4


             reply	other threads:[~2014-03-27  2:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-27  2:51 Gui Hecheng [this message]
2014-03-27  2:51 ` [PATCH] btrfs-progs: update manpage for btrfs resize support size unit t/p/e Gui Hecheng
2014-03-27  7:35 ` [PATCH] btrfs: add btrfs resize unit t/p/e support Brendan Hide
2014-03-27 15:27   ` David Sterba
2014-03-28  1:08     ` Gui Hecheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395888673-28433-1-git-send-email-guihc.fnst@cn.fujitsu.com \
    --to=guihc.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.