aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-02-11 11:52:47 -0500
committerTejun Heo <tj@kernel.org>2014-02-11 11:52:47 -0500
commit5a17f543ed6808e9085063277fe46795dea484bd (patch)
tree8b6e2afd5619bcff76438470670247eb55bef908 /kernel/cgroup.c
parent398f878789fceb51bf5e424b753a3756643513c4 (diff)
cgroup: improve css_from_dir() into css_tryget_from_dir()
css_from_dir() returns the matching css (cgroup_subsys_state) given a dentry and subsystem. The function doesn't pin the css before returning and requires the caller to be holding RCU read lock or cgroup_mutex and handling pinning on the caller side. Given that users of the function are likely to want to pin the returned css (both existing users do) and that getting and putting css's are very cheap, there's no reason for the interface to be tricky like this. Rename css_from_dir() to css_tryget_from_dir() and make it try to pin the found css and return it only if pinning succeeded. The callers are updated so that they no longer do RCU locking and pinning around the function and just use the returned css. This will also ease converting cgroup to kernfs. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 2de8decfd99f..fc2db071d95e 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4978,28 +4978,35 @@ static int __init cgroup_disable(char *str)
4978__setup("cgroup_disable=", cgroup_disable); 4978__setup("cgroup_disable=", cgroup_disable);
4979 4979
4980/** 4980/**
4981 * css_from_dir - get corresponding css from the dentry of a cgroup dir 4981 * css_tryget_from_dir - get corresponding css from the dentry of a cgroup dir
4982 * @dentry: directory dentry of interest 4982 * @dentry: directory dentry of interest
4983 * @ss: subsystem of interest 4983 * @ss: subsystem of interest
4984 * 4984 *
4985 * Must be called under cgroup_mutex or RCU read lock. The caller is 4985 * If @dentry is a directory for a cgroup which has @ss enabled on it, try
4986 * responsible for pinning the returned css if it needs to be accessed 4986 * to get the corresponding css and return it. If such css doesn't exist
4987 * outside the critical section. 4987 * or can't be pinned, an ERR_PTR value is returned.
4988 */ 4988 */
4989struct cgroup_subsys_state *css_from_dir(struct dentry *dentry, 4989struct cgroup_subsys_state *css_tryget_from_dir(struct dentry *dentry,
4990 struct cgroup_subsys *ss) 4990 struct cgroup_subsys *ss)
4991{ 4991{
4992 struct cgroup *cgrp; 4992 struct cgroup *cgrp;
4993 4993 struct cgroup_subsys_state *css;
4994 cgroup_assert_mutex_or_rcu_locked();
4995 4994
4996 /* is @dentry a cgroup dir? */ 4995 /* is @dentry a cgroup dir? */
4997 if (!dentry->d_inode || 4996 if (!dentry->d_inode ||
4998 dentry->d_inode->i_op != &cgroup_dir_inode_operations) 4997 dentry->d_inode->i_op != &cgroup_dir_inode_operations)
4999 return ERR_PTR(-EBADF); 4998 return ERR_PTR(-EBADF);
5000 4999
5000 rcu_read_lock();
5001
5001 cgrp = __d_cgrp(dentry); 5002 cgrp = __d_cgrp(dentry);
5002 return cgroup_css(cgrp, ss) ?: ERR_PTR(-ENOENT); 5003 css = cgroup_css(cgrp, ss);
5004
5005 if (!css || !css_tryget(css))
5006 css = ERR_PTR(-ENOENT);
5007
5008 rcu_read_unlock();
5009 return css;
5003} 5010}
5004 5011
5005/** 5012/**