Commit b3bfd983 authored by Tejun Heo's avatar Tejun Heo

cgroup: collapse cgroup_create() into croup_mkdir()

cgroup_mkdir() is the sole user of cgroup_create().  Let's collapse
the latter into the former.  This will help simplifying locking.
While at it, remove now stale comment about inode locking.

This patch doesn't introduce any functional changes.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
parent ba0f4d76
...@@ -4235,30 +4235,24 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss) ...@@ -4235,30 +4235,24 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
return err; return err;
} }
/** static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
* cgroup_create - create a cgroup umode_t mode)
* @parent: cgroup that will be parent of the new cgroup
* @name: name of the new cgroup
* @mode: mode to set on new cgroup
*/
static long cgroup_create(struct cgroup *parent, const char *name,
umode_t mode)
{ {
struct cgroup *cgrp; struct cgroup *parent = parent_kn->priv, *cgrp;
struct cgroup_root *root = parent->root; struct cgroup_root *root = parent->root;
int ssid, ret;
struct cgroup_subsys *ss; struct cgroup_subsys *ss;
struct kernfs_node *kn; struct kernfs_node *kn;
int ssid, ret;
mutex_lock(&cgroup_tree_mutex);
/* /*
* Only live parents can have children. Note that the liveliness * cgroup_mkdir() grabs cgroup_tree_mutex which nests outside
* check isn't strictly necessary because cgroup_mkdir() and * kernfs active_ref and cgroup_create() already synchronizes
* cgroup_rmdir() are fully synchronized by i_mutex; however, do it * properly against removal through cgroup_lock_live_group().
* anyway so that locking is contained inside cgroup proper and we * Break it before calling cgroup_create().
* don't get nasty surprises if we ever grow another caller.
*/ */
cgroup_get(parent);
kernfs_break_active_protection(parent_kn);
mutex_lock(&cgroup_tree_mutex);
if (!cgroup_lock_live_group(parent)) { if (!cgroup_lock_live_group(parent)) {
ret = -ENODEV; ret = -ENODEV;
goto out_unlock_tree; goto out_unlock_tree;
...@@ -4357,6 +4351,8 @@ static long cgroup_create(struct cgroup *parent, const char *name, ...@@ -4357,6 +4351,8 @@ static long cgroup_create(struct cgroup *parent, const char *name,
mutex_unlock(&cgroup_mutex); mutex_unlock(&cgroup_mutex);
out_unlock_tree: out_unlock_tree:
mutex_unlock(&cgroup_tree_mutex); mutex_unlock(&cgroup_tree_mutex);
kernfs_unbreak_active_protection(parent_kn);
cgroup_put(parent);
return ret; return ret;
out_destroy: out_destroy:
...@@ -4364,28 +4360,6 @@ static long cgroup_create(struct cgroup *parent, const char *name, ...@@ -4364,28 +4360,6 @@ static long cgroup_create(struct cgroup *parent, const char *name,
goto out_unlock; goto out_unlock;
} }
static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
umode_t mode)
{
struct cgroup *parent = parent_kn->priv;
int ret;
/*
* cgroup_create() grabs cgroup_tree_mutex which nests outside
* kernfs active_ref and cgroup_create() already synchronizes
* properly against removal through cgroup_lock_live_group().
* Break it before calling cgroup_create().
*/
cgroup_get(parent);
kernfs_break_active_protection(parent_kn);
ret = cgroup_create(parent, name, mode);
kernfs_unbreak_active_protection(parent_kn);
cgroup_put(parent);
return ret;
}
/* /*
* This is called when the refcnt of a css is confirmed to be killed. * This is called when the refcnt of a css is confirmed to be killed.
* css_tryget_online() is now guaranteed to fail. * css_tryget_online() is now guaranteed to fail.
......
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