diff options
author | Paul Menage <menage@google.com> | 2007-10-19 02:39:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-19 14:53:36 -0400 |
commit | 355e0c48b757b7fcc79ccb98fda8105ed37a1598 (patch) | |
tree | f9687961979a808e46620f4bdf9af05de2fd68e2 /kernel | |
parent | bbcb81d09104f0d440974b994c1fc508ccbe9503 (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')
-rw-r--r-- | kernel/cgroup.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 356c40d5d20a..f4c4dce9558f 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -829,6 +829,39 @@ enum cgroup_filetype { | |||
829 | FILE_TASKLIST, | 829 | FILE_TASKLIST, |
830 | }; | 830 | }; |
831 | 831 | ||
832 | static ssize_t cgroup_write_uint(struct cgroup *cont, struct cftype *cft, | ||
833 | struct file *file, | ||
834 | const char __user *userbuf, | ||
835 | size_t nbytes, loff_t *unused_ppos) | ||
836 | { | ||
837 | char buffer[64]; | ||
838 | int retval = 0; | ||
839 | u64 val; | ||
840 | char *end; | ||
841 | |||
842 | if (!nbytes) | ||
843 | return -EINVAL; | ||
844 | if (nbytes >= sizeof(buffer)) | ||
845 | return -E2BIG; | ||
846 | if (copy_from_user(buffer, userbuf, nbytes)) | ||
847 | return -EFAULT; | ||
848 | |||
849 | buffer[nbytes] = 0; /* nul-terminate */ | ||
850 | |||
851 | /* strip newline if necessary */ | ||
852 | if (nbytes && (buffer[nbytes-1] == '\n')) | ||
853 | buffer[nbytes-1] = 0; | ||
854 | val = simple_strtoull(buffer, &end, 0); | ||
855 | if (*end) | ||
856 | return -EINVAL; | ||
857 | |||
858 | /* Pass to subsystem */ | ||
859 | retval = cft->write_uint(cont, cft, val); | ||
860 | if (!retval) | ||
861 | retval = nbytes; | ||
862 | return retval; | ||
863 | } | ||
864 | |||
832 | static ssize_t cgroup_common_file_write(struct cgroup *cont, | 865 | static ssize_t cgroup_common_file_write(struct cgroup *cont, |
833 | struct cftype *cft, | 866 | struct cftype *cft, |
834 | struct file *file, | 867 | struct file *file, |
@@ -886,10 +919,11 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf, | |||
886 | 919 | ||
887 | if (!cft) | 920 | if (!cft) |
888 | return -ENODEV; | 921 | return -ENODEV; |
889 | if (!cft->write) | 922 | if (cft->write) |
890 | return -EINVAL; | 923 | return cft->write(cont, cft, file, buf, nbytes, ppos); |
891 | 924 | if (cft->write_uint) | |
892 | return cft->write(cont, cft, file, buf, nbytes, ppos); | 925 | return cgroup_write_uint(cont, cft, file, buf, nbytes, ppos); |
926 | return -EINVAL; | ||
893 | } | 927 | } |
894 | 928 | ||
895 | static ssize_t cgroup_read_uint(struct cgroup *cont, struct cftype *cft, | 929 | static ssize_t cgroup_read_uint(struct cgroup *cont, struct cftype *cft, |