aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-13 11:01:55 -0400
committerTejun Heo <tj@kernel.org>2013-08-13 11:01:55 -0400
commit623f926b050e12b0f5e3a2f4d11c36e4ddd63541 (patch)
treeda5df0064e57432decbe0bf93d01fde2fe013c40
parent73e80ed8007fc48a6deeb295ba37159fad274bd2 (diff)
cgroup: reorganize css init / exit paths
css (cgroup_subsys_state) lifetime management is about to be restructured. In prepartion, make the following mostly trivial changes. * init_cgroup_css() is renamed to init_css() so that it's consistent with other css handling functions. * alloc_css_id(), online_css() and offline_css() updated to take @css instead of cgroups and subsys IDs. This patch doesn't make any functional changes. v2: v1 merged two for_each_root_subsys() loops in cgroup_create() but Li Zefan pointed out that it breaks error path. Dropped. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r--kernel/cgroup.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c27101622567..a1ebc445f350 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -838,8 +838,7 @@ static struct backing_dev_info cgroup_backing_dev_info = {
838 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, 838 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
839}; 839};
840 840
841static int alloc_css_id(struct cgroup_subsys *ss, 841static int alloc_css_id(struct cgroup_subsys_state *child_css);
842 struct cgroup *parent, struct cgroup *child);
843 842
844static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb) 843static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
845{ 844{
@@ -4308,9 +4307,8 @@ static void css_release(struct percpu_ref *ref)
4308 schedule_work(&css->destroy_work); 4307 schedule_work(&css->destroy_work);
4309} 4308}
4310 4309
4311static void init_cgroup_css(struct cgroup_subsys_state *css, 4310static void init_css(struct cgroup_subsys_state *css, struct cgroup_subsys *ss,
4312 struct cgroup_subsys *ss, 4311 struct cgroup *cgrp)
4313 struct cgroup *cgrp)
4314{ 4312{
4315 css->cgroup = cgrp; 4313 css->cgroup = cgrp;
4316 css->ss = ss; 4314 css->ss = ss;
@@ -4327,9 +4325,9 @@ static void init_cgroup_css(struct cgroup_subsys_state *css,
4327} 4325}
4328 4326
4329/* invoke ->css_online() on a new CSS and mark it online if successful */ 4327/* invoke ->css_online() on a new CSS and mark it online if successful */
4330static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp) 4328static int online_css(struct cgroup_subsys_state *css)
4331{ 4329{
4332 struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); 4330 struct cgroup_subsys *ss = css->ss;
4333 int ret = 0; 4331 int ret = 0;
4334 4332
4335 lockdep_assert_held(&cgroup_mutex); 4333 lockdep_assert_held(&cgroup_mutex);
@@ -4342,9 +4340,9 @@ static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp)
4342} 4340}
4343 4341
4344/* if the CSS is online, invoke ->css_offline() on it and mark it offline */ 4342/* if the CSS is online, invoke ->css_offline() on it and mark it offline */
4345static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp) 4343static void offline_css(struct cgroup_subsys_state *css)
4346{ 4344{
4347 struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); 4345 struct cgroup_subsys *ss = css->ss;
4348 4346
4349 lockdep_assert_held(&cgroup_mutex); 4347 lockdep_assert_held(&cgroup_mutex);
4350 4348
@@ -4442,10 +4440,10 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4442 goto err_free_all; 4440 goto err_free_all;
4443 } 4441 }
4444 4442
4445 init_cgroup_css(css, ss, cgrp); 4443 init_css(css, ss, cgrp);
4446 4444
4447 if (ss->use_id) { 4445 if (ss->use_id) {
4448 err = alloc_css_id(ss, parent, cgrp); 4446 err = alloc_css_id(css);
4449 if (err) 4447 if (err)
4450 goto err_free_all; 4448 goto err_free_all;
4451 } 4449 }
@@ -4480,7 +4478,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4480 4478
4481 /* creation succeeded, notify subsystems */ 4479 /* creation succeeded, notify subsystems */
4482 for_each_root_subsys(root, ss) { 4480 for_each_root_subsys(root, ss) {
4483 err = online_css(ss, cgrp); 4481 struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id);
4482
4483 err = online_css(css);
4484 if (err) 4484 if (err)
4485 goto err_destroy; 4485 goto err_destroy;
4486 4486
@@ -4700,7 +4700,7 @@ static void cgroup_offline_fn(struct work_struct *work)
4700 * initate destruction. 4700 * initate destruction.
4701 */ 4701 */
4702 for_each_root_subsys(cgrp->root, ss) 4702 for_each_root_subsys(cgrp->root, ss)
4703 offline_css(ss, cgrp); 4703 offline_css(cgroup_css(cgrp, ss->subsys_id));
4704 4704
4705 /* 4705 /*
4706 * Put the css refs from cgroup_destroy_locked(). Each css holds 4706 * Put the css refs from cgroup_destroy_locked(). Each css holds
@@ -4778,7 +4778,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
4778 css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss->subsys_id)); 4778 css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss->subsys_id));
4779 /* We don't handle early failures gracefully */ 4779 /* We don't handle early failures gracefully */
4780 BUG_ON(IS_ERR(css)); 4780 BUG_ON(IS_ERR(css));
4781 init_cgroup_css(css, ss, cgroup_dummy_top); 4781 init_css(css, ss, cgroup_dummy_top);
4782 4782
4783 /* Update the init_css_set to contain a subsys 4783 /* Update the init_css_set to contain a subsys
4784 * pointer to this state - since the subsystem is 4784 * pointer to this state - since the subsystem is
@@ -4793,7 +4793,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
4793 * need to invoke fork callbacks here. */ 4793 * need to invoke fork callbacks here. */
4794 BUG_ON(!list_empty(&init_task.tasks)); 4794 BUG_ON(!list_empty(&init_task.tasks));
4795 4795
4796 BUG_ON(online_css(ss, cgroup_dummy_top)); 4796 BUG_ON(online_css(cgroup_css(cgroup_dummy_top, ss->subsys_id)));
4797 4797
4798 mutex_unlock(&cgroup_mutex); 4798 mutex_unlock(&cgroup_mutex);
4799 4799
@@ -4866,8 +4866,8 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
4866 ss->root = &cgroup_dummy_root; 4866 ss->root = &cgroup_dummy_root;
4867 4867
4868 /* our new subsystem will be attached to the dummy hierarchy. */ 4868 /* our new subsystem will be attached to the dummy hierarchy. */
4869 init_cgroup_css(css, ss, cgroup_dummy_top); 4869 init_css(css, ss, cgroup_dummy_top);
4870 /* init_idr must be after init_cgroup_css because it sets css->id. */ 4870 /* init_idr must be after init_css() because it sets css->id. */
4871 if (ss->use_id) { 4871 if (ss->use_id) {
4872 ret = cgroup_init_idr(ss, css); 4872 ret = cgroup_init_idr(ss, css);
4873 if (ret) 4873 if (ret)
@@ -4897,7 +4897,7 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
4897 } 4897 }
4898 write_unlock(&css_set_lock); 4898 write_unlock(&css_set_lock);
4899 4899
4900 ret = online_css(ss, cgroup_dummy_top); 4900 ret = online_css(cgroup_css(cgroup_dummy_top, ss->subsys_id));
4901 if (ret) 4901 if (ret)
4902 goto err_unload; 4902 goto err_unload;
4903 4903
@@ -4936,7 +4936,7 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
4936 4936
4937 mutex_lock(&cgroup_mutex); 4937 mutex_lock(&cgroup_mutex);
4938 4938
4939 offline_css(ss, cgroup_dummy_top); 4939 offline_css(cgroup_css(cgroup_dummy_top, ss->subsys_id));
4940 4940
4941 if (ss->use_id) 4941 if (ss->use_id)
4942 idr_destroy(&ss->idr); 4942 idr_destroy(&ss->idr);
@@ -5588,20 +5588,16 @@ static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss,
5588 return 0; 5588 return 0;
5589} 5589}
5590 5590
5591static int alloc_css_id(struct cgroup_subsys *ss, struct cgroup *parent, 5591static int alloc_css_id(struct cgroup_subsys_state *child_css)
5592 struct cgroup *child)
5593{ 5592{
5594 int subsys_id, i, depth = 0; 5593 struct cgroup_subsys_state *parent_css = css_parent(child_css);
5595 struct cgroup_subsys_state *parent_css, *child_css;
5596 struct css_id *child_id, *parent_id; 5594 struct css_id *child_id, *parent_id;
5595 int i, depth;
5597 5596
5598 subsys_id = ss->subsys_id;
5599 parent_css = cgroup_css(parent, subsys_id);
5600 child_css = cgroup_css(child, subsys_id);
5601 parent_id = rcu_dereference_protected(parent_css->id, true); 5597 parent_id = rcu_dereference_protected(parent_css->id, true);
5602 depth = parent_id->depth + 1; 5598 depth = parent_id->depth + 1;
5603 5599
5604 child_id = get_new_cssid(ss, depth); 5600 child_id = get_new_cssid(child_css->ss, depth);
5605 if (IS_ERR(child_id)) 5601 if (IS_ERR(child_id))
5606 return PTR_ERR(child_id); 5602 return PTR_ERR(child_id);
5607 5603