diff options
author | Zefan Li <lizefan@huawei.com> | 2014-09-18 04:03:15 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-09-18 13:27:23 -0400 |
commit | 006f4ac49742b5f70ef7e39176fd42a500144ccc (patch) | |
tree | 976006e7b7a5a0df635538fe51348e4648d9df8c | |
parent | 971ff49355387fef41d1327434d8939721a4eb35 (diff) |
cgroup: simplify proc_cgroup_show()
Use the ONE macro instead of REG, and we can simplify proc_cgroup_show().
Signed-off-by: Zefan Li <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r-- | fs/proc/base.c | 19 | ||||
-rw-r--r-- | include/linux/cgroup.h | 3 | ||||
-rw-r--r-- | kernel/cgroup.c | 18 |
3 files changed, 7 insertions, 33 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index baf852b648ad..6b96892015ec 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -376,21 +376,6 @@ static const struct file_operations proc_lstats_operations = { | |||
376 | 376 | ||
377 | #endif | 377 | #endif |
378 | 378 | ||
379 | #ifdef CONFIG_CGROUPS | ||
380 | static int cgroup_open(struct inode *inode, struct file *file) | ||
381 | { | ||
382 | struct pid *pid = PROC_I(inode)->pid; | ||
383 | return single_open(file, proc_cgroup_show, pid); | ||
384 | } | ||
385 | |||
386 | static const struct file_operations proc_cgroup_operations = { | ||
387 | .open = cgroup_open, | ||
388 | .read = seq_read, | ||
389 | .llseek = seq_lseek, | ||
390 | .release = single_release, | ||
391 | }; | ||
392 | #endif | ||
393 | |||
394 | #ifdef CONFIG_PROC_PID_CPUSET | 379 | #ifdef CONFIG_PROC_PID_CPUSET |
395 | 380 | ||
396 | static int cpuset_open(struct inode *inode, struct file *file) | 381 | static int cpuset_open(struct inode *inode, struct file *file) |
@@ -2576,7 +2561,7 @@ static const struct pid_entry tgid_base_stuff[] = { | |||
2576 | REG("cpuset", S_IRUGO, proc_cpuset_operations), | 2561 | REG("cpuset", S_IRUGO, proc_cpuset_operations), |
2577 | #endif | 2562 | #endif |
2578 | #ifdef CONFIG_CGROUPS | 2563 | #ifdef CONFIG_CGROUPS |
2579 | REG("cgroup", S_IRUGO, proc_cgroup_operations), | 2564 | ONE("cgroup", S_IRUGO, proc_cgroup_show), |
2580 | #endif | 2565 | #endif |
2581 | ONE("oom_score", S_IRUGO, proc_oom_score), | 2566 | ONE("oom_score", S_IRUGO, proc_oom_score), |
2582 | REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations), | 2567 | REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations), |
@@ -2922,7 +2907,7 @@ static const struct pid_entry tid_base_stuff[] = { | |||
2922 | REG("cpuset", S_IRUGO, proc_cpuset_operations), | 2907 | REG("cpuset", S_IRUGO, proc_cpuset_operations), |
2923 | #endif | 2908 | #endif |
2924 | #ifdef CONFIG_CGROUPS | 2909 | #ifdef CONFIG_CGROUPS |
2925 | REG("cgroup", S_IRUGO, proc_cgroup_operations), | 2910 | ONE("cgroup", S_IRUGO, proc_cgroup_show), |
2926 | #endif | 2911 | #endif |
2927 | ONE("oom_score", S_IRUGO, proc_oom_score), | 2912 | ONE("oom_score", S_IRUGO, proc_oom_score), |
2928 | REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations), | 2913 | REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations), |
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 51958d0fb88f..77a1d37b742b 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -37,7 +37,8 @@ extern void cgroup_exit(struct task_struct *p); | |||
37 | extern int cgroupstats_build(struct cgroupstats *stats, | 37 | extern int cgroupstats_build(struct cgroupstats *stats, |
38 | struct dentry *dentry); | 38 | struct dentry *dentry); |
39 | 39 | ||
40 | extern int proc_cgroup_show(struct seq_file *, void *); | 40 | extern int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns, |
41 | struct pid *pid, struct task_struct *tsk); | ||
41 | 42 | ||
42 | /* define the enumeration of all cgroup subsystems */ | 43 | /* define the enumeration of all cgroup subsystems */ |
43 | #define SUBSYS(_x) _x ## _cgrp_id, | 44 | #define SUBSYS(_x) _x ## _cgrp_id, |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index db19a4884a7f..df7733b48d2e 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -5030,12 +5030,9 @@ core_initcall(cgroup_wq_init); | |||
5030 | * - Print task's cgroup paths into seq_file, one line for each hierarchy | 5030 | * - Print task's cgroup paths into seq_file, one line for each hierarchy |
5031 | * - Used for /proc/<pid>/cgroup. | 5031 | * - Used for /proc/<pid>/cgroup. |
5032 | */ | 5032 | */ |
5033 | 5033 | int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns, | |
5034 | /* TODO: Use a proper seq_file iterator */ | 5034 | struct pid *pid, struct task_struct *tsk) |
5035 | int proc_cgroup_show(struct seq_file *m, void *v) | ||
5036 | { | 5035 | { |
5037 | struct pid *pid; | ||
5038 | struct task_struct *tsk; | ||
5039 | char *buf, *path; | 5036 | char *buf, *path; |
5040 | int retval; | 5037 | int retval; |
5041 | struct cgroup_root *root; | 5038 | struct cgroup_root *root; |
@@ -5045,14 +5042,6 @@ int proc_cgroup_show(struct seq_file *m, void *v) | |||
5045 | if (!buf) | 5042 | if (!buf) |
5046 | goto out; | 5043 | goto out; |
5047 | 5044 | ||
5048 | retval = -ESRCH; | ||
5049 | pid = m->private; | ||
5050 | tsk = get_pid_task(pid, PIDTYPE_PID); | ||
5051 | if (!tsk) | ||
5052 | goto out_free; | ||
5053 | |||
5054 | retval = 0; | ||
5055 | |||
5056 | mutex_lock(&cgroup_mutex); | 5045 | mutex_lock(&cgroup_mutex); |
5057 | down_read(&css_set_rwsem); | 5046 | down_read(&css_set_rwsem); |
5058 | 5047 | ||
@@ -5082,11 +5071,10 @@ int proc_cgroup_show(struct seq_file *m, void *v) | |||
5082 | seq_putc(m, '\n'); | 5071 | seq_putc(m, '\n'); |
5083 | } | 5072 | } |
5084 | 5073 | ||
5074 | retval = 0; | ||
5085 | out_unlock: | 5075 | out_unlock: |
5086 | up_read(&css_set_rwsem); | 5076 | up_read(&css_set_rwsem); |
5087 | mutex_unlock(&cgroup_mutex); | 5077 | mutex_unlock(&cgroup_mutex); |
5088 | put_task_struct(tsk); | ||
5089 | out_free: | ||
5090 | kfree(buf); | 5078 | kfree(buf); |
5091 | out: | 5079 | out: |
5092 | return retval; | 5080 | return retval; |