Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 71412
b: refs/heads/master
c: 355e0c4
h: refs/heads/master
v: v3
  • Loading branch information
Paul Menage authored and Linus Torvalds committed Oct 19, 2007
1 parent b7be2b0 commit 1b53d92
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: bbcb81d09104f0d440974b994c1fc508ccbe9503
refs/heads/master: 355e0c48b757b7fcc79ccb98fda8105ed37a1598
8 changes: 8 additions & 0 deletions trunk/include/linux/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ struct cftype {
ssize_t (*write) (struct cgroup *cont, struct cftype *cft,
struct file *file,
const char __user *buf, size_t nbytes, loff_t *ppos);

/*
* write_uint() is a shortcut for the common case of accepting
* a single integer (as parsed by simple_strtoull) from
* userspace. Use in place of write(); return 0 or error.
*/
int (*write_uint) (struct cgroup *cont, struct cftype *cft, u64 val);

int (*release) (struct inode *inode, struct file *file);
};

Expand Down
42 changes: 38 additions & 4 deletions trunk/kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1b53d92

Please sign in to comment.