diff options
author | Li Zefan <lizefan@huawei.com> | 2013-07-30 21:51:31 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-07-31 07:47:34 -0400 |
commit | e14880f7bb7e0dc0933af304998371dd543ceb40 (patch) | |
tree | d17af9f967acdce1761264a2361986f10348995e | |
parent | b414dc09a31d41d696093a4cce9fb2853a5ecd4e (diff) |
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: Li Zefan <lizefan@huawei.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r-- | include/linux/cgroup.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 4dfcd0e1b73e..bbf4d89b56a8 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -720,6 +720,24 @@ static inline struct cgroup* task_cgroup(struct task_struct *task, | |||
720 | return task_subsys_state(task, subsys_id)->cgroup; | 720 | return task_subsys_state(task, subsys_id)->cgroup; |
721 | } | 721 | } |
722 | 722 | ||
723 | /** | ||
724 | * cgroup_from_id - lookup cgroup by id | ||
725 | * @ss: cgroup subsys to be looked into | ||
726 | * @id: the cgroup id | ||
727 | * | ||
728 | * Returns the cgroup if there's valid one with @id, otherwise returns NULL. | ||
729 | * Should be called under rcu_read_lock(). | ||
730 | */ | ||
731 | static inline struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id) | ||
732 | { | ||
733 | #ifdef CONFIG_PROVE_RCU | ||
734 | rcu_lockdep_assert(rcu_read_lock_held() || | ||
735 | lockdep_is_held(&cgroup_mutex), | ||
736 | "cgroup_from_id() needs proper protection"); | ||
737 | #endif | ||
738 | return idr_find(&ss->root->cgroup_idr, id); | ||
739 | } | ||
740 | |||
723 | struct cgroup *cgroup_next_sibling(struct cgroup *pos); | 741 | struct cgroup *cgroup_next_sibling(struct cgroup *pos); |
724 | 742 | ||
725 | /** | 743 | /** |