aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-03-19 10:23:53 -0400
committerTejun Heo <tj@kernel.org>2014-03-19 10:23:53 -0400
commit985ed670144c25058f235276f69d687de1b7c7ba (patch)
treef34e4c7c1dc4a339672749524d07eef21eefaf28 /kernel/cgroup.c
parent172a2c0685ff3bc0b7a611b308aac0694de34594 (diff)
cgroup: use cgroup_setup_root() to initialize cgroup_dummy_root
cgroup_dummy_root is used to host controllers which aren't attached to any other hierarchy. The root is minimally set up during kernfs bootstrap and didn't go through full hierarchy initialization. We're planning to use cgroup_dummy_root for the default unified hierarchy and thus want it to be fully functional. Replace the special initialization, which was collected into cgroup_init() by the previous patch, with an invocation of cgroup_setup_root(). This simplifies the init path and makes cgroup_dummy_root a full hierarchy with its own kernfs_root and all. As this puts the dummy hierarchy on the cgroup_roots list, rename for_each_active_root() to for_each_root() and update its users to skip the dummy root for now. This patch doesn't cause any userland visible behavior changes at this point. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index e66b9ee5ecc1..78017f52c69b 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -289,8 +289,8 @@ static int notify_on_release(const struct cgroup *cgrp)
289 for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \ 289 for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
290 (((ss) = cgroup_subsys[ssid]) || true); (ssid)++) 290 (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
291 291
292/* iterate across the active hierarchies */ 292/* iterate across the hierarchies */
293#define for_each_active_root(root) \ 293#define for_each_root(root) \
294 list_for_each_entry((root), &cgroup_roots, root_list) 294 list_for_each_entry((root), &cgroup_roots, root_list)
295 295
296/** 296/**
@@ -354,7 +354,6 @@ static struct css_set init_css_set = {
354 .mg_node = LIST_HEAD_INIT(init_css_set.mg_node), 354 .mg_node = LIST_HEAD_INIT(init_css_set.mg_node),
355}; 355};
356 356
357static struct cgrp_cset_link init_cgrp_cset_link;
358static int css_set_count = 1; /* 1 for init_css_set */ 357static int css_set_count = 1; /* 1 for init_css_set */
359 358
360/* 359/*
@@ -693,14 +692,13 @@ static struct cgroupfs_root *cgroup_root_from_kf(struct kernfs_root *kf_root)
693 return top_cgrp->root; 692 return top_cgrp->root;
694} 693}
695 694
696static int cgroup_init_root_id(struct cgroupfs_root *root, int start, int end) 695static int cgroup_init_root_id(struct cgroupfs_root *root)
697{ 696{
698 int id; 697 int id;
699 698
700 lockdep_assert_held(&cgroup_mutex); 699 lockdep_assert_held(&cgroup_mutex);
701 700
702 id = idr_alloc_cyclic(&cgroup_hierarchy_idr, root, start, end, 701 id = idr_alloc_cyclic(&cgroup_hierarchy_idr, root, 0, 0, GFP_KERNEL);
703 GFP_KERNEL);
704 if (id < 0) 702 if (id < 0)
705 return id; 703 return id;
706 704
@@ -1405,8 +1403,7 @@ static int cgroup_setup_root(struct cgroupfs_root *root, unsigned long ss_mask)
1405 if (ret) 1403 if (ret)
1406 goto out; 1404 goto out;
1407 1405
1408 /* ID 0 is reserved for dummy root, 1 for unified hierarchy */ 1406 ret = cgroup_init_root_id(root);
1409 ret = cgroup_init_root_id(root, 2, 0);
1410 if (ret) 1407 if (ret)
1411 goto out; 1408 goto out;
1412 1409
@@ -1486,9 +1483,12 @@ retry:
1486 goto out_unlock; 1483 goto out_unlock;
1487 1484
1488 /* look for a matching existing root */ 1485 /* look for a matching existing root */
1489 for_each_active_root(root) { 1486 for_each_root(root) {
1490 bool name_match = false; 1487 bool name_match = false;
1491 1488
1489 if (root == &cgroup_dummy_root)
1490 continue;
1491
1492 /* 1492 /*
1493 * If we asked for a name then it must match. Also, if 1493 * If we asked for a name then it must match. Also, if
1494 * name matches but sybsys_mask doesn't, we should fail. 1494 * name matches but sybsys_mask doesn't, we should fail.
@@ -2106,9 +2106,12 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
2106 int retval = 0; 2106 int retval = 0;
2107 2107
2108 mutex_lock(&cgroup_mutex); 2108 mutex_lock(&cgroup_mutex);
2109 for_each_active_root(root) { 2109 for_each_root(root) {
2110 struct cgroup *from_cgrp; 2110 struct cgroup *from_cgrp;
2111 2111
2112 if (root == &cgroup_dummy_root)
2113 continue;
2114
2112 down_read(&css_set_rwsem); 2115 down_read(&css_set_rwsem);
2113 from_cgrp = task_cgroup_from_root(from, root); 2116 from_cgrp = task_cgroup_from_root(from, root);
2114 up_read(&css_set_rwsem); 2117 up_read(&css_set_rwsem);
@@ -4073,26 +4076,17 @@ int __init cgroup_init(void)
4073 4076
4074 BUG_ON(cgroup_init_cftypes(NULL, cgroup_base_files)); 4077 BUG_ON(cgroup_init_cftypes(NULL, cgroup_base_files));
4075 4078
4076 /* allocate id for the dummy hierarchy */ 4079 mutex_lock(&cgroup_tree_mutex);
4077 mutex_lock(&cgroup_mutex); 4080 mutex_lock(&cgroup_mutex);
4078 4081
4079 /* Add init_css_set to the hash table */ 4082 /* Add init_css_set to the hash table */
4080 key = css_set_hash(init_css_set.subsys); 4083 key = css_set_hash(init_css_set.subsys);
4081 hash_add(css_set_table, &init_css_set.hlist, key); 4084 hash_add(css_set_table, &init_css_set.hlist, key);
4082 4085
4083 BUG_ON(cgroup_init_root_id(&cgroup_dummy_root, 0, 1)); 4086 BUG_ON(cgroup_setup_root(&cgroup_dummy_root, 0));
4084
4085 err = idr_alloc(&cgroup_dummy_root.cgroup_idr, cgroup_dummy_top,
4086 0, 1, GFP_KERNEL);
4087 BUG_ON(err < 0);
4088
4089 cgroup_root_count = 1;
4090 init_cgrp_cset_link.cset = &init_css_set;
4091 init_cgrp_cset_link.cgrp = cgroup_dummy_top;
4092 list_add(&init_cgrp_cset_link.cset_link, &cgroup_dummy_top->cset_links);
4093 list_add(&init_cgrp_cset_link.cgrp_link, &init_css_set.cgrp_links);
4094 4087
4095 mutex_unlock(&cgroup_mutex); 4088 mutex_unlock(&cgroup_mutex);
4089 mutex_unlock(&cgroup_tree_mutex);
4096 4090
4097 for_each_subsys(ss, ssid) { 4091 for_each_subsys(ss, ssid) {
4098 if (!ss->early_init) 4092 if (!ss->early_init)
@@ -4176,11 +4170,14 @@ int proc_cgroup_show(struct seq_file *m, void *v)
4176 mutex_lock(&cgroup_mutex); 4170 mutex_lock(&cgroup_mutex);
4177 down_read(&css_set_rwsem); 4171 down_read(&css_set_rwsem);
4178 4172
4179 for_each_active_root(root) { 4173 for_each_root(root) {
4180 struct cgroup_subsys *ss; 4174 struct cgroup_subsys *ss;
4181 struct cgroup *cgrp; 4175 struct cgroup *cgrp;
4182 int ssid, count = 0; 4176 int ssid, count = 0;
4183 4177
4178 if (root == &cgroup_dummy_root)
4179 continue;
4180
4184 seq_printf(m, "%d:", root->hierarchy_id); 4181 seq_printf(m, "%d:", root->hierarchy_id);
4185 for_each_subsys(ss, ssid) 4182 for_each_subsys(ss, ssid)
4186 if (root->subsys_mask & (1 << ssid)) 4183 if (root->subsys_mask & (1 << ssid))