aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-11-19 11:13:38 -0500
committerTejun Heo <tj@kernel.org>2012-11-19 11:13:38 -0500
commit92fb97487a7e41b222c1417cabd1d1ab7cc3a48c (patch)
treec220c622b9ac9b16535535d448e9cd29be72c77e /kernel/cgroup.c
parentb1929db42f8a649d9a9e397119f628c27fd4021f (diff)
cgroup: rename ->create/post_create/pre_destroy/destroy() to ->css_alloc/online/offline/free()
Rename cgroup_subsys css lifetime related callbacks to better describe what their roles are. Also, update documentation. 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.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c389f4258681..d35463bab487 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -876,7 +876,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
876 * Release the subsystem state objects. 876 * Release the subsystem state objects.
877 */ 877 */
878 for_each_subsys(cgrp->root, ss) 878 for_each_subsys(cgrp->root, ss)
879 ss->destroy(cgrp); 879 ss->css_free(cgrp);
880 880
881 cgrp->root->number_of_cgroups--; 881 cgrp->root->number_of_cgroups--;
882 mutex_unlock(&cgroup_mutex); 882 mutex_unlock(&cgroup_mutex);
@@ -4048,8 +4048,8 @@ static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp)
4048 4048
4049 lockdep_assert_held(&cgroup_mutex); 4049 lockdep_assert_held(&cgroup_mutex);
4050 4050
4051 if (ss->post_create) 4051 if (ss->css_online)
4052 ret = ss->post_create(cgrp); 4052 ret = ss->css_online(cgrp);
4053 if (!ret) 4053 if (!ret)
4054 cgrp->subsys[ss->subsys_id]->flags |= CSS_ONLINE; 4054 cgrp->subsys[ss->subsys_id]->flags |= CSS_ONLINE;
4055 return ret; 4055 return ret;
@@ -4067,14 +4067,14 @@ static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp)
4067 return; 4067 return;
4068 4068
4069 /* 4069 /*
4070 * pre_destroy() should be called with cgroup_mutex unlocked. See 4070 * css_offline() should be called with cgroup_mutex unlocked. See
4071 * 3fa59dfbc3 ("cgroup: fix potential deadlock in pre_destroy") for 4071 * 3fa59dfbc3 ("cgroup: fix potential deadlock in pre_destroy") for
4072 * details. This temporary unlocking should go away once 4072 * details. This temporary unlocking should go away once
4073 * cgroup_mutex is unexported from controllers. 4073 * cgroup_mutex is unexported from controllers.
4074 */ 4074 */
4075 if (ss->pre_destroy) { 4075 if (ss->css_offline) {
4076 mutex_unlock(&cgroup_mutex); 4076 mutex_unlock(&cgroup_mutex);
4077 ss->pre_destroy(cgrp); 4077 ss->css_offline(cgrp);
4078 mutex_lock(&cgroup_mutex); 4078 mutex_lock(&cgroup_mutex);
4079 } 4079 }
4080 4080
@@ -4136,7 +4136,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4136 for_each_subsys(root, ss) { 4136 for_each_subsys(root, ss) {
4137 struct cgroup_subsys_state *css; 4137 struct cgroup_subsys_state *css;
4138 4138
4139 css = ss->create(cgrp); 4139 css = ss->css_alloc(cgrp);
4140 if (IS_ERR(css)) { 4140 if (IS_ERR(css)) {
4141 err = PTR_ERR(css); 4141 err = PTR_ERR(css);
4142 goto err_free_all; 4142 goto err_free_all;
@@ -4147,7 +4147,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4147 if (err) 4147 if (err)
4148 goto err_free_all; 4148 goto err_free_all;
4149 } 4149 }
4150 /* At error, ->destroy() callback has to free assigned ID. */ 4150 /* At error, ->css_free() callback has to free assigned ID. */
4151 if (clone_children(parent) && ss->post_clone) 4151 if (clone_children(parent) && ss->post_clone)
4152 ss->post_clone(cgrp); 4152 ss->post_clone(cgrp);
4153 4153
@@ -4201,7 +4201,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4201err_free_all: 4201err_free_all:
4202 for_each_subsys(root, ss) { 4202 for_each_subsys(root, ss) {
4203 if (cgrp->subsys[ss->subsys_id]) 4203 if (cgrp->subsys[ss->subsys_id])
4204 ss->destroy(cgrp); 4204 ss->css_free(cgrp);
4205 } 4205 }
4206 mutex_unlock(&cgroup_mutex); 4206 mutex_unlock(&cgroup_mutex);
4207 /* Release the reference count that we took on the superblock */ 4207 /* Release the reference count that we took on the superblock */
@@ -4381,7 +4381,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
4381 /* Create the top cgroup state for this subsystem */ 4381 /* Create the top cgroup state for this subsystem */
4382 list_add(&ss->sibling, &rootnode.subsys_list); 4382 list_add(&ss->sibling, &rootnode.subsys_list);
4383 ss->root = &rootnode; 4383 ss->root = &rootnode;
4384 css = ss->create(dummytop); 4384 css = ss->css_alloc(dummytop);
4385 /* We don't handle early failures gracefully */ 4385 /* We don't handle early failures gracefully */
4386 BUG_ON(IS_ERR(css)); 4386 BUG_ON(IS_ERR(css));
4387 init_cgroup_css(css, ss, dummytop); 4387 init_cgroup_css(css, ss, dummytop);
@@ -4425,7 +4425,7 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
4425 4425
4426 /* check name and function validity */ 4426 /* check name and function validity */
4427 if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN || 4427 if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN ||
4428 ss->create == NULL || ss->destroy == NULL) 4428 ss->css_alloc == NULL || ss->css_free == NULL)
4429 return -EINVAL; 4429 return -EINVAL;
4430 4430
4431 /* 4431 /*
@@ -4454,10 +4454,11 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
4454 subsys[ss->subsys_id] = ss; 4454 subsys[ss->subsys_id] = ss;
4455 4455
4456 /* 4456 /*
4457 * no ss->create seems to need anything important in the ss struct, so 4457 * no ss->css_alloc seems to need anything important in the ss
4458 * this can happen first (i.e. before the rootnode attachment). 4458 * struct, so this can happen first (i.e. before the rootnode
4459 * attachment).
4459 */ 4460 */
4460 css = ss->create(dummytop); 4461 css = ss->css_alloc(dummytop);
4461 if (IS_ERR(css)) { 4462 if (IS_ERR(css)) {
4462 /* failure case - need to deassign the subsys[] slot. */ 4463 /* failure case - need to deassign the subsys[] slot. */
4463 subsys[ss->subsys_id] = NULL; 4464 subsys[ss->subsys_id] = NULL;
@@ -4577,12 +4578,12 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
4577 write_unlock(&css_set_lock); 4578 write_unlock(&css_set_lock);
4578 4579
4579 /* 4580 /*
4580 * remove subsystem's css from the dummytop and free it - need to free 4581 * remove subsystem's css from the dummytop and free it - need to
4581 * before marking as null because ss->destroy needs the cgrp->subsys 4582 * free before marking as null because ss->css_free needs the
4582 * pointer to find their state. note that this also takes care of 4583 * cgrp->subsys pointer to find their state. note that this also
4583 * freeing the css_id. 4584 * takes care of freeing the css_id.
4584 */ 4585 */
4585 ss->destroy(dummytop); 4586 ss->css_free(dummytop);
4586 dummytop->subsys[ss->subsys_id] = NULL; 4587 dummytop->subsys[ss->subsys_id] = NULL;
4587 4588
4588 mutex_unlock(&cgroup_mutex); 4589 mutex_unlock(&cgroup_mutex);
@@ -4626,8 +4627,8 @@ int __init cgroup_init_early(void)
4626 4627
4627 BUG_ON(!ss->name); 4628 BUG_ON(!ss->name);
4628 BUG_ON(strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN); 4629 BUG_ON(strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN);
4629 BUG_ON(!ss->create); 4630 BUG_ON(!ss->css_alloc);
4630 BUG_ON(!ss->destroy); 4631 BUG_ON(!ss->css_free);
4631 if (ss->subsys_id != i) { 4632 if (ss->subsys_id != i) {
4632 printk(KERN_ERR "cgroup: Subsys %s id == %d\n", 4633 printk(KERN_ERR "cgroup: Subsys %s id == %d\n",
4633 ss->name, ss->subsys_id); 4634 ss->name, ss->subsys_id);
@@ -5439,7 +5440,7 @@ struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id)
5439} 5440}
5440 5441
5441#ifdef CONFIG_CGROUP_DEBUG 5442#ifdef CONFIG_CGROUP_DEBUG
5442static struct cgroup_subsys_state *debug_create(struct cgroup *cont) 5443static struct cgroup_subsys_state *debug_css_alloc(struct cgroup *cont)
5443{ 5444{
5444 struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL); 5445 struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL);
5445 5446
@@ -5449,7 +5450,7 @@ static struct cgroup_subsys_state *debug_create(struct cgroup *cont)
5449 return css; 5450 return css;
5450} 5451}
5451 5452
5452static void debug_destroy(struct cgroup *cont) 5453static void debug_css_free(struct cgroup *cont)
5453{ 5454{
5454 kfree(cont->subsys[debug_subsys_id]); 5455 kfree(cont->subsys[debug_subsys_id]);
5455} 5456}
@@ -5578,8 +5579,8 @@ static struct cftype debug_files[] = {
5578 5579
5579struct cgroup_subsys debug_subsys = { 5580struct cgroup_subsys debug_subsys = {
5580 .name = "debug", 5581 .name = "debug",
5581 .create = debug_create, 5582 .css_alloc = debug_css_alloc,
5582 .destroy = debug_destroy, 5583 .css_free = debug_css_free,
5583 .subsys_id = debug_subsys_id, 5584 .subsys_id = debug_subsys_id,
5584 .base_cftypes = debug_files, 5585 .base_cftypes = debug_files,
5585}; 5586};