Commit e73d2c61 authored by Paul Menage's avatar Paul Menage Committed by Linus Torvalds

CGroups _s64 files: add cgroups read_s64/write_s64 file methods

These patches add cgroups read_s64 and write_s64 control file methods (the
signed equivalent of read_u64/write_u64) and use them to implement the
cpu.rt_runtime_us control file in the CFS cgroup subsystem.

This patch:

These are the signed equivalents of the read_u64/write_u64 methods
Signed-off-by: default avatarPaul Menage <menage@google.com>
Acked-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 418d7d87
...@@ -215,6 +215,10 @@ struct cftype { ...@@ -215,6 +215,10 @@ struct cftype {
* single integer. Use it in place of read() * single integer. Use it in place of read()
*/ */
u64 (*read_u64) (struct cgroup *cgrp, struct cftype *cft); u64 (*read_u64) (struct cgroup *cgrp, struct cftype *cft);
/*
* read_s64() is a signed version of read_u64()
*/
s64 (*read_s64) (struct cgroup *cgrp, struct cftype *cft);
/* /*
* read_map() is used for defining a map of key/value * read_map() is used for defining a map of key/value
* pairs. It should call cb->fill(cb, key, value) for each * pairs. It should call cb->fill(cb, key, value) for each
...@@ -234,6 +238,10 @@ struct cftype { ...@@ -234,6 +238,10 @@ struct cftype {
* userspace. Use in place of write(); return 0 or error. * userspace. Use in place of write(); return 0 or error.
*/ */
int (*write_u64) (struct cgroup *cgrp, struct cftype *cft, u64 val); int (*write_u64) (struct cgroup *cgrp, struct cftype *cft, u64 val);
/*
* write_s64() is a signed version of write_u64()
*/
int (*write_s64) (struct cgroup *cgrp, struct cftype *cft, s64 val);
int (*release) (struct inode *inode, struct file *file); int (*release) (struct inode *inode, struct file *file);
}; };
......
...@@ -1299,14 +1299,13 @@ enum cgroup_filetype { ...@@ -1299,14 +1299,13 @@ enum cgroup_filetype {
FILE_RELEASE_AGENT, FILE_RELEASE_AGENT,
}; };
static ssize_t cgroup_write_u64(struct cgroup *cgrp, struct cftype *cft, static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft,
struct file *file, struct file *file,
const char __user *userbuf, const char __user *userbuf,
size_t nbytes, loff_t *unused_ppos) size_t nbytes, loff_t *unused_ppos)
{ {
char buffer[64]; char buffer[64];
int retval = 0; int retval = 0;
u64 val;
char *end; char *end;
if (!nbytes) if (!nbytes)
...@@ -1318,12 +1317,17 @@ static ssize_t cgroup_write_u64(struct cgroup *cgrp, struct cftype *cft, ...@@ -1318,12 +1317,17 @@ static ssize_t cgroup_write_u64(struct cgroup *cgrp, struct cftype *cft,
buffer[nbytes] = 0; /* nul-terminate */ buffer[nbytes] = 0; /* nul-terminate */
strstrip(buffer); strstrip(buffer);
val = simple_strtoull(buffer, &end, 0); if (cft->write_u64) {
if (*end) u64 val = simple_strtoull(buffer, &end, 0);
return -EINVAL; if (*end)
return -EINVAL;
/* Pass to subsystem */ retval = cft->write_u64(cgrp, cft, val);
retval = cft->write_u64(cgrp, cft, val); } else {
s64 val = simple_strtoll(buffer, &end, 0);
if (*end)
return -EINVAL;
retval = cft->write_s64(cgrp, cft, val);
}
if (!retval) if (!retval)
retval = nbytes; retval = nbytes;
return retval; return retval;
...@@ -1404,8 +1408,8 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf, ...@@ -1404,8 +1408,8 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf,
return -ENODEV; return -ENODEV;
if (cft->write) if (cft->write)
return cft->write(cgrp, cft, file, buf, nbytes, ppos); return cft->write(cgrp, cft, file, buf, nbytes, ppos);
if (cft->write_u64) if (cft->write_u64 || cft->write_s64)
return cgroup_write_u64(cgrp, cft, file, buf, nbytes, ppos); return cgroup_write_X64(cgrp, cft, file, buf, nbytes, ppos);
return -EINVAL; return -EINVAL;
} }
...@@ -1421,6 +1425,18 @@ static ssize_t cgroup_read_u64(struct cgroup *cgrp, struct cftype *cft, ...@@ -1421,6 +1425,18 @@ static ssize_t cgroup_read_u64(struct cgroup *cgrp, struct cftype *cft,
return simple_read_from_buffer(buf, nbytes, ppos, tmp, len); return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
} }
static ssize_t cgroup_read_s64(struct cgroup *cgrp, struct cftype *cft,
struct file *file,
char __user *buf, size_t nbytes,
loff_t *ppos)
{
char tmp[64];
s64 val = cft->read_s64(cgrp, cft);
int len = sprintf(tmp, "%lld\n", (long long) val);
return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
}
static ssize_t cgroup_common_file_read(struct cgroup *cgrp, static ssize_t cgroup_common_file_read(struct cgroup *cgrp,
struct cftype *cft, struct cftype *cft,
struct file *file, struct file *file,
...@@ -1477,6 +1493,8 @@ static ssize_t cgroup_file_read(struct file *file, char __user *buf, ...@@ -1477,6 +1493,8 @@ static ssize_t cgroup_file_read(struct file *file, char __user *buf,
return cft->read(cgrp, cft, file, buf, nbytes, ppos); return cft->read(cgrp, cft, file, buf, nbytes, ppos);
if (cft->read_u64) if (cft->read_u64)
return cgroup_read_u64(cgrp, cft, file, buf, nbytes, ppos); return cgroup_read_u64(cgrp, cft, file, buf, nbytes, ppos);
if (cft->read_s64)
return cgroup_read_s64(cgrp, cft, file, buf, nbytes, ppos);
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment