diff options
author | Tejun Heo <tj@kernel.org> | 2013-12-06 15:11:56 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-12-06 15:11:56 -0500 |
commit | c81c925ad9b0460a14ec35b52c61158da0733d51 (patch) | |
tree | 4dfa8b6cb6b16cc900cfc218e5a46989fe11a758 | |
parent | 9d403e99238ed6d7151a2c07db6cf8f6932ef3d5 (diff) |
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>
-rw-r--r-- | kernel/cgroup.c | 95 |
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) | |||
4073 | RCU_INIT_POINTER(css->cgroup->subsys[ss->subsys_id], css); | 4073 | RCU_INIT_POINTER(css->cgroup->subsys[ss->subsys_id], css); |
4074 | } | 4074 | } |
4075 | 4075 | ||
4076 | /** | ||
4077 | * create_css - create a cgroup_subsys_state | ||
4078 | * @cgrp: the cgroup new css will be associated with | ||
4079 | * @ss: the subsys of new css | ||
4080 | * | ||
4081 | * Create a new css associated with @cgrp - @ss pair. On success, the new | ||
4082 | * css is online and installed in @cgrp with all interface files created. | ||
4083 | * Returns 0 on success, -errno on failure. | ||
4084 | */ | ||
4085 | static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss) | ||
4086 | { | ||
4087 | struct cgroup *parent = cgrp->parent; | ||
4088 | struct cgroup_subsys_state *css; | ||
4089 | int err; | ||
4090 | |||
4091 | lockdep_assert_held(&cgrp->dentry->d_inode->i_mutex); | ||
4092 | lockdep_assert_held(&cgroup_mutex); | ||
4093 | |||
4094 | css = ss->css_alloc(cgroup_css(parent, ss)); | ||
4095 | if (IS_ERR(css)) | ||
4096 | return PTR_ERR(css); | ||
4097 | |||
4098 | err = percpu_ref_init(&css->refcnt, css_release); | ||
4099 | if (err) | ||
4100 | goto err_free; | ||
4101 | |||
4102 | init_css(css, ss, cgrp); | ||
4103 | |||
4104 | err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id); | ||
4105 | if (err) | ||
4106 | goto err_free; | ||
4107 | |||
4108 | err = online_css(css); | ||
4109 | if (err) | ||
4110 | goto err_free; | ||
4111 | |||
4112 | dget(cgrp->dentry); | ||
4113 | css_get(css->parent); | ||
4114 | |||
4115 | if (ss->broken_hierarchy && !ss->warned_broken_hierarchy && | ||
4116 | parent->parent) { | ||
4117 | 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", | ||
4118 | current->comm, current->pid, ss->name); | ||
4119 | if (!strcmp(ss->name, "memory")) | ||
4120 | pr_warning("cgroup: \"memory\" requires setting use_hierarchy to 1 on the root.\n"); | ||
4121 | ss->warned_broken_hierarchy = true; | ||
4122 | } | ||
4123 | |||
4124 | return 0; | ||
4125 | |||
4126 | err_free: | ||
4127 | percpu_ref_cancel_init(&css->refcnt); | ||
4128 | ss->css_free(css); | ||
4129 | return err; | ||
4130 | } | ||
4131 | |||
4076 | /* | 4132 | /* |
4077 | * cgroup_create - create a cgroup | 4133 | * cgroup_create - create a cgroup |
4078 | * @parent: cgroup that will be parent of the new cgroup | 4134 | * @parent: cgroup that will be parent of the new cgroup |
@@ -4084,7 +4140,6 @@ static void offline_css(struct cgroup_subsys_state *css) | |||
4084 | static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | 4140 | static long cgroup_create(struct cgroup *parent, struct dentry *dentry, |
4085 | umode_t mode) | 4141 | umode_t mode) |
4086 | { | 4142 | { |
4087 | struct cgroup_subsys_state *css = NULL; | ||
4088 | struct cgroup *cgrp; | 4143 | struct cgroup *cgrp; |
4089 | struct cgroup_name *name; | 4144 | struct cgroup_name *name; |
4090 | struct cgroupfs_root *root = parent->root; | 4145 | struct cgroupfs_root *root = parent->root; |
@@ -4175,41 +4230,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4175 | 4230 | ||
4176 | /* let's create and online css's */ | 4231 | /* let's create and online css's */ |
4177 | for_each_root_subsys(root, ss) { | 4232 | for_each_root_subsys(root, ss) { |
4178 | css = ss->css_alloc(cgroup_css(parent, ss)); | 4233 | err = create_css(cgrp, ss); |
4179 | if (IS_ERR(css)) { | ||
4180 | err = PTR_ERR(css); | ||
4181 | css = NULL; | ||
4182 | goto err_destroy; | ||
4183 | } | ||
4184 | |||
4185 | err = percpu_ref_init(&css->refcnt, css_release); | ||
4186 | if (err) | 4234 | if (err) |
4187 | goto err_destroy; | 4235 | goto err_destroy; |
4188 | |||
4189 | init_css(css, ss, cgrp); | ||
4190 | |||
4191 | err = cgroup_populate_dir(cgrp, 1 << ss->subsys_id); | ||
4192 | if (err) | ||
4193 | goto err_destroy; | ||
4194 | |||
4195 | err = online_css(css); | ||
4196 | if (err) | ||
4197 | goto err_destroy; | ||
4198 | |||
4199 | dget(dentry); | ||
4200 | css_get(css->parent); | ||
4201 | |||
4202 | /* mark it consumed for error path */ | ||
4203 | css = NULL; | ||
4204 | |||
4205 | if (ss->broken_hierarchy && !ss->warned_broken_hierarchy && | ||
4206 | parent->parent) { | ||
4207 | 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", | ||
4208 | current->comm, current->pid, ss->name); | ||
4209 | if (!strcmp(ss->name, "memory")) | ||
4210 | pr_warning("cgroup: \"memory\" requires setting use_hierarchy to 1 on the root.\n"); | ||
4211 | ss->warned_broken_hierarchy = true; | ||
4212 | } | ||
4213 | } | 4236 | } |
4214 | 4237 | ||
4215 | mutex_unlock(&cgroup_mutex); | 4238 | mutex_unlock(&cgroup_mutex); |
@@ -4230,10 +4253,6 @@ err_free_cgrp: | |||
4230 | return err; | 4253 | return err; |
4231 | 4254 | ||
4232 | err_destroy: | 4255 | err_destroy: |
4233 | if (css) { | ||
4234 | percpu_ref_cancel_init(&css->refcnt); | ||
4235 | css->ss->css_free(css); | ||
4236 | } | ||
4237 | cgroup_destroy_locked(cgrp); | 4256 | cgroup_destroy_locked(cgrp); |
4238 | mutex_unlock(&cgroup_mutex); | 4257 | mutex_unlock(&cgroup_mutex); |
4239 | mutex_unlock(&dentry->d_inode->i_mutex); | 4258 | mutex_unlock(&dentry->d_inode->i_mutex); |