aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-08 20:11:23 -0400
committerTejun Heo <tj@kernel.org>2013-08-08 20:11:23 -0400
commita7c6d554aa01236ac2a9f851ab0f75704f76dfa2 (patch)
treefe62d07283a589daa39f843deaefafd11c572b84 /block
parent72c97e54e0f043d33b246d7460ae0a36c4b8c643 (diff)
cgroup: add/update accessors which obtain subsys specific data from css
css (cgroup_subsys_state) is usually embedded in a subsys specific data structure. Subsystems either use container_of() directly to cast from css to such data structure or has an accessor function wrapping such cast. As cgroup as whole is moving towards using css as the main interface handle, add and update such accessors to ease dealing with css's. All accessors explicitly handle NULL input and return NULL in those cases. While this looks like an extra branch in the code, as all controllers specific data structures have css as the first field, the casting doesn't involve any offsetting and the compiler can trivially optimize out the branch. * blkio, freezer, cpuset, cpu, cpuacct and net_cls didn't have such accessor. Added. * memory, hugetlb and devices already had one but didn't explicitly handle NULL input. Updated. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-cgroup.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 628e50f6f8a8..8e5863e900bf 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -179,21 +179,25 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
179void blkg_conf_finish(struct blkg_conf_ctx *ctx); 179void blkg_conf_finish(struct blkg_conf_ctx *ctx);
180 180
181 181
182static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
183{
184 return css ? container_of(css, struct blkcg, css) : NULL;
185}
186
182static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup) 187static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup)
183{ 188{
184 return container_of(cgroup_css(cgroup, blkio_subsys_id), 189 return css_to_blkcg(cgroup_css(cgroup, blkio_subsys_id));
185 struct blkcg, css);
186} 190}
187 191
188static inline struct blkcg *task_blkcg(struct task_struct *tsk) 192static inline struct blkcg *task_blkcg(struct task_struct *tsk)
189{ 193{
190 return container_of(task_css(tsk, blkio_subsys_id), struct blkcg, css); 194 return css_to_blkcg(task_css(tsk, blkio_subsys_id));
191} 195}
192 196
193static inline struct blkcg *bio_blkcg(struct bio *bio) 197static inline struct blkcg *bio_blkcg(struct bio *bio)
194{ 198{
195 if (bio && bio->bi_css) 199 if (bio && bio->bi_css)
196 return container_of(bio->bi_css, struct blkcg, css); 200 return css_to_blkcg(bio->bi_css);
197 return task_blkcg(current); 201 return task_blkcg(current);
198} 202}
199 203