summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorPaul Menage <menage@google.com>2007-10-18 23:39:33 -0700
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 11:53:36 -0700
commit355e0c48b757b7fcc79ccb98fda8105ed37a1598 (patch)
treef9687961979a808e46620f4bdf9af05de2fd68e2 /kernel/cgroup.c
parentbbcb81d09104f0d440974b994c1fc508ccbe9503 (diff)
Add cgroup write_uint() helper method
Add write_uint() helper method for cgroup subsystems This helper is analagous to the read_uint() helper method for reporting u64 values to userspace. It's designed to reduce the amount of boilerplate requierd for creating new cgroup subsystems. Signed-off-by: Paul Menage <menage@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 356c40d5d20..f4c4dce9558 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -829,6 +829,39 @@ enum cgroup_filetype {
FILE_TASKLIST,
};
+static ssize_t cgroup_write_uint(struct cgroup *cont, struct cftype *cft,
+ struct file *file,
+ const char __user *userbuf,
+ size_t nbytes, loff_t *unused_ppos)
+{
+ char buffer[64];
+ int retval = 0;
+ u64 val;
+ char *end;
+
+ if (!nbytes)
+ return -EINVAL;
+ if (nbytes >= sizeof(buffer))
+ return -E2BIG;
+ if (copy_from_user(buffer, userbuf, nbytes))
+ return -EFAULT;
+
+ buffer[nbytes] = 0; /* nul-terminate */
+
+ /* strip newline if necessary */
+ if (nbytes && (buffer[nbytes-1] == '\n'))
+ buffer[nbytes-1] = 0;
+ val = simple_strtoull(buffer, &end, 0);
+ if (*end)
+ return -EINVAL;
+
+ /* Pass to subsystem */
+ retval = cft->write_uint(cont, cft, val);
+ if (!retval)
+ retval = nbytes;
+ return retval;
+}
+
static ssize_t cgroup_common_file_write(struct cgroup *cont,
struct cftype *cft,
struct file *file,
@@ -886,10 +919,11 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf,
if (!cft)
return -ENODEV;
- if (!cft->write)
- return -EINVAL;
-
- return cft->write(cont, cft, file, buf, nbytes, ppos);
+ if (cft->write)
+ return cft->write(cont, cft, file, buf, nbytes, ppos);
+ if (cft->write_uint)
+ return cgroup_write_uint(cont, cft, file, buf, nbytes, ppos);
+ return -EINVAL;
}
static ssize_t cgroup_read_uint(struct cgroup *cont, struct cftype *cft,