aboutsummaryrefslogtreecommitdiffstats
path: root/security/device_cgroup.c
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
commiteb95419b023abacb415e2a18fea899023ce7624d (patch)
tree705284469b67cbe440b86c6cb81e1cf27648eba9 /security/device_cgroup.c
parent6387698699afd72d6304566fb6ccf84bffe07c56 (diff)
cgroup: pass around cgroup_subsys_state instead of cgroup in subsystem methods
cgroup is currently in the process of transitioning to using struct cgroup_subsys_state * as the primary handle instead of struct cgroup * in subsystem implementations for the following reasons. * With unified hierarchy, subsystems will be dynamically bound and unbound from cgroups and thus css's (cgroup_subsys_state) may be created and destroyed dynamically over the lifetime of a cgroup, which is different from the current state where all css's are allocated and destroyed together with the associated cgroup. This in turn means that cgroup_css() should be synchronized and may return NULL, making it more cumbersome to use. * Differing levels of per-subsystem granularity in the unified hierarchy means that the task and descendant iterators should behave differently depending on the specific subsystem the iteration is being performed for. * In majority of the cases, subsystems only care about its part in the cgroup hierarchy - ie. the hierarchy of css's. Subsystem methods often obtain the matching css pointer from the cgroup and don't bother with the cgroup pointer itself. Passing around css fits much better. This patch converts all cgroup_subsys methods to take @css instead of @cgroup. The conversions are mostly straight-forward. A few noteworthy changes are * ->css_alloc() now takes css of the parent cgroup rather than the pointer to the new cgroup as the css for the new cgroup doesn't exist yet. Knowing the parent css is enough for all the existing subsystems. * In kernel/cgroup.c::offline_css(), unnecessary open coded css dereference is replaced with local variable access. This patch shouldn't cause any behavior differences. v2: Unnecessary explicit cgrp->subsys[] deref in css_online() replaced with local variable @css as suggested by Li Zefan. Rebased on top of new for-3.12 which includes for-3.11-fixes so that ->css_free() invocation added by da0a12caff ("cgroup: fix a leak when percpu_ref_init() fails") is converted too. Suggested by Li Zefan. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Aristeu Rozanski <aris@redhat.com> Acked-by: Daniel Wagner <daniel.wagner@bmw-carit.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'security/device_cgroup.c')
-rw-r--r--security/device_cgroup.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 635a49db005d..7293ac49ba7b 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -68,7 +68,7 @@ static inline struct dev_cgroup *task_devcgroup(struct task_struct *task)
68 68
69struct cgroup_subsys devices_subsys; 69struct cgroup_subsys devices_subsys;
70 70
71static int devcgroup_can_attach(struct cgroup *new_cgrp, 71static int devcgroup_can_attach(struct cgroup_subsys_state *new_css,
72 struct cgroup_taskset *set) 72 struct cgroup_taskset *set)
73{ 73{
74 struct task_struct *task = cgroup_taskset_first(set); 74 struct task_struct *task = cgroup_taskset_first(set);
@@ -193,13 +193,13 @@ static inline bool is_devcg_online(const struct dev_cgroup *devcg)
193/** 193/**
194 * devcgroup_online - initializes devcgroup's behavior and exceptions based on 194 * devcgroup_online - initializes devcgroup's behavior and exceptions based on
195 * parent's 195 * parent's
196 * @cgroup: cgroup getting online 196 * @css: css getting online
197 * returns 0 in case of success, error code otherwise 197 * returns 0 in case of success, error code otherwise
198 */ 198 */
199static int devcgroup_online(struct cgroup *cgroup) 199static int devcgroup_online(struct cgroup_subsys_state *css)
200{ 200{
201 struct dev_cgroup *dev_cgroup = cgroup_to_devcgroup(cgroup); 201 struct dev_cgroup *dev_cgroup = css_to_devcgroup(css);
202 struct dev_cgroup *parent_dev_cgroup = css_to_devcgroup(css_parent(&dev_cgroup->css)); 202 struct dev_cgroup *parent_dev_cgroup = css_to_devcgroup(css_parent(css));
203 int ret = 0; 203 int ret = 0;
204 204
205 mutex_lock(&devcgroup_mutex); 205 mutex_lock(&devcgroup_mutex);
@@ -217,9 +217,9 @@ static int devcgroup_online(struct cgroup *cgroup)
217 return ret; 217 return ret;
218} 218}
219 219
220static void devcgroup_offline(struct cgroup *cgroup) 220static void devcgroup_offline(struct cgroup_subsys_state *css)
221{ 221{
222 struct dev_cgroup *dev_cgroup = cgroup_to_devcgroup(cgroup); 222 struct dev_cgroup *dev_cgroup = css_to_devcgroup(css);
223 223
224 mutex_lock(&devcgroup_mutex); 224 mutex_lock(&devcgroup_mutex);
225 dev_cgroup->behavior = DEVCG_DEFAULT_NONE; 225 dev_cgroup->behavior = DEVCG_DEFAULT_NONE;
@@ -229,7 +229,8 @@ static void devcgroup_offline(struct cgroup *cgroup)
229/* 229/*
230 * called from kernel/cgroup.c with cgroup_lock() held. 230 * called from kernel/cgroup.c with cgroup_lock() held.
231 */ 231 */
232static struct cgroup_subsys_state *devcgroup_css_alloc(struct cgroup *cgroup) 232static struct cgroup_subsys_state *
233devcgroup_css_alloc(struct cgroup_subsys_state *parent_css)
233{ 234{
234 struct dev_cgroup *dev_cgroup; 235 struct dev_cgroup *dev_cgroup;
235 236
@@ -242,11 +243,10 @@ static struct cgroup_subsys_state *devcgroup_css_alloc(struct cgroup *cgroup)
242 return &dev_cgroup->css; 243 return &dev_cgroup->css;
243} 244}
244 245
245static void devcgroup_css_free(struct cgroup *cgroup) 246static void devcgroup_css_free(struct cgroup_subsys_state *css)
246{ 247{
247 struct dev_cgroup *dev_cgroup; 248 struct dev_cgroup *dev_cgroup = css_to_devcgroup(css);
248 249
249 dev_cgroup = cgroup_to_devcgroup(cgroup);
250 __dev_exception_clean(dev_cgroup); 250 __dev_exception_clean(dev_cgroup);
251 kfree(dev_cgroup); 251 kfree(dev_cgroup);
252} 252}