Commit e14880f7 authored by Li Zefan's avatar Li Zefan Committed by Tejun Heo

cgroup: implement cgroup_from_id()

This will be used as a replacement for css_lookup().

There's a difference with cgroup id and css id. cgroup id starts with 0,
while css id starts with 1.

v4:
- also check if cggroup_mutex is held.
- make it an inline function.
Signed-off-by: default avatarLi Zefan <lizefan@huawei.com>
Reviewed-by: default avatarMichal Hocko <mhocko@suse.cz>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent b414dc09
......@@ -720,6 +720,24 @@ static inline struct cgroup* task_cgroup(struct task_struct *task,
return task_subsys_state(task, subsys_id)->cgroup;
}
/**
* cgroup_from_id - lookup cgroup by id
* @ss: cgroup subsys to be looked into
* @id: the cgroup id
*
* Returns the cgroup if there's valid one with @id, otherwise returns NULL.
* Should be called under rcu_read_lock().
*/
static inline struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id)
{
#ifdef CONFIG_PROVE_RCU
rcu_lockdep_assert(rcu_read_lock_held() ||
lockdep_is_held(&cgroup_mutex),
"cgroup_from_id() needs proper protection");
#endif
return idr_find(&ss->root->cgroup_idr, id);
}
struct cgroup *cgroup_next_sibling(struct cgroup *pos);
/**
......
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