diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-13 11:01:53 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-13 11:01:53 -0400 |
commit | 40e93b39cd5b6a347333a95152ce37deef37bbd0 (patch) | |
tree | 6789f2b7310d828496358ccdac93b68d2abda415 | |
parent | bd8815a6d802fc16a7a106e170593aa05dc17e72 (diff) |
cgroup: always use cgroup_css()
cgroup_css() is the accessor for cgroup->subsys[] but is not used
consistently. cgroup->subsys[] will become RCU protected and
cgroup_css() will grow synchronization sanity checks. In preparation,
make all cgroup->subsys[] dereferences use cgroup_css() consistently.
This patch doesn't introduce any functional difference.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r-- | kernel/cgroup.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 52f0498db946..49ad96ee08e1 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -574,7 +574,7 @@ static struct css_set *find_existing_css_set(struct css_set *old_cset, | |||
574 | /* Subsystem is in this hierarchy. So we want | 574 | /* Subsystem is in this hierarchy. So we want |
575 | * the subsystem state from the new | 575 | * the subsystem state from the new |
576 | * cgroup */ | 576 | * cgroup */ |
577 | template[i] = cgrp->subsys[i]; | 577 | template[i] = cgroup_css(cgrp, i); |
578 | } else { | 578 | } else { |
579 | /* Subsystem is not in this hierarchy, so we | 579 | /* Subsystem is not in this hierarchy, so we |
580 | * don't want to change the subsystem state */ | 580 | * don't want to change the subsystem state */ |
@@ -871,7 +871,7 @@ static void cgroup_free_fn(struct work_struct *work) | |||
871 | * Release the subsystem state objects. | 871 | * Release the subsystem state objects. |
872 | */ | 872 | */ |
873 | for_each_root_subsys(cgrp->root, ss) { | 873 | for_each_root_subsys(cgrp->root, ss) { |
874 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 874 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
875 | 875 | ||
876 | ss->css_free(css); | 876 | ss->css_free(css); |
877 | } | 877 | } |
@@ -1067,27 +1067,27 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
1067 | 1067 | ||
1068 | if (bit & added_mask) { | 1068 | if (bit & added_mask) { |
1069 | /* We're binding this subsystem to this hierarchy */ | 1069 | /* We're binding this subsystem to this hierarchy */ |
1070 | BUG_ON(cgrp->subsys[i]); | 1070 | BUG_ON(cgroup_css(cgrp, i)); |
1071 | BUG_ON(!cgroup_dummy_top->subsys[i]); | 1071 | BUG_ON(!cgroup_css(cgroup_dummy_top, i)); |
1072 | BUG_ON(cgroup_dummy_top->subsys[i]->cgroup != cgroup_dummy_top); | 1072 | BUG_ON(cgroup_css(cgroup_dummy_top, i)->cgroup != cgroup_dummy_top); |
1073 | 1073 | ||
1074 | cgrp->subsys[i] = cgroup_dummy_top->subsys[i]; | 1074 | cgrp->subsys[i] = cgroup_dummy_top->subsys[i]; |
1075 | cgrp->subsys[i]->cgroup = cgrp; | 1075 | cgroup_css(cgrp, i)->cgroup = cgrp; |
1076 | list_move(&ss->sibling, &root->subsys_list); | 1076 | list_move(&ss->sibling, &root->subsys_list); |
1077 | ss->root = root; | 1077 | ss->root = root; |
1078 | if (ss->bind) | 1078 | if (ss->bind) |
1079 | ss->bind(cgrp->subsys[i]); | 1079 | ss->bind(cgroup_css(cgrp, i)); |
1080 | 1080 | ||
1081 | /* refcount was already taken, and we're keeping it */ | 1081 | /* refcount was already taken, and we're keeping it */ |
1082 | root->subsys_mask |= bit; | 1082 | root->subsys_mask |= bit; |
1083 | } else if (bit & removed_mask) { | 1083 | } else if (bit & removed_mask) { |
1084 | /* We're removing this subsystem */ | 1084 | /* We're removing this subsystem */ |
1085 | BUG_ON(cgrp->subsys[i] != cgroup_dummy_top->subsys[i]); | 1085 | BUG_ON(cgroup_css(cgrp, i) != cgroup_css(cgroup_dummy_top, i)); |
1086 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); | 1086 | BUG_ON(cgroup_css(cgrp, i)->cgroup != cgrp); |
1087 | 1087 | ||
1088 | if (ss->bind) | 1088 | if (ss->bind) |
1089 | ss->bind(cgroup_dummy_top->subsys[i]); | 1089 | ss->bind(cgroup_css(cgroup_dummy_top, i)); |
1090 | cgroup_dummy_top->subsys[i]->cgroup = cgroup_dummy_top; | 1090 | cgroup_css(cgroup_dummy_top, i)->cgroup = cgroup_dummy_top; |
1091 | cgrp->subsys[i] = NULL; | 1091 | cgrp->subsys[i] = NULL; |
1092 | cgroup_subsys[i]->root = &cgroup_dummy_root; | 1092 | cgroup_subsys[i]->root = &cgroup_dummy_root; |
1093 | list_move(&ss->sibling, &cgroup_dummy_root.subsys_list); | 1093 | list_move(&ss->sibling, &cgroup_dummy_root.subsys_list); |
@@ -2072,7 +2072,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk, | |||
2072 | * step 1: check that we can legitimately attach to the cgroup. | 2072 | * step 1: check that we can legitimately attach to the cgroup. |
2073 | */ | 2073 | */ |
2074 | for_each_root_subsys(root, ss) { | 2074 | for_each_root_subsys(root, ss) { |
2075 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 2075 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
2076 | 2076 | ||
2077 | if (ss->can_attach) { | 2077 | if (ss->can_attach) { |
2078 | retval = ss->can_attach(css, &tset); | 2078 | retval = ss->can_attach(css, &tset); |
@@ -2114,7 +2114,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk, | |||
2114 | * step 4: do subsystem attach callbacks. | 2114 | * step 4: do subsystem attach callbacks. |
2115 | */ | 2115 | */ |
2116 | for_each_root_subsys(root, ss) { | 2116 | for_each_root_subsys(root, ss) { |
2117 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 2117 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
2118 | 2118 | ||
2119 | if (ss->attach) | 2119 | if (ss->attach) |
2120 | ss->attach(css, &tset); | 2120 | ss->attach(css, &tset); |
@@ -2136,7 +2136,7 @@ out_put_css_set_refs: | |||
2136 | out_cancel_attach: | 2136 | out_cancel_attach: |
2137 | if (retval) { | 2137 | if (retval) { |
2138 | for_each_root_subsys(root, ss) { | 2138 | for_each_root_subsys(root, ss) { |
2139 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 2139 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
2140 | 2140 | ||
2141 | if (ss == failed_ss) | 2141 | if (ss == failed_ss) |
2142 | break; | 2142 | break; |
@@ -2308,7 +2308,7 @@ static struct cgroup_subsys_state *cgroup_file_css(struct cfent *cfe) | |||
2308 | struct cgroup *cgrp = __d_cgrp(cfe->dentry->d_parent); | 2308 | struct cgroup *cgrp = __d_cgrp(cfe->dentry->d_parent); |
2309 | 2309 | ||
2310 | if (cft->ss) | 2310 | if (cft->ss) |
2311 | return cgrp->subsys[cft->ss->subsys_id]; | 2311 | return cgroup_css(cgrp, cft->ss->subsys_id); |
2312 | return &cgrp->dummy_css; | 2312 | return &cgrp->dummy_css; |
2313 | } | 2313 | } |
2314 | 2314 | ||
@@ -4241,7 +4241,7 @@ static int cgroup_populate_dir(struct cgroup *cgrp, unsigned long subsys_mask) | |||
4241 | 4241 | ||
4242 | /* This cgroup is ready now */ | 4242 | /* This cgroup is ready now */ |
4243 | for_each_root_subsys(cgrp->root, ss) { | 4243 | for_each_root_subsys(cgrp->root, ss) { |
4244 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 4244 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
4245 | struct css_id *id = rcu_dereference_protected(css->id, true); | 4245 | struct css_id *id = rcu_dereference_protected(css->id, true); |
4246 | 4246 | ||
4247 | /* | 4247 | /* |
@@ -4285,7 +4285,7 @@ static void init_cgroup_css(struct cgroup_subsys_state *css, | |||
4285 | css->id = NULL; | 4285 | css->id = NULL; |
4286 | if (cgrp == cgroup_dummy_top) | 4286 | if (cgrp == cgroup_dummy_top) |
4287 | css->flags |= CSS_ROOT; | 4287 | css->flags |= CSS_ROOT; |
4288 | BUG_ON(cgrp->subsys[ss->subsys_id]); | 4288 | BUG_ON(cgroup_css(cgrp, ss->subsys_id)); |
4289 | cgrp->subsys[ss->subsys_id] = css; | 4289 | cgrp->subsys[ss->subsys_id] = css; |
4290 | 4290 | ||
4291 | /* | 4291 | /* |
@@ -4300,7 +4300,7 @@ static void init_cgroup_css(struct cgroup_subsys_state *css, | |||
4300 | /* invoke ->css_online() on a new CSS and mark it online if successful */ | 4300 | /* invoke ->css_online() on a new CSS and mark it online if successful */ |
4301 | static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp) | 4301 | static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp) |
4302 | { | 4302 | { |
4303 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 4303 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
4304 | int ret = 0; | 4304 | int ret = 0; |
4305 | 4305 | ||
4306 | lockdep_assert_held(&cgroup_mutex); | 4306 | lockdep_assert_held(&cgroup_mutex); |
@@ -4315,7 +4315,7 @@ static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
4315 | /* if the CSS is online, invoke ->css_offline() on it and mark it offline */ | 4315 | /* if the CSS is online, invoke ->css_offline() on it and mark it offline */ |
4316 | static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp) | 4316 | static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp) |
4317 | { | 4317 | { |
4318 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 4318 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
4319 | 4319 | ||
4320 | lockdep_assert_held(&cgroup_mutex); | 4320 | lockdep_assert_held(&cgroup_mutex); |
4321 | 4321 | ||
@@ -4400,7 +4400,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4400 | for_each_root_subsys(root, ss) { | 4400 | for_each_root_subsys(root, ss) { |
4401 | struct cgroup_subsys_state *css; | 4401 | struct cgroup_subsys_state *css; |
4402 | 4402 | ||
4403 | css = ss->css_alloc(parent->subsys[ss->subsys_id]); | 4403 | css = ss->css_alloc(cgroup_css(parent, ss->subsys_id)); |
4404 | if (IS_ERR(css)) { | 4404 | if (IS_ERR(css)) { |
4405 | err = PTR_ERR(css); | 4405 | err = PTR_ERR(css); |
4406 | goto err_free_all; | 4406 | goto err_free_all; |
@@ -4477,7 +4477,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4477 | 4477 | ||
4478 | err_free_all: | 4478 | err_free_all: |
4479 | for_each_root_subsys(root, ss) { | 4479 | for_each_root_subsys(root, ss) { |
4480 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 4480 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
4481 | 4481 | ||
4482 | if (css) { | 4482 | if (css) { |
4483 | percpu_ref_cancel_init(&css->refcnt); | 4483 | percpu_ref_cancel_init(&css->refcnt); |
@@ -4590,7 +4590,7 @@ static int cgroup_destroy_locked(struct cgroup *cgrp) | |||
4590 | */ | 4590 | */ |
4591 | atomic_set(&cgrp->css_kill_cnt, 1); | 4591 | atomic_set(&cgrp->css_kill_cnt, 1); |
4592 | for_each_root_subsys(cgrp->root, ss) { | 4592 | for_each_root_subsys(cgrp->root, ss) { |
4593 | struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id]; | 4593 | struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); |
4594 | 4594 | ||
4595 | /* | 4595 | /* |
4596 | * Killing would put the base ref, but we need to keep it | 4596 | * Killing would put the base ref, but we need to keep it |
@@ -4676,7 +4676,7 @@ static void cgroup_offline_fn(struct work_struct *work) | |||
4676 | * destruction happens only after all css's are released. | 4676 | * destruction happens only after all css's are released. |
4677 | */ | 4677 | */ |
4678 | for_each_root_subsys(cgrp->root, ss) | 4678 | for_each_root_subsys(cgrp->root, ss) |
4679 | css_put(cgrp->subsys[ss->subsys_id]); | 4679 | css_put(cgroup_css(cgrp, ss->subsys_id)); |
4680 | 4680 | ||
4681 | /* delete this cgroup from parent->children */ | 4681 | /* delete this cgroup from parent->children */ |
4682 | list_del_rcu(&cgrp->sibling); | 4682 | list_del_rcu(&cgrp->sibling); |
@@ -4741,7 +4741,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
4741 | /* Create the top cgroup state for this subsystem */ | 4741 | /* Create the top cgroup state for this subsystem */ |
4742 | list_add(&ss->sibling, &cgroup_dummy_root.subsys_list); | 4742 | list_add(&ss->sibling, &cgroup_dummy_root.subsys_list); |
4743 | ss->root = &cgroup_dummy_root; | 4743 | ss->root = &cgroup_dummy_root; |
4744 | css = ss->css_alloc(cgroup_dummy_top->subsys[ss->subsys_id]); | 4744 | css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss->subsys_id)); |
4745 | /* We don't handle early failures gracefully */ | 4745 | /* We don't handle early failures gracefully */ |
4746 | BUG_ON(IS_ERR(css)); | 4746 | BUG_ON(IS_ERR(css)); |
4747 | init_cgroup_css(css, ss, cgroup_dummy_top); | 4747 | init_cgroup_css(css, ss, cgroup_dummy_top); |
@@ -4820,7 +4820,7 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) | |||
4820 | * struct, so this can happen first (i.e. before the dummy root | 4820 | * struct, so this can happen first (i.e. before the dummy root |
4821 | * attachment). | 4821 | * attachment). |
4822 | */ | 4822 | */ |
4823 | css = ss->css_alloc(cgroup_dummy_top->subsys[ss->subsys_id]); | 4823 | css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss->subsys_id)); |
4824 | if (IS_ERR(css)) { | 4824 | if (IS_ERR(css)) { |
4825 | /* failure case - need to deassign the cgroup_subsys[] slot. */ | 4825 | /* failure case - need to deassign the cgroup_subsys[] slot. */ |
4826 | cgroup_subsys[ss->subsys_id] = NULL; | 4826 | cgroup_subsys[ss->subsys_id] = NULL; |
@@ -4936,7 +4936,7 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss) | |||
4936 | * the cgrp->subsys pointer to find their state. note that this | 4936 | * the cgrp->subsys pointer to find their state. note that this |
4937 | * also takes care of freeing the css_id. | 4937 | * also takes care of freeing the css_id. |
4938 | */ | 4938 | */ |
4939 | ss->css_free(cgroup_dummy_top->subsys[ss->subsys_id]); | 4939 | ss->css_free(cgroup_css(cgroup_dummy_top, ss->subsys_id)); |
4940 | cgroup_dummy_top->subsys[ss->subsys_id] = NULL; | 4940 | cgroup_dummy_top->subsys[ss->subsys_id] = NULL; |
4941 | 4941 | ||
4942 | mutex_unlock(&cgroup_mutex); | 4942 | mutex_unlock(&cgroup_mutex); |
@@ -5562,8 +5562,8 @@ static int alloc_css_id(struct cgroup_subsys *ss, struct cgroup *parent, | |||
5562 | struct css_id *child_id, *parent_id; | 5562 | struct css_id *child_id, *parent_id; |
5563 | 5563 | ||
5564 | subsys_id = ss->subsys_id; | 5564 | subsys_id = ss->subsys_id; |
5565 | parent_css = parent->subsys[subsys_id]; | 5565 | parent_css = cgroup_css(parent, subsys_id); |
5566 | child_css = child->subsys[subsys_id]; | 5566 | child_css = cgroup_css(child, subsys_id); |
5567 | parent_id = rcu_dereference_protected(parent_css->id, true); | 5567 | parent_id = rcu_dereference_protected(parent_css->id, true); |
5568 | depth = parent_id->depth + 1; | 5568 | depth = parent_id->depth + 1; |
5569 | 5569 | ||
@@ -5624,7 +5624,7 @@ struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id) | |||
5624 | 5624 | ||
5625 | /* get cgroup */ | 5625 | /* get cgroup */ |
5626 | cgrp = __d_cgrp(f->f_dentry); | 5626 | cgrp = __d_cgrp(f->f_dentry); |
5627 | css = cgrp->subsys[id]; | 5627 | css = cgroup_css(cgrp, id); |
5628 | return css ? css : ERR_PTR(-ENOENT); | 5628 | return css ? css : ERR_PTR(-ENOENT); |
5629 | } | 5629 | } |
5630 | 5630 | ||