[PATCH 1/3] Add the cgroup_first_css_set function

From: Liu Aleaxander
Date: Mon Nov 02 2009 - 01:05:11 EST


It will return the first css_set of the specified cgroup if any as
the 'current' css_set used by the debug subsystem. Note: return NUll
is a normal case as there are no css_sets in that cgroup now.

And this would stop the debug subsystem from printing the *same*
content of debug.current_css_set and debug.current_css_set_refcount
even though in different directories, aka cgroups.

Signed-off-by: Liu Aleaxander <Aleaxander@xxxxxxxxx>
---
include/linux/cgroup.h | 2 ++
kernel/cgroup.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 0008dee..4d63c5c 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -389,6 +389,8 @@ int cgroup_add_files(struct cgroup *cgrp,
const struct cftype cft[],
int count);

+struct css_set* cgroup_first_css_set(const struct cgroup *cgrp);
+
int cgroup_is_removed(const struct cgroup *cgrp);

int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0249f4b..863089f 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -338,6 +338,26 @@ static inline void put_css_set_taskexit(struct css_set *cg)
}

/*
+ * Get the first css_set of the cgroup 'cgrp'.
+ */
+struct css_set* cgroup_first_css_set(const struct cgroup *cgrp)
+{
+ struct list_head *head = &cgrp->css_sets;
+ struct cg_cgroup_link *link;
+
+ read_lock(&css_set_lock);
+ if (list_empty(head)) {
+ read_unlock(&css_set_lock);
+ return NULL;
+ }
+ link = list_first_entry(head, struct cg_cgroup_link, cgrp_link_list);
+ read_unlock(&css_set_lock);
+ BUG_ON(!link);
+
+ return link->cg;
+}
+
+/*
* compare_css_sets - helper function for find_existing_css_set().
* @cg: candidate css_set being tested
* @old_cg: existing css_set for a task
--
1.6.2.5

--
regards
Liu Aleaxander
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/