diff options
-rw-r--r-- | include/linux/cgroup.h | 18 | ||||
-rw-r--r-- | kernel/cgroup.c | 25 |
2 files changed, 33 insertions, 10 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index ee041a01a67e..d0ad3794b947 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -688,9 +688,9 @@ struct cgroup *cgroup_next_sibling(struct cgroup *pos); | |||
688 | /** | 688 | /** |
689 | * cgroup_for_each_child - iterate through children of a cgroup | 689 | * cgroup_for_each_child - iterate through children of a cgroup |
690 | * @pos: the cgroup * to use as the loop cursor | 690 | * @pos: the cgroup * to use as the loop cursor |
691 | * @cgroup: cgroup whose children to walk | 691 | * @cgrp: cgroup whose children to walk |
692 | * | 692 | * |
693 | * Walk @cgroup's children. Must be called under rcu_read_lock(). A child | 693 | * Walk @cgrp's children. Must be called under rcu_read_lock(). A child |
694 | * cgroup which hasn't finished ->css_online() or already has finished | 694 | * cgroup which hasn't finished ->css_online() or already has finished |
695 | * ->css_offline() may show up during traversal and it's each subsystem's | 695 | * ->css_offline() may show up during traversal and it's each subsystem's |
696 | * responsibility to verify that each @pos is alive. | 696 | * responsibility to verify that each @pos is alive. |
@@ -698,9 +698,15 @@ struct cgroup *cgroup_next_sibling(struct cgroup *pos); | |||
698 | * If a subsystem synchronizes against the parent in its ->css_online() and | 698 | * If a subsystem synchronizes against the parent in its ->css_online() and |
699 | * before starting iterating, a cgroup which finished ->css_online() is | 699 | * before starting iterating, a cgroup which finished ->css_online() is |
700 | * guaranteed to be visible in the future iterations. | 700 | * guaranteed to be visible in the future iterations. |
701 | * | ||
702 | * It is allowed to temporarily drop RCU read lock during iteration. The | ||
703 | * caller is responsible for ensuring that @pos remains accessible until | ||
704 | * the start of the next iteration by, for example, bumping the css refcnt. | ||
701 | */ | 705 | */ |
702 | #define cgroup_for_each_child(pos, cgroup) \ | 706 | #define cgroup_for_each_child(pos, cgrp) \ |
703 | list_for_each_entry_rcu(pos, &(cgroup)->children, sibling) | 707 | for ((pos) = list_first_or_null_rcu(&(cgrp)->children, \ |
708 | struct cgroup, sibling); \ | ||
709 | (pos); (pos) = cgroup_next_sibling((pos))) | ||
704 | 710 | ||
705 | struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos, | 711 | struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos, |
706 | struct cgroup *cgroup); | 712 | struct cgroup *cgroup); |
@@ -759,6 +765,10 @@ struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos); | |||
759 | * Alternatively, a subsystem may choose to use a single global lock to | 765 | * Alternatively, a subsystem may choose to use a single global lock to |
760 | * synchronize ->css_online() and ->css_offline() against tree-walking | 766 | * synchronize ->css_online() and ->css_offline() against tree-walking |
761 | * operations. | 767 | * operations. |
768 | * | ||
769 | * It is allowed to temporarily drop RCU read lock during iteration. The | ||
770 | * caller is responsible for ensuring that @pos remains accessible until | ||
771 | * the start of the next iteration by, for example, bumping the css refcnt. | ||
762 | */ | 772 | */ |
763 | #define cgroup_for_each_descendant_pre(pos, cgroup) \ | 773 | #define cgroup_for_each_descendant_pre(pos, cgroup) \ |
764 | for (pos = cgroup_next_descendant_pre(NULL, (cgroup)); (pos); \ | 774 | for (pos = cgroup_next_descendant_pre(NULL, (cgroup)); (pos); \ |
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 | */ |
3035 | struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos, | 3040 | struct 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 | */ |
3073 | struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos) | 3081 | struct 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 | */ |
3112 | struct cgroup *cgroup_next_descendant_post(struct cgroup *pos, | 3125 | struct 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 */ |