summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-12-06 15:11:56 -0500
committerTejun Heo <tj@kernel.org>2013-12-06 15:11:56 -0500
commitc81c925ad9b0460a14ec35b52c61158da0733d51 (patch)
tree4dfa8b6cb6b16cc900cfc218e5a46989fe11a758 /kernel/cgroup.c
parent9d403e99238ed6d7151a2c07db6cf8f6932ef3d5 (diff)
downloadlinux-c81c925ad9b0460a14ec35b52c61158da0733d51.tar.gz
linux-c81c925ad9b0460a14ec35b52c61158da0733d51.tar.bz2
linux-c81c925ad9b0460a14ec35b52c61158da0733d51.zip
cgroup: factor out cgroup_subsys_state creation into create_css()
Now that all opertations to create a css (cgroup_subsys_state) are collected into a single loop in cgroup_create(), it's easy to factor it out into its own function. Factor out css creation into create_css(). This makes the code easier to follow and will enable decoupling css creation from cgroup creation which is necessary for the planned unified hierarchy. 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.c95
1 files changed, 57 insertions, 38 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 39e2295466ec..d12c29f42feb 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4073,6 +4073,62 @@ static void offline_css(struct cgroup_subsys_state *css)
RCU_INIT_POINTER(css->cgroup->subsys[ss->subsys_id], css);
}
+/**
+ * create_css - create a cgroup_subsys_state
+ * @cgrp: the cgroup new css will be associated with
+ * @ss: the subsys of new css
+ *
+ * Create a new css associated with @cgrp - @ss pair. On success, the new
+ * css is online and installed in @cgrp with all interface files created.
+ * Returns 0 on success, -errno on failure.
+ */
+static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
+{
+ struct cgroup *parent = cgrp->parent;
+ struct cgroup_subsys_state *css;
+ int err;
+
+ lockdep_assert_held(&cgrp->dentry->d_inode->i_mutex);
+ lockdep_assert_held(&cgroup_mutex);
+
+ css = ss->css_alloc(cgroup_css(parent, ss));
+ if (IS_ERR(css))
+ return PTR_ERR(css);
+
+ err = percpu_ref_init(&css->refcnt, css_release);
+ if (err)
+ goto err_free;
+
+ init_css(css, ss, cgrp);
+
+ err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id);
+ if (err)
+ goto err_free;
+
+ err = online_css(css);
+ if (err)
+ goto err_free;
+
+ dget(cgrp->dentry);
+ css_get(css->parent);
+
+ if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
+ parent->parent) {
+ pr_warning("cgroup: %s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n",
+ current->comm, current->pid, ss->name);
+ if (!strcmp(ss->name, "memory"))
+ pr_warning("cgroup: \"memory\" requires setting use_hierarchy to 1 on the root.\n");
+ ss->warned_broken_hierarchy = true;
+ }
+
+ return 0;
+
+err_free:
+ percpu_ref_cancel_init(&css->refcnt);
+ ss->css_free(css);
+ return err;
+}
+
/*
* cgroup_create - create a cgroup
* @parent: cgroup that will be parent of the new cgroup
@@ -4084,7 +4140,6 @@ static void offline_css(struct cgroup_subsys_state *css)
static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
umode_t mode)
{
- struct cgroup_subsys_state *css = NULL;
struct cgroup *cgrp;
struct cgroup_name *name;
struct cgroupfs_root *root = parent->root;
@@ -4175,41 +4230,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
/* let's create and online css's */
for_each_root_subsys(root, ss) {
- css = ss->css_alloc(cgroup_css(parent, ss));
- if (IS_ERR(css)) {
- err = PTR_ERR(css);
- css = NULL;
- goto err_destroy;
- }
-
- err = percpu_ref_init(&css->refcnt, css_release);
+ err = create_css(cgrp, ss);
if (err)
goto err_destroy;
-
- init_css(css, ss, cgrp);
-
- err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id);
- if (err)
- goto err_destroy;
-
- err = online_css(css);
- if (err)
- goto err_destroy;
-
- dget(dentry);
- css_get(css->parent);
-
- /* mark it consumed for error path */
- css = NULL;
-
- if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
- parent->parent) {
- pr_warning("cgroup: %s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n",
- current->comm, current->pid, ss->name);
- if (!strcmp(ss->name, "memory"))
- pr_warning("cgroup: \"memory\" requires setting use_hierarchy to 1 on the root.\n");
- ss->warned_broken_hierarchy = true;
- }
}
mutex_unlock(&cgroup_mutex);
@@ -4230,10 +4253,6 @@ err_free_cgrp:
return err;
err_destroy:
- if (css) {
- percpu_ref_cancel_init(&css->refcnt);
- css->ss->css_free(css);
- }
cgroup_destroy_locked(cgrp);
mutex_unlock(&cgroup_mutex);
mutex_unlock(&dentry->d_inode->i_mutex);