aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
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
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')
-rw-r--r--kernel/cgroup.c51
-rw-r--r--kernel/cgroup_freezer.c20
-rw-r--r--kernel/cpuset.c10
-rw-r--r--kernel/events/core.c8
-rw-r--r--kernel/sched/core.c16
5 files changed, 53 insertions, 52 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};
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index ee8bb671688c..75dda1ea5026 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -92,7 +92,7 @@ static const char *freezer_state_strs(unsigned int state)
92 92
93struct cgroup_subsys freezer_subsys; 93struct cgroup_subsys freezer_subsys;
94 94
95static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup) 95static struct cgroup_subsys_state *freezer_css_alloc(struct cgroup *cgroup)
96{ 96{
97 struct freezer *freezer; 97 struct freezer *freezer;
98 98
@@ -105,14 +105,14 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup)
105} 105}
106 106
107/** 107/**
108 * freezer_post_create - commit creation of a freezer cgroup 108 * freezer_css_online - commit creation of a freezer cgroup
109 * @cgroup: cgroup being created 109 * @cgroup: cgroup being created
110 * 110 *
111 * We're committing to creation of @cgroup. Mark it online and inherit 111 * We're committing to creation of @cgroup. Mark it online and inherit
112 * parent's freezing state while holding both parent's and our 112 * parent's freezing state while holding both parent's and our
113 * freezer->lock. 113 * freezer->lock.
114 */ 114 */
115static int freezer_post_create(struct cgroup *cgroup) 115static int freezer_css_online(struct cgroup *cgroup)
116{ 116{
117 struct freezer *freezer = cgroup_freezer(cgroup); 117 struct freezer *freezer = cgroup_freezer(cgroup);
118 struct freezer *parent = parent_freezer(freezer); 118 struct freezer *parent = parent_freezer(freezer);
@@ -141,13 +141,13 @@ static int freezer_post_create(struct cgroup *cgroup)
141} 141}
142 142
143/** 143/**
144 * freezer_pre_destroy - initiate destruction of @cgroup 144 * freezer_css_offline - initiate destruction of @cgroup
145 * @cgroup: cgroup being destroyed 145 * @cgroup: cgroup being destroyed
146 * 146 *
147 * @cgroup is going away. Mark it dead and decrement system_freezing_count 147 * @cgroup is going away. Mark it dead and decrement system_freezing_count
148 * if it was holding one. 148 * if it was holding one.
149 */ 149 */
150static void freezer_pre_destroy(struct cgroup *cgroup) 150static void freezer_css_offline(struct cgroup *cgroup)
151{ 151{
152 struct freezer *freezer = cgroup_freezer(cgroup); 152 struct freezer *freezer = cgroup_freezer(cgroup);
153 153
@@ -161,7 +161,7 @@ static void freezer_pre_destroy(struct cgroup *cgroup)
161 spin_unlock_irq(&freezer->lock); 161 spin_unlock_irq(&freezer->lock);
162} 162}
163 163
164static void freezer_destroy(struct cgroup *cgroup) 164static void freezer_css_free(struct cgroup *cgroup)
165{ 165{
166 kfree(cgroup_freezer(cgroup)); 166 kfree(cgroup_freezer(cgroup));
167} 167}
@@ -477,10 +477,10 @@ static struct cftype files[] = {
477 477
478struct cgroup_subsys freezer_subsys = { 478struct cgroup_subsys freezer_subsys = {
479 .name = "freezer", 479 .name = "freezer",
480 .create = freezer_create, 480 .css_alloc = freezer_css_alloc,
481 .post_create = freezer_post_create, 481 .css_online = freezer_css_online,
482 .pre_destroy = freezer_pre_destroy, 482 .css_offline = freezer_css_offline,
483 .destroy = freezer_destroy, 483 .css_free = freezer_css_free,
484 .subsys_id = freezer_subsys_id, 484 .subsys_id = freezer_subsys_id,
485 .attach = freezer_attach, 485 .attach = freezer_attach,
486 .fork = freezer_fork, 486 .fork = freezer_fork,
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index f33c7153b6d7..06931337c4e5 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1821,11 +1821,11 @@ static void cpuset_post_clone(struct cgroup *cgroup)
1821} 1821}
1822 1822
1823/* 1823/*
1824 * cpuset_create - create a cpuset 1824 * cpuset_css_alloc - allocate a cpuset css
1825 * cont: control group that the new cpuset will be part of 1825 * cont: control group that the new cpuset will be part of
1826 */ 1826 */
1827 1827
1828static struct cgroup_subsys_state *cpuset_create(struct cgroup *cont) 1828static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cont)
1829{ 1829{
1830 struct cpuset *cs; 1830 struct cpuset *cs;
1831 struct cpuset *parent; 1831 struct cpuset *parent;
@@ -1864,7 +1864,7 @@ static struct cgroup_subsys_state *cpuset_create(struct cgroup *cont)
1864 * will call async_rebuild_sched_domains(). 1864 * will call async_rebuild_sched_domains().
1865 */ 1865 */
1866 1866
1867static void cpuset_destroy(struct cgroup *cont) 1867static void cpuset_css_free(struct cgroup *cont)
1868{ 1868{
1869 struct cpuset *cs = cgroup_cs(cont); 1869 struct cpuset *cs = cgroup_cs(cont);
1870 1870
@@ -1878,8 +1878,8 @@ static void cpuset_destroy(struct cgroup *cont)
1878 1878
1879struct cgroup_subsys cpuset_subsys = { 1879struct cgroup_subsys cpuset_subsys = {
1880 .name = "cpuset", 1880 .name = "cpuset",
1881 .create = cpuset_create, 1881 .css_alloc = cpuset_css_alloc,
1882 .destroy = cpuset_destroy, 1882 .css_free = cpuset_css_free,
1883 .can_attach = cpuset_can_attach, 1883 .can_attach = cpuset_can_attach,
1884 .attach = cpuset_attach, 1884 .attach = cpuset_attach,
1885 .post_clone = cpuset_post_clone, 1885 .post_clone = cpuset_post_clone,
diff --git a/kernel/events/core.c b/kernel/events/core.c
index dbccf83c134d..f9ff5493171d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7434,7 +7434,7 @@ unlock:
7434device_initcall(perf_event_sysfs_init); 7434device_initcall(perf_event_sysfs_init);
7435 7435
7436#ifdef CONFIG_CGROUP_PERF 7436#ifdef CONFIG_CGROUP_PERF
7437static struct cgroup_subsys_state *perf_cgroup_create(struct cgroup *cont) 7437static struct cgroup_subsys_state *perf_cgroup_css_alloc(struct cgroup *cont)
7438{ 7438{
7439 struct perf_cgroup *jc; 7439 struct perf_cgroup *jc;
7440 7440
@@ -7451,7 +7451,7 @@ static struct cgroup_subsys_state *perf_cgroup_create(struct cgroup *cont)
7451 return &jc->css; 7451 return &jc->css;
7452} 7452}
7453 7453
7454static void perf_cgroup_destroy(struct cgroup *cont) 7454static void perf_cgroup_css_free(struct cgroup *cont)
7455{ 7455{
7456 struct perf_cgroup *jc; 7456 struct perf_cgroup *jc;
7457 jc = container_of(cgroup_subsys_state(cont, perf_subsys_id), 7457 jc = container_of(cgroup_subsys_state(cont, perf_subsys_id),
@@ -7492,8 +7492,8 @@ static void perf_cgroup_exit(struct cgroup *cgrp, struct cgroup *old_cgrp,
7492struct cgroup_subsys perf_subsys = { 7492struct cgroup_subsys perf_subsys = {
7493 .name = "perf_event", 7493 .name = "perf_event",
7494 .subsys_id = perf_subsys_id, 7494 .subsys_id = perf_subsys_id,
7495 .create = perf_cgroup_create, 7495 .css_alloc = perf_cgroup_css_alloc,
7496 .destroy = perf_cgroup_destroy, 7496 .css_free = perf_cgroup_css_free,
7497 .exit = perf_cgroup_exit, 7497 .exit = perf_cgroup_exit,
7498 .attach = perf_cgroup_attach, 7498 .attach = perf_cgroup_attach,
7499 7499
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2d8927fda712..6f20c8fb2326 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7468,7 +7468,7 @@ static inline struct task_group *cgroup_tg(struct cgroup *cgrp)
7468 struct task_group, css); 7468 struct task_group, css);
7469} 7469}
7470 7470
7471static struct cgroup_subsys_state *cpu_cgroup_create(struct cgroup *cgrp) 7471static struct cgroup_subsys_state *cpu_cgroup_css_alloc(struct cgroup *cgrp)
7472{ 7472{
7473 struct task_group *tg, *parent; 7473 struct task_group *tg, *parent;
7474 7474
@@ -7485,7 +7485,7 @@ static struct cgroup_subsys_state *cpu_cgroup_create(struct cgroup *cgrp)
7485 return &tg->css; 7485 return &tg->css;
7486} 7486}
7487 7487
7488static void cpu_cgroup_destroy(struct cgroup *cgrp) 7488static void cpu_cgroup_css_free(struct cgroup *cgrp)
7489{ 7489{
7490 struct task_group *tg = cgroup_tg(cgrp); 7490 struct task_group *tg = cgroup_tg(cgrp);
7491 7491
@@ -7845,8 +7845,8 @@ static struct cftype cpu_files[] = {
7845 7845
7846struct cgroup_subsys cpu_cgroup_subsys = { 7846struct cgroup_subsys cpu_cgroup_subsys = {
7847 .name = "cpu", 7847 .name = "cpu",
7848 .create = cpu_cgroup_create, 7848 .css_alloc = cpu_cgroup_css_alloc,
7849 .destroy = cpu_cgroup_destroy, 7849 .css_free = cpu_cgroup_css_free,
7850 .can_attach = cpu_cgroup_can_attach, 7850 .can_attach = cpu_cgroup_can_attach,
7851 .attach = cpu_cgroup_attach, 7851 .attach = cpu_cgroup_attach,
7852 .exit = cpu_cgroup_exit, 7852 .exit = cpu_cgroup_exit,
@@ -7869,7 +7869,7 @@ struct cgroup_subsys cpu_cgroup_subsys = {
7869struct cpuacct root_cpuacct; 7869struct cpuacct root_cpuacct;
7870 7870
7871/* create a new cpu accounting group */ 7871/* create a new cpu accounting group */
7872static struct cgroup_subsys_state *cpuacct_create(struct cgroup *cgrp) 7872static struct cgroup_subsys_state *cpuacct_css_alloc(struct cgroup *cgrp)
7873{ 7873{
7874 struct cpuacct *ca; 7874 struct cpuacct *ca;
7875 7875
@@ -7899,7 +7899,7 @@ out:
7899} 7899}
7900 7900
7901/* destroy an existing cpu accounting group */ 7901/* destroy an existing cpu accounting group */
7902static void cpuacct_destroy(struct cgroup *cgrp) 7902static void cpuacct_css_free(struct cgroup *cgrp)
7903{ 7903{
7904 struct cpuacct *ca = cgroup_ca(cgrp); 7904 struct cpuacct *ca = cgroup_ca(cgrp);
7905 7905
@@ -8070,8 +8070,8 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
8070 8070
8071struct cgroup_subsys cpuacct_subsys = { 8071struct cgroup_subsys cpuacct_subsys = {
8072 .name = "cpuacct", 8072 .name = "cpuacct",
8073 .create = cpuacct_create, 8073 .css_alloc = cpuacct_css_alloc,
8074 .destroy = cpuacct_destroy, 8074 .css_free = cpuacct_css_free,
8075 .subsys_id = cpuacct_subsys_id, 8075 .subsys_id = cpuacct_subsys_id,
8076 .base_cftypes = files, 8076 .base_cftypes = files,
8077}; 8077};