aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-05-23 21:55:38 -0400
committerTejun Heo <tj@kernel.org>2013-05-23 21:55:38 -0400
commit75501a6d59e989e5c286716e5b3b66ace4660e83 (patch)
tree087af4f93bba2257ae139c5e4a0f3b850954ed81 /kernel/cgroup.c
parent53fa5261747a90746531e8a1c81eeb78fedc2f71 (diff)
cgroup: update iterators to use cgroup_next_sibling()
This patch converts cgroup_for_each_child(), cgroup_next_descendant_pre/post() and thus cgroup_for_each_descendant_pre/post() to use cgroup_next_sibling() instead of manually dereferencing ->sibling.next. The only reason the iterators couldn't allow dropping RCU read lock while iteration is in progress was because they couldn't determine the next sibling safely once RCU read lock is dropped. Using cgroup_next_sibling() removes that problem and enables all iterators to allow dropping RCU read lock in the middle. Comments are updated accordingly. This makes the iterators easier to use and will simplify controllers. Note that @cgroup argument is renamed to @cgrp in cgroup_for_each_child() because it conflicts with "struct cgroup" used in the new macro body. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> Reviewed-by: Michal Hocko <mhocko@suse.cz>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index b87c7a5a5497..fefc41c1a147 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3031,6 +3031,11 @@ EXPORT_SYMBOL_GPL(cgroup_next_sibling);
3031 * 3031 *
3032 * To be used by cgroup_for_each_descendant_pre(). Find the next 3032 * To be used by cgroup_for_each_descendant_pre(). Find the next
3033 * descendant to visit for pre-order traversal of @cgroup's descendants. 3033 * descendant to visit for pre-order traversal of @cgroup's descendants.
3034 *
3035 * While this function requires RCU read locking, it doesn't require the
3036 * whole traversal to be contained in a single RCU critical section. This
3037 * function will return the correct next descendant as long as both @pos
3038 * and @cgroup are accessible and @pos is a descendant of @cgroup.
3034 */ 3039 */
3035struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos, 3040struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,
3036 struct cgroup *cgroup) 3041 struct cgroup *cgroup)
@@ -3050,11 +3055,9 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,
3050 3055
3051 /* no child, visit my or the closest ancestor's next sibling */ 3056 /* no child, visit my or the closest ancestor's next sibling */
3052 while (pos != cgroup) { 3057 while (pos != cgroup) {
3053 next = list_entry_rcu(pos->sibling.next, struct cgroup, 3058 next = cgroup_next_sibling(pos);
3054 sibling); 3059 if (next)
3055 if (&next->sibling != &pos->parent->children)
3056 return next; 3060 return next;
3057
3058 pos = pos->parent; 3061 pos = pos->parent;
3059 } 3062 }
3060 3063
@@ -3069,6 +3072,11 @@ EXPORT_SYMBOL_GPL(cgroup_next_descendant_pre);
3069 * Return the rightmost descendant of @pos. If there's no descendant, 3072 * Return the rightmost descendant of @pos. If there's no descendant,
3070 * @pos is returned. This can be used during pre-order traversal to skip 3073 * @pos is returned. This can be used during pre-order traversal to skip
3071 * subtree of @pos. 3074 * subtree of @pos.
3075 *
3076 * While this function requires RCU read locking, it doesn't require the
3077 * whole traversal to be contained in a single RCU critical section. This
3078 * function will return the correct rightmost descendant as long as @pos is
3079 * accessible.
3072 */ 3080 */
3073struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos) 3081struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos)
3074{ 3082{
@@ -3108,6 +3116,11 @@ static struct cgroup *cgroup_leftmost_descendant(struct cgroup *pos)
3108 * 3116 *
3109 * To be used by cgroup_for_each_descendant_post(). Find the next 3117 * To be used by cgroup_for_each_descendant_post(). Find the next
3110 * descendant to visit for post-order traversal of @cgroup's descendants. 3118 * descendant to visit for post-order traversal of @cgroup's descendants.
3119 *
3120 * While this function requires RCU read locking, it doesn't require the
3121 * whole traversal to be contained in a single RCU critical section. This
3122 * function will return the correct next descendant as long as both @pos
3123 * and @cgroup are accessible and @pos is a descendant of @cgroup.
3111 */ 3124 */
3112struct cgroup *cgroup_next_descendant_post(struct cgroup *pos, 3125struct cgroup *cgroup_next_descendant_post(struct cgroup *pos,
3113 struct cgroup *cgroup) 3126 struct cgroup *cgroup)
@@ -3123,8 +3136,8 @@ struct cgroup *cgroup_next_descendant_post(struct cgroup *pos,
3123 } 3136 }
3124 3137
3125 /* if there's an unvisited sibling, visit its leftmost descendant */ 3138 /* if there's an unvisited sibling, visit its leftmost descendant */
3126 next = list_entry_rcu(pos->sibling.next, struct cgroup, sibling); 3139 next = cgroup_next_sibling(pos);
3127 if (&next->sibling != &pos->parent->children) 3140 if (next)
3128 return cgroup_leftmost_descendant(next); 3141 return cgroup_leftmost_descendant(next);
3129 3142
3130 /* no sibling left, visit parent */ 3143 /* no sibling left, visit parent */