Skip to contentSkip to conversation

cgroup quota: add disk space parse strategy to res_counter

RFC PATCH In review Jeff Liu 3 participants 3 messages Mar 9, 2012 – Mar 11, 2012 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

RFC PATCH 1/4 cgroup quota: add disk space parse strategy to res_counter

Introduce a new disk space parse strategy routine for cgroup quota supports. disk_space_parse() is simply copied from mmparse() with Petabytes and Terabytes parse.

---
 include/linux/res_counter.h |    3 ++
 kernel/res_counter.c        |   58 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
include/linux/res_counter.h +3 -0
index c9d625c..f8ce315 100644
@@ -79,6 +79,9 @@ typedef int (*write_strategy_fn)(const char *buf, unsigned long long *val);
 int res_counter_memparse_write_strategy(const char *buf,
 					unsigned long long *res);
 
+int res_counter_diskspace_parse_write_strategy(const char *buf,
+					       unsigned long long *res);
+
 int res_counter_write(struct res_counter *counter, int member,
 		      const char *buffer, write_strategy_fn write_strategy);
 
kernel/res_counter.c +58 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.9
#1 lore raw
Quoted 28 lines · Jeff Liu

Introduce a new disk space parse strategy routine for cgroup quota supports. disk_space_parse() is simply copied from mmparse() with Petabytes and Terabytes parse.

---
  include/linux/res_counter.h |    3 ++
  kernel/res_counter.c        |   58 +++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+), 0 deletions(-)
include/linux/res_counter.h +3 -0
index c9d625c..f8ce315 100644
@@ -79,6 +79,9 @@ typedef int (*write_strategy_fn)(const char *buf, unsigned long long *val);
  int res_counter_memparse_write_strategy(const char *buf,
  					unsigned long long *res);
 
+int res_counter_diskspace_parse_write_strategy(const char *buf,
+					       unsigned long long *res);
+
  int res_counter_write(struct res_counter *counter, int member,
  		      const char *buffer, write_strategy_fn write_strategy);
 
kernel/res_counter.c +0 -0
index 34683ef..42c1623 100644

kernel/res_counter.c u64 res_counter_read_u64(struct res_counter *counter, int member) · line 150

Quoted 6 lines
kernel/res_counter.c +3 -0
@@ -145,6 +145,64 @@ u64 res_counter_read_u64(struct res_counter *counter, int member)
  }
  #endif
 
+/*
+ * Copy from memparse(), add terabytes, petabytes parse support.
+ */

Don't see a reason for that. It is all bytes and such, just add the modifiers you want to the normal parse...

Quoted 58 lines
kernel/res_counter.c +55 -0
+unsigned long long disk_space_parse(const char *ptr, char **retptr)
+{
+	char *endptr; /* local pointer to end of parsed string */
+	unsigned long long ret = kstrtoull(ptr,&endptr, 0);
+
+	switch (*endptr) {
+	case 'P':
+	case 'p':
+		ret<<= 10;
+	case 'T':
+	case 't':
+		ret<<= 10;
+	case 'G':
+	case 'g':
+		ret<<= 10;
+	case 'M':
+	case 'm':
+		ret<<= 10;
+	case 'K':
+	case 'k':
+		ret<<= 10;
+		endptr++;
+	default:
+		break;
+	}
+
+	if (retptr)
+		*retptr = endptr;
+
+	return ret;
+}
+
+int res_counter_diskspace_parse_write_strategy(const char *buf,
+					       unsigned long long *res)
+{
+	char *end;
+
+	/* return RESOURCE_MAX(unlimited) if "-1" is specified */
+	if (*buf == '-') {
+		*res = kstrtoull(buf + 1,&end, 10);
+		if (*res != 1 || *end != '\0')
+			return -EINVAL;
+		*res = RESOURCE_MAX;
+		return 0;
+	}
+
+	/* FIXME - make memparse() take const char* args */
+	*res = disk_space_parse((char *)buf,&end);
+	if (*end != '\0')
+		return -EINVAL;
+
+	/* FIXME - need to return *res as block aligned? */
+	return 0;
+}
+
  int res_counter_memparse_write_strategy(const char *buf,
  					unsigned long long *res)
  {

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 37 lines · Glauber Costa
Quoted 36 lines · Jeff Liu

Introduce a new disk space parse strategy routine for cgroup quota supports.
disk_space_parse() is simply copied from mmparse() with Petabytes and Terabytes parse.

---
  include/linux/res_counter.h |    3 ++
  kernel/res_counter.c        |   58
+++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+), 0 deletions(-)
include/linux/res_counter.h +3 -0
index c9d625c..f8ce315 100644
@@ -79,6 +79,9 @@ typedef int (*write_strategy_fn)(const char *buf,
 unsigned long long *val);
  int res_counter_memparse_write_strategy(const char *buf,
                      unsigned long long *res);
 
+int res_counter_diskspace_parse_write_strategy(const char *buf,
+                           unsigned long long *res);
+
  int res_counter_write(struct res_counter *counter, int member,
                const char *buffer, write_strategy_fn write_strategy);
kernel/res_counter.c +0 -0
index 34683ef..42c1623 100644
@@ -145,6 +145,64 @@ u64 res_counter_read_u64(struct res_counter
 *counter, int member)
  }
  #endif
 
Quoted 5 lines

kernel/res_counter.c u64 res_counter_read_u64(struct res_counter *counter, int member) · line 150

Quoted 3 lines
kernel/res_counter.c +3 -0
+/*
+ * Copy from memparse(), add terabytes, petabytes parse support.
+ */

Don't see a reason for that. It is all bytes and such, just add the modifiers you want to the normal parse...

ok, I'll take care.

Thanks,
-Jeff

Quoted 60 lines
Quoted 59 lines
kernel/res_counter.c +55 -0
+unsigned long long disk_space_parse(const char *ptr, char **retptr)
+{
+    char *endptr; /* local pointer to end of parsed string */
+    unsigned long long ret = kstrtoull(ptr,&endptr, 0);
+
+    switch (*endptr) {
+    case 'P':
+    case 'p':
+        ret<<= 10;
+    case 'T':
+    case 't':
+        ret<<= 10;
+    case 'G':
+    case 'g':
+        ret<<= 10;
+    case 'M':
+    case 'm':
+        ret<<= 10;
+    case 'K':
+    case 'k':
+        ret<<= 10;
+        endptr++;
+    default:
+        break;
+    }
+
+    if (retptr)
+        *retptr = endptr;
+
+    return ret;
+}
+
+int res_counter_diskspace_parse_write_strategy(const char *buf,
+                           unsigned long long *res)
+{
+    char *end;
+
+    /* return RESOURCE_MAX(unlimited) if "-1" is specified */
+    if (*buf == '-') {
+        *res = kstrtoull(buf + 1,&end, 10);
+        if (*res != 1 || *end != '\0')
+            return -EINVAL;
+        *res = RESOURCE_MAX;
+        return 0;
+    }
+
+    /* FIXME - make memparse() take const char* args */
+    *res = disk_space_parse((char *)buf,&end);
+    if (*end != '\0')
+        return -EINVAL;
+
+    /* FIXME - need to return *res as block aligned? */
+    return 0;
+}
+
  int res_counter_memparse_write_strategy(const char *buf,
                      unsigned long long *res)
  {