Commit 195e9b6c authored by Tejun Heo's avatar Tejun Heo

cgroup: reorder operations in cgroup_mkdir()

Currently, operations to initialize internal objects and create
interface directory and files are intermixed in cgroup_mkdir().  We're
in the process of refactoring cgroup and css management paths to
separate them out to eventually allow cgroups which aren't visible
through cgroup fs.

This patch reorders operations inside cgroup_mkdir() so that interface
directory and file handling comes after internal object
initialization.  This will enable further refactoring.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarZefan Li <lizefan@huawei.com>
parent 88cb04b9
...@@ -4945,20 +4945,6 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -4945,20 +4945,6 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &parent->flags)) if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &parent->flags))
set_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags); set_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags);
/* create the directory */
kn = kernfs_create_dir(parent->kn, name, mode, cgrp);
if (IS_ERR(kn)) {
ret = PTR_ERR(kn);
goto out_free_id;
}
cgrp->kn = kn;
/*
* This extra ref will be put in cgroup_free_fn() and guarantees
* that @cgrp->kn is always accessible.
*/
kernfs_get(kn);
cgrp->self.serial_nr = css_serial_nr_next++; cgrp->self.serial_nr = css_serial_nr_next++;
/* allocation complete, commit to creation */ /* allocation complete, commit to creation */
...@@ -4972,15 +4958,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -4972,15 +4958,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
*/ */
cgroup_idr_replace(&root->cgroup_idr, cgrp, cgrp->id); cgroup_idr_replace(&root->cgroup_idr, cgrp, cgrp->id);
ret = cgroup_kn_set_ugid(kn); /* create the csses */
if (ret)
goto out_destroy;
ret = css_populate_dir(&cgrp->self, NULL);
if (ret)
goto out_destroy;
/* let's create and online css's */
do_each_subsys_mask(ss, ssid, parent->subtree_ss_mask) { do_each_subsys_mask(ss, ssid, parent->subtree_ss_mask) {
struct cgroup_subsys_state *css; struct cgroup_subsys_state *css;
...@@ -4989,12 +4967,6 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -4989,12 +4967,6 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
ret = PTR_ERR(css); ret = PTR_ERR(css);
goto out_destroy; goto out_destroy;
} }
if (parent->subtree_control & (1 << ssid)) {
ret = css_populate_dir(css, NULL);
if (ret)
goto out_destroy;
}
} while_each_subsys_mask(); } while_each_subsys_mask();
/* /*
...@@ -5006,13 +4978,40 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -5006,13 +4978,40 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
cgroup_refresh_subtree_ss_mask(cgrp); cgroup_refresh_subtree_ss_mask(cgrp);
} }
/* create the directory */
kn = kernfs_create_dir(parent->kn, name, mode, cgrp);
if (IS_ERR(kn)) {
ret = PTR_ERR(kn);
goto out_destroy;
}
cgrp->kn = kn;
/*
* This extra ref will be put in cgroup_free_fn() and guarantees
* that @cgrp->kn is always accessible.
*/
kernfs_get(kn);
ret = cgroup_kn_set_ugid(kn);
if (ret)
goto out_destroy;
ret = css_populate_dir(&cgrp->self, NULL);
if (ret)
goto out_destroy;
do_each_subsys_mask(ss, ssid, parent->subtree_control) {
ret = css_populate_dir(cgroup_css(cgrp, ss), NULL);
if (ret)
goto out_destroy;
} while_each_subsys_mask();
/* let's create and online css's */
kernfs_activate(kn); kernfs_activate(kn);
ret = 0; ret = 0;
goto out_unlock; goto out_unlock;
out_free_id:
cgroup_idr_remove(&root->cgroup_idr, cgrp->id);
out_cancel_ref: out_cancel_ref:
percpu_ref_exit(&cgrp->self.refcnt); percpu_ref_exit(&cgrp->self.refcnt);
out_free_cgrp: out_free_cgrp:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment