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
commita2bed8209a3afc3b2cf1c28383fb48155c1fea46 (patch)
treeb0b7b2dbbd0bfa934353335cb73e5adbcf207986 /kernel/cgroup.c
parent6fa4918d03c39351aef3573ac3e7958d6a5ad9b6 (diff)
cgroup: use RCU free in create_css() failure path
Currently, when create_css() fails in the middle, the half-initialized css is freed by invoking cgroup_subsys->css_free() directly. This patch updates the function so that it invokes RCU free path instead. As the RCU free path puts the parent css and owning cgroup, their references are now acquired right after a new css is successfully allocated. This doesn't make any visible difference now but is to enable implementing css->id and RCU protected lookup by such IDs. 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.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7cb9c0847445..0e2c401ed7b9 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4185,12 +4185,14 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
4185 if (IS_ERR(css)) 4185 if (IS_ERR(css))
4186 return PTR_ERR(css); 4186 return PTR_ERR(css);
4187 4187
4188 init_css(css, ss, cgrp);
4189 cgroup_get(cgrp);
4190 css_get(css->parent);
4191
4188 err = percpu_ref_init(&css->refcnt, css_release); 4192 err = percpu_ref_init(&css->refcnt, css_release);
4189 if (err) 4193 if (err)
4190 goto err_free_css; 4194 goto err_free_css;
4191 4195
4192 init_css(css, ss, cgrp);
4193
4194 err = cgroup_populate_dir(cgrp, 1 << ss->id); 4196 err = cgroup_populate_dir(cgrp, 1 << ss->id);
4195 if (err) 4197 if (err)
4196 goto err_free_percpu_ref; 4198 goto err_free_percpu_ref;
@@ -4199,9 +4201,6 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
4199 if (err) 4201 if (err)
4200 goto err_clear_dir; 4202 goto err_clear_dir;
4201 4203
4202 cgroup_get(cgrp);
4203 css_get(css->parent);
4204
4205 if (ss->broken_hierarchy && !ss->warned_broken_hierarchy && 4204 if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
4206 parent->parent) { 4205 parent->parent) {
4207 pr_warn("%s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n", 4206 pr_warn("%s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n",
@@ -4218,7 +4217,7 @@ err_clear_dir:
4218err_free_percpu_ref: 4217err_free_percpu_ref:
4219 percpu_ref_cancel_init(&css->refcnt); 4218 percpu_ref_cancel_init(&css->refcnt);
4220err_free_css: 4219err_free_css:
4221 ss->css_free(css); 4220 call_rcu(&css->rcu_head, css_free_rcu_fn);
4222 return err; 4221 return err;
4223} 4222}
4224 4223