cgroup: combine css handling loops in cgroup_create()
Now that css operations in cgroup_create() are back-to-back, there isn't much point in allocating css's in one loop and onlining them in another. Merge the two loops so that a css is allocated and onlined on each iteration. css_ar[] is no longer necessary and replaced with a single pointer. This also simplifies the error handling path. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
This commit is contained in:
parent
0d80255e42
commit
9d403e9923
|
@ -4084,7 +4084,7 @@ static void offline_css(struct cgroup_subsys_state *css)
|
||||||
static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
||||||
umode_t mode)
|
umode_t mode)
|
||||||
{
|
{
|
||||||
struct cgroup_subsys_state *css_ar[CGROUP_SUBSYS_COUNT] = { };
|
struct cgroup_subsys_state *css = NULL;
|
||||||
struct cgroup *cgrp;
|
struct cgroup *cgrp;
|
||||||
struct cgroup_name *name;
|
struct cgroup_name *name;
|
||||||
struct cgroupfs_root *root = parent->root;
|
struct cgroupfs_root *root = parent->root;
|
||||||
|
@ -4173,26 +4173,20 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
||||||
if (err)
|
if (err)
|
||||||
goto err_destroy;
|
goto err_destroy;
|
||||||
|
|
||||||
|
/* let's create and online css's */
|
||||||
for_each_root_subsys(root, ss) {
|
for_each_root_subsys(root, ss) {
|
||||||
struct cgroup_subsys_state *css;
|
|
||||||
|
|
||||||
css = ss->css_alloc(cgroup_css(parent, ss));
|
css = ss->css_alloc(cgroup_css(parent, ss));
|
||||||
if (IS_ERR(css)) {
|
if (IS_ERR(css)) {
|
||||||
err = PTR_ERR(css);
|
err = PTR_ERR(css);
|
||||||
|
css = NULL;
|
||||||
goto err_destroy;
|
goto err_destroy;
|
||||||
}
|
}
|
||||||
css_ar[ss->subsys_id] = css;
|
|
||||||
|
|
||||||
err = percpu_ref_init(&css->refcnt, css_release);
|
err = percpu_ref_init(&css->refcnt, css_release);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_destroy;
|
goto err_destroy;
|
||||||
|
|
||||||
init_css(css, ss, cgrp);
|
init_css(css, ss, cgrp);
|
||||||
}
|
|
||||||
|
|
||||||
/* creation succeeded, notify subsystems */
|
|
||||||
for_each_root_subsys(root, ss) {
|
|
||||||
struct cgroup_subsys_state *css = css_ar[ss->subsys_id];
|
|
||||||
|
|
||||||
err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id);
|
err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -4202,12 +4196,11 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
||||||
if (err)
|
if (err)
|
||||||
goto err_destroy;
|
goto err_destroy;
|
||||||
|
|
||||||
/* each css holds a ref to the cgroup's dentry and parent css */
|
|
||||||
dget(dentry);
|
dget(dentry);
|
||||||
css_get(css->parent);
|
css_get(css->parent);
|
||||||
|
|
||||||
/* mark it consumed for error path */
|
/* mark it consumed for error path */
|
||||||
css_ar[ss->subsys_id] = NULL;
|
css = NULL;
|
||||||
|
|
||||||
if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
|
if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
|
||||||
parent->parent) {
|
parent->parent) {
|
||||||
|
@ -4237,13 +4230,9 @@ err_free_cgrp:
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err_destroy:
|
err_destroy:
|
||||||
for_each_root_subsys(root, ss) {
|
if (css) {
|
||||||
struct cgroup_subsys_state *css = css_ar[ss->subsys_id];
|
percpu_ref_cancel_init(&css->refcnt);
|
||||||
|
css->ss->css_free(css);
|
||||||
if (css) {
|
|
||||||
percpu_ref_cancel_init(&css->refcnt);
|
|
||||||
ss->css_free(css);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cgroup_destroy_locked(cgrp);
|
cgroup_destroy_locked(cgrp);
|
||||||
mutex_unlock(&cgroup_mutex);
|
mutex_unlock(&cgroup_mutex);
|
||||||
|
|
Loading…
Reference in New Issue