public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: add btrfs resize unit t/p/e support
@ 2014-03-27  2:51 Gui Hecheng
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Gui Hecheng @ 2014-03-27  2:51 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-28  1:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-27  2:51 [PATCH] btrfs: add btrfs resize unit t/p/e support Gui Hecheng
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox