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) { | ||
