2009-11-02 07:45:55

by Liu Aleaxander

[permalink] [raw]
Subject: [PATCH 1/3] Add the cgroup_first_css_set function

>From c5279120ee5a4c7133ce1557fef0645da05467b0 Mon Sep 17 00:00:00 2001
From: Liu Aleaxander <[email protected]>
Date: Mon, 2 Nov 2009 14:05:11 +0800
Subject: [PATCH 1/3] Add the cgroup_first_css_set function

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 <[email protected]>
---
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