diff mbox

btrfs: add btrfs resize unit t/p/e support

Message ID 1395888673-28433-1-git-send-email-guihc.fnst@cn.fujitsu.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Gui Hecheng March 27, 2014, 2:51 a.m. UTC
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(-)

Comments

Brendan Hide March 27, 2014, 7:35 a.m. UTC | #1
On 2014/03/27 04:51 AM, Gui Hecheng wrote:
> [snip]
>
> 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.
Is there a conflict preventing adding this to memparse directly?
David Sterba March 27, 2014, 3:27 p.m. UTC | #2
On Thu, Mar 27, 2014 at 09:35:41AM +0200, Brendan Hide wrote:
> On 2014/03/27 04:51 AM, Gui Hecheng wrote:
> >[snip]
> >
> >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.
> Is there a conflict preventing adding this to memparse directly?

Agreed, there's no reason do duplicate this function.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Gui Hecheng March 28, 2014, 1:08 a.m. UTC | #3
On Thu, 2014-03-27 at 16:27 +0100, David Sterba wrote:
> On Thu, Mar 27, 2014 at 09:35:41AM +0200, Brendan Hide wrote:
> > On 2014/03/27 04:51 AM, Gui Hecheng wrote:
> > >[snip]
> > >
> > >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.
> > Is there a conflict preventing adding this to memparse directly?
> 
> Agreed, there's no reason do duplicate this function.
Yes, I will try to modify the original memparse soon.

Thanks all!

-Gui

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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;
 		}