Commit 03970d3c authored by Tejun Heo's avatar Tejun Heo

cgroup: use cgroup_apply_enable_control() in cgroup creation path

cgroup_create() manually updates control masks and creates child csses
which cgroup_mkdir() then manually populates.  Both can be simplified
by using cgroup_apply_enable_control() and friends.  The only catch is
that it calls css_populate_dir() with NULL cgroup->kn during
cgroup_create().  This is worked around by making the function noop on
NULL kn.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarZefan Li <lizefan@huawei.com>
parent 945ba199
...@@ -1490,7 +1490,7 @@ static int css_populate_dir(struct cgroup_subsys_state *css, ...@@ -1490,7 +1490,7 @@ static int css_populate_dir(struct cgroup_subsys_state *css,
struct cftype *cfts, *failed_cfts; struct cftype *cfts, *failed_cfts;
int ret; int ret;
if (css->flags & CSS_VISIBLE) if ((css->flags & CSS_VISIBLE) || !cgrp->kn)
return 0; return 0;
if (!css->ss) { if (!css->ss) {
...@@ -5042,10 +5042,9 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp, ...@@ -5042,10 +5042,9 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp,
static struct cgroup *cgroup_create(struct cgroup *parent) static struct cgroup *cgroup_create(struct cgroup *parent)
{ {
struct cgroup_root *root = parent->root; struct cgroup_root *root = parent->root;
struct cgroup_subsys *ss;
struct cgroup *cgrp, *tcgrp; struct cgroup *cgrp, *tcgrp;
int level = parent->level + 1; int level = parent->level + 1;
int ssid, ret; int ret;
/* allocate the cgroup and its ID, 0 is reserved for the root */ /* allocate the cgroup and its ID, 0 is reserved for the root */
cgrp = kzalloc(sizeof(*cgrp) + cgrp = kzalloc(sizeof(*cgrp) +
...@@ -5095,25 +5094,19 @@ static struct cgroup *cgroup_create(struct cgroup *parent) ...@@ -5095,25 +5094,19 @@ static struct cgroup *cgroup_create(struct cgroup *parent)
*/ */
cgroup_idr_replace(&root->cgroup_idr, cgrp, cgrp->id); cgroup_idr_replace(&root->cgroup_idr, cgrp, cgrp->id);
/* create the csses */
do_each_subsys_mask(ss, ssid, cgroup_ss_mask(cgrp)) {
struct cgroup_subsys_state *css;
css = css_create(cgrp, ss);
if (IS_ERR(css)) {
ret = PTR_ERR(css);
goto out_destroy;
}
} while_each_subsys_mask();
/* /*
* On the default hierarchy, a child doesn't automatically inherit * On the default hierarchy, a child doesn't automatically inherit
* subtree_control from the parent. Each is configured manually. * subtree_control from the parent. Each is configured manually.
*/ */
if (!cgroup_on_dfl(cgrp)) { if (!cgroup_on_dfl(cgrp))
cgrp->subtree_control = cgroup_control(cgrp); cgrp->subtree_control = cgroup_control(cgrp);
cgroup_refresh_subtree_ss_mask(cgrp);
} cgroup_propagate_control(cgrp);
/* @cgrp doesn't have dir yet so the following will only create csses */
ret = cgroup_apply_control_enable(cgrp);
if (ret)
goto out_destroy;
return cgrp; return cgrp;
...@@ -5131,9 +5124,8 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -5131,9 +5124,8 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
umode_t mode) umode_t mode)
{ {
struct cgroup *parent, *cgrp; struct cgroup *parent, *cgrp;
struct cgroup_subsys *ss;
struct kernfs_node *kn; struct kernfs_node *kn;
int ssid, ret; int ret;
/* do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable */ /* do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable */
if (strchr(name, '\n')) if (strchr(name, '\n'))
...@@ -5171,11 +5163,9 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -5171,11 +5163,9 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
if (ret) if (ret)
goto out_destroy; goto out_destroy;
do_each_subsys_mask(ss, ssid, cgroup_control(cgrp)) { ret = cgroup_apply_control_enable(cgrp);
ret = css_populate_dir(cgroup_css(cgrp, ss), NULL); if (ret)
if (ret) goto out_destroy;
goto out_destroy;
} while_each_subsys_mask();
/* let's create and online css's */ /* let's create and online css's */
kernfs_activate(kn); kernfs_activate(kn);
......
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