diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-26 18:40:56 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-26 18:40:56 -0400 |
commit | 35cf083619da5677f83e9a8eae813f0b413d7082 (patch) | |
tree | 509ea1ae09644bc82040ec919fa94c928e98db27 | |
parent | 6e6eab0efdf48fb2d8d7aee904d7740acb4661c6 (diff) |
cgroup: rename cgroup_css_from_dir() to css_from_dir() and update its syntax
cgroup_css_from_dir() will grow another user. In preparation, make
the following changes.
* All css functions are prefixed with just "css_", rename it to
css_from_dir().
* Take dentry * instead of file * as dentry is what ultimately
identifies a cgroup and file may not always be available. Note that
the function now checkes whether @dentry->d_inode is NULL as the
caller now may specify a negative dentry.
* Make it take cgroup_subsys * instead of integer subsys_id. This
simplifies the function and allows specifying no subsystem for
cgroup->dummy_css.
* Make return section a bit less verbose.
This patch doesn't introduce any behavior changes.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
-rw-r--r-- | include/linux/cgroup.h | 3 | ||||
-rw-r--r-- | kernel/cgroup.c | 26 | ||||
-rw-r--r-- | kernel/events/core.c | 2 |
3 files changed, 13 insertions, 18 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index b685955d4b29..21ba29869eb8 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -903,7 +903,8 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg, | |||
903 | 903 | ||
904 | /* Get id and depth of css */ | 904 | /* Get id and depth of css */ |
905 | unsigned short css_id(struct cgroup_subsys_state *css); | 905 | unsigned short css_id(struct cgroup_subsys_state *css); |
906 | struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id); | 906 | struct cgroup_subsys_state *css_from_dir(struct dentry *dentry, |
907 | struct cgroup_subsys *ss); | ||
907 | 908 | ||
908 | #else /* !CONFIG_CGROUPS */ | 909 | #else /* !CONFIG_CGROUPS */ |
909 | 910 | ||
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index ef43e3f453ef..921b1387c944 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -5700,34 +5700,28 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id) | |||
5700 | EXPORT_SYMBOL_GPL(css_lookup); | 5700 | EXPORT_SYMBOL_GPL(css_lookup); |
5701 | 5701 | ||
5702 | /** | 5702 | /** |
5703 | * cgroup_css_from_dir - get corresponding css from file open on cgroup dir | 5703 | * css_from_dir - get corresponding css from the dentry of a cgroup dir |
5704 | * @f: directory file of interest | 5704 | * @dentry: directory dentry of interest |
5705 | * @id: subsystem id of interest | 5705 | * @ss: subsystem of interest |
5706 | * | 5706 | * |
5707 | * Must be called under RCU read lock. The caller is responsible for | 5707 | * Must be called under RCU read lock. The caller is responsible for |
5708 | * pinning the returned css if it needs to be accessed outside the RCU | 5708 | * pinning the returned css if it needs to be accessed outside the RCU |
5709 | * critical section. | 5709 | * critical section. |
5710 | */ | 5710 | */ |
5711 | struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id) | 5711 | struct cgroup_subsys_state *css_from_dir(struct dentry *dentry, |
5712 | struct cgroup_subsys *ss) | ||
5712 | { | 5713 | { |
5713 | struct cgroup *cgrp; | 5714 | struct cgroup *cgrp; |
5714 | struct inode *inode; | ||
5715 | struct cgroup_subsys_state *css; | ||
5716 | 5715 | ||
5717 | WARN_ON_ONCE(!rcu_read_lock_held()); | 5716 | WARN_ON_ONCE(!rcu_read_lock_held()); |
5718 | 5717 | ||
5719 | inode = file_inode(f); | 5718 | /* is @dentry a cgroup dir? */ |
5720 | /* check in cgroup filesystem dir */ | 5719 | if (!dentry->d_inode || |
5721 | if (inode->i_op != &cgroup_dir_inode_operations) | 5720 | dentry->d_inode->i_op != &cgroup_dir_inode_operations) |
5722 | return ERR_PTR(-EBADF); | 5721 | return ERR_PTR(-EBADF); |
5723 | 5722 | ||
5724 | if (id < 0 || id >= CGROUP_SUBSYS_COUNT) | 5723 | cgrp = __d_cgrp(dentry); |
5725 | return ERR_PTR(-EINVAL); | 5724 | return cgroup_css(cgrp, ss->subsys_id) ?: ERR_PTR(-ENOENT); |
5726 | |||
5727 | /* get cgroup */ | ||
5728 | cgrp = __d_cgrp(f->f_dentry); | ||
5729 | css = cgroup_css(cgrp, id); | ||
5730 | return css ? css : ERR_PTR(-ENOENT); | ||
5731 | } | 5725 | } |
5732 | 5726 | ||
5733 | /** | 5727 | /** |
diff --git a/kernel/events/core.c b/kernel/events/core.c index 23261f957713..b59ab6632f30 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -593,7 +593,7 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, | |||
593 | 593 | ||
594 | rcu_read_lock(); | 594 | rcu_read_lock(); |
595 | 595 | ||
596 | css = cgroup_css_from_dir(f.file, perf_subsys_id); | 596 | css = css_from_dir(f.file->f_dentry, &perf_subsys); |
597 | if (IS_ERR(css)) { | 597 | if (IS_ERR(css)) { |
598 | ret = PTR_ERR(css); | 598 | ret = PTR_ERR(css); |
599 | goto out; | 599 | goto out; |