From 1ea14b2fdb4912e1379c25503c8a3d0189d8d821 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 7 Jan 2013 08:49:33 -0800 Subject: [PATCH] --- yaml --- r: 350317 b: refs/heads/master c: 12a9d2fef1d35770d3cdc2cd1faabb83c45bc0fa h: refs/heads/master i: 350315: 5443e6bce69941f6112a0a675ae52748a8bfe009 v: v3 --- [refs] | 2 +- trunk/include/linux/cgroup.h | 1 + trunk/kernel/cgroup.c | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 6073e5a536c0..476feb229710 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: d5b1fe68baa7213f198e5be8cd1a1037258ab2c8 +refs/heads/master: 12a9d2fef1d35770d3cdc2cd1faabb83c45bc0fa diff --git a/trunk/include/linux/cgroup.h b/trunk/include/linux/cgroup.h index 942e68705577..8118a3120378 100644 --- a/trunk/include/linux/cgroup.h +++ b/trunk/include/linux/cgroup.h @@ -558,6 +558,7 @@ static inline struct cgroup* task_cgroup(struct task_struct *task, struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos, struct cgroup *cgroup); +struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos); /** * cgroup_for_each_descendant_pre - pre-order walk of a cgroup's descendants diff --git a/trunk/kernel/cgroup.c b/trunk/kernel/cgroup.c index 4855892798fd..6643f7053454 100644 --- a/trunk/kernel/cgroup.c +++ b/trunk/kernel/cgroup.c @@ -3017,6 +3017,32 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos, } EXPORT_SYMBOL_GPL(cgroup_next_descendant_pre); +/** + * cgroup_rightmost_descendant - return the rightmost descendant of a cgroup + * @pos: cgroup of interest + * + * Return the rightmost descendant of @pos. If there's no descendant, + * @pos is returned. This can be used during pre-order traversal to skip + * subtree of @pos. + */ +struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos) +{ + struct cgroup *last, *tmp; + + WARN_ON_ONCE(!rcu_read_lock_held()); + + do { + last = pos; + /* ->prev isn't RCU safe, walk ->next till the end */ + pos = NULL; + list_for_each_entry_rcu(tmp, &last->children, sibling) + pos = tmp; + } while (pos); + + return last; +} +EXPORT_SYMBOL_GPL(cgroup_rightmost_descendant); + static struct cgroup *cgroup_leftmost_descendant(struct cgroup *pos) { struct cgroup *last;