aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-04 15:09:14 -0400
committerTejun Heo <tj@kernel.org>2014-05-04 15:09:14 -0400
commitddfcadab35dda6e5bc23ccf1c3055ecb63a71e49 (patch)
tree68ff0218d96629b63d30a3a91580bff256f93c28 /kernel/cgroup.c
parenta2bed8209a3afc3b2cf1c28383fb48155c1fea46 (diff)
cgroup: update init_css() into init_and_link_css()
init_css() takes the cgroup the new css belongs to as an argument and initializes the new css's ->cgroup and ->parent pointers but doesn't acquire the matching reference counts. After the previous patch, create_css() puts init_css() and reference acquisition right next to each other. Let's move reference acquistion into init_css() and rename the function to init_and_link_css(). This makes sense and is easier to follow. This makes the root csses to hold a reference on cgrp_dfl_root.cgrp, which is harmless. 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.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0e2c401ed7b9..f1c98c527b2d 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4109,17 +4109,21 @@ static void css_release(struct percpu_ref *ref)
4109 call_rcu(&css->rcu_head, css_free_rcu_fn); 4109 call_rcu(&css->rcu_head, css_free_rcu_fn);
4110} 4110}
4111 4111
4112static void init_css(struct cgroup_subsys_state *css, struct cgroup_subsys *ss, 4112static void init_and_link_css(struct cgroup_subsys_state *css,
4113 struct cgroup *cgrp) 4113 struct cgroup_subsys *ss, struct cgroup *cgrp)
4114{ 4114{
4115 cgroup_get(cgrp);
4116
4115 css->cgroup = cgrp; 4117 css->cgroup = cgrp;
4116 css->ss = ss; 4118 css->ss = ss;
4117 css->flags = 0; 4119 css->flags = 0;
4118 4120
4119 if (cgrp->parent) 4121 if (cgrp->parent) {
4120 css->parent = cgroup_css(cgrp->parent, ss); 4122 css->parent = cgroup_css(cgrp->parent, ss);
4121 else 4123 css_get(css->parent);
4124 } else {
4122 css->flags |= CSS_ROOT; 4125 css->flags |= CSS_ROOT;
4126 }
4123 4127
4124 BUG_ON(cgroup_css(cgrp, ss)); 4128 BUG_ON(cgroup_css(cgrp, ss));
4125} 4129}
@@ -4185,9 +4189,7 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
4185 if (IS_ERR(css)) 4189 if (IS_ERR(css))
4186 return PTR_ERR(css); 4190 return PTR_ERR(css);
4187 4191
4188 init_css(css, ss, cgrp); 4192 init_and_link_css(css, ss, cgrp);
4189 cgroup_get(cgrp);
4190 css_get(css->parent);
4191 4193
4192 err = percpu_ref_init(&css->refcnt, css_release); 4194 err = percpu_ref_init(&css->refcnt, css_release);
4193 if (err) 4195 if (err)
@@ -4656,7 +4658,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
4656 css = ss->css_alloc(cgroup_css(&cgrp_dfl_root.cgrp, ss)); 4658 css = ss->css_alloc(cgroup_css(&cgrp_dfl_root.cgrp, ss));
4657 /* We don't handle early failures gracefully */ 4659 /* We don't handle early failures gracefully */
4658 BUG_ON(IS_ERR(css)); 4660 BUG_ON(IS_ERR(css));
4659 init_css(css, ss, &cgrp_dfl_root.cgrp); 4661 init_and_link_css(css, ss, &cgrp_dfl_root.cgrp);
4660 4662
4661 /* Update the init_css_set to contain a subsys 4663 /* Update the init_css_set to contain a subsys
4662 * pointer to this state - since the subsystem is 4664 * pointer to this state - since the subsystem is