summaryrefslogtreecommitdiff
path: root/block/blk-cgroup.h
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/blk-cgroup.h
parent72c97e54e0f043d33b246d7460ae0a36c4b8c643 (diff)
downloadlwn-a7c6d554aa01236ac2a9f851ab0f75704f76dfa2.tar.gz
lwn-a7c6d554aa01236ac2a9f851ab0f75704f76dfa2.zip
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/blk-cgroup.h')
-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,
void blkg_conf_finish(struct blkg_conf_ctx *ctx);
+static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
+{
+ return css ? container_of(css, struct blkcg, css) : NULL;
+}
+
static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup)
{
- return container_of(cgroup_css(cgroup, blkio_subsys_id),
- struct blkcg, css);
+ return css_to_blkcg(cgroup_css(cgroup, blkio_subsys_id));
}
static inline struct blkcg *task_blkcg(struct task_struct *tsk)
{
- return container_of(task_css(tsk, blkio_subsys_id), struct blkcg, css);
+ return css_to_blkcg(task_css(tsk, blkio_subsys_id));
}
static inline struct blkcg *bio_blkcg(struct bio *bio)
{
if (bio && bio->bi_css)
- return container_of(bio->bi_css, struct blkcg, css);
+ return css_to_blkcg(bio->bi_css);
return task_blkcg(current);
}