aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-16 13:22:48 -0400
committerTejun Heo <tj@kernel.org>2014-05-16 13:22:48 -0400
commit5c9d535b893f30266ea29fe377cb9b002fcd76aa (patch)
tree27b1fd6e16c5b0c0729a93c4924289119033137c
parent3b514d24e200fcdcde0a57c354a51d3677a86743 (diff)
cgroup: remove css_parent()
cgroup in general is moving towards using cgroup_subsys_state as the fundamental structural component and css_parent() was introduced to convert from using cgroup->parent to css->parent. It was quite some time ago and we're moving forward with making css more prominent. This patch drops the trivial wrapper css_parent() and let the users dereference css->parent. While at it, explicitly mark fields of css which are public and immutable. v2: New usage from device_cgroup.c converted. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: "David S. Miller" <davem@davemloft.net> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--block/blk-cgroup.h2
-rw-r--r--include/linux/cgroup.h29
-rw-r--r--kernel/cgroup.c8
-rw-r--r--kernel/cgroup_freezer.c2
-rw-r--r--kernel/cpuset.c2
-rw-r--r--kernel/sched/core.c2
-rw-r--r--kernel/sched/cpuacct.c2
-rw-r--r--mm/hugetlb_cgroup.c2
-rw-r--r--mm/memcontrol.c14
-rw-r--r--net/core/netclassid_cgroup.c2
-rw-r--r--net/core/netprio_cgroup.c2
-rw-r--r--security/device_cgroup.c8
12 files changed, 34 insertions, 41 deletions
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 371fe8e92ab5..d692b29c083a 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -204,7 +204,7 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)
204 */ 204 */
205static inline struct blkcg *blkcg_parent(struct blkcg *blkcg) 205static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
206{ 206{
207 return css_to_blkcg(css_parent(&blkcg->css)); 207 return css_to_blkcg(blkcg->css.parent);
208} 208}
209 209
210/** 210/**
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 1737db0c63fe..2549493d518d 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -48,22 +48,28 @@ enum cgroup_subsys_id {
48}; 48};
49#undef SUBSYS 49#undef SUBSYS
50 50
51/* Per-subsystem/per-cgroup state maintained by the system. */ 51/*
52 * Per-subsystem/per-cgroup state maintained by the system. This is the
53 * fundamental structural building block that controllers deal with.
54 *
55 * Fields marked with "PI:" are public and immutable and may be accessed
56 * directly without synchronization.
57 */
52struct cgroup_subsys_state { 58struct cgroup_subsys_state {
53 /* the cgroup that this css is attached to */ 59 /* PI: the cgroup that this css is attached to */
54 struct cgroup *cgroup; 60 struct cgroup *cgroup;
55 61
56 /* the cgroup subsystem that this css is attached to */ 62 /* PI: the cgroup subsystem that this css is attached to */
57 struct cgroup_subsys *ss; 63 struct cgroup_subsys *ss;
58 64
59 /* reference count - access via css_[try]get() and css_put() */ 65 /* reference count - access via css_[try]get() and css_put() */
60 struct percpu_ref refcnt; 66 struct percpu_ref refcnt;
61 67
62 /* the parent css */ 68 /* PI: the parent css */
63 struct cgroup_subsys_state *parent; 69 struct cgroup_subsys_state *parent;
64 70
65 /* 71 /*
66 * Subsys-unique ID. 0 is unused and root is always 1. The 72 * PI: Subsys-unique ID. 0 is unused and root is always 1. The
67 * matching css can be looked up using css_from_id(). 73 * matching css can be looked up using css_from_id().
68 */ 74 */
69 int id; 75 int id;
@@ -670,19 +676,6 @@ struct cgroup_subsys {
670#undef SUBSYS 676#undef SUBSYS
671 677
672/** 678/**
673 * css_parent - find the parent css
674 * @css: the target cgroup_subsys_state
675 *
676 * Return the parent css of @css. This function is guaranteed to return
677 * non-NULL parent as long as @css isn't the root.
678 */
679static inline
680struct cgroup_subsys_state *css_parent(struct cgroup_subsys_state *css)
681{
682 return css->parent;
683}
684
685/**
686 * task_css_set_check - obtain a task's css_set with extra access conditions 679 * task_css_set_check - obtain a task's css_set with extra access conditions
687 * @task: the task to obtain css_set for 680 * @task: the task to obtain css_set for
688 * @__c: extra condition expression to be passed to rcu_dereference_check() 681 * @__c: extra condition expression to be passed to rcu_dereference_check()
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0343d7ee6d62..929bbbc539e9 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3176,10 +3176,10 @@ css_next_descendant_pre(struct cgroup_subsys_state *pos,
3176 3176
3177 /* no child, visit my or the closest ancestor's next sibling */ 3177 /* no child, visit my or the closest ancestor's next sibling */
3178 while (pos != root) { 3178 while (pos != root) {
3179 next = css_next_child(pos, css_parent(pos)); 3179 next = css_next_child(pos, pos->parent);
3180 if (next) 3180 if (next)
3181 return next; 3181 return next;
3182 pos = css_parent(pos); 3182 pos = pos->parent;
3183 } 3183 }
3184 3184
3185 return NULL; 3185 return NULL;
@@ -3261,12 +3261,12 @@ css_next_descendant_post(struct cgroup_subsys_state *pos,
3261 return NULL; 3261 return NULL;
3262 3262
3263 /* if there's an unvisited sibling, visit its leftmost descendant */ 3263 /* if there's an unvisited sibling, visit its leftmost descendant */
3264 next = css_next_child(pos, css_parent(pos)); 3264 next = css_next_child(pos, pos->parent);
3265 if (next) 3265 if (next)
3266 return css_leftmost_descendant(next); 3266 return css_leftmost_descendant(next);
3267 3267
3268 /* no sibling left, visit parent */ 3268 /* no sibling left, visit parent */
3269 return css_parent(pos); 3269 return pos->parent;
3270} 3270}
3271 3271
3272static bool cgroup_has_live_children(struct cgroup *cgrp) 3272static bool cgroup_has_live_children(struct cgroup *cgrp)
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 6b4e60e33a9a..a79e40f9d700 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -59,7 +59,7 @@ static inline struct freezer *task_freezer(struct task_struct *task)
59 59
60static struct freezer *parent_freezer(struct freezer *freezer) 60static struct freezer *parent_freezer(struct freezer *freezer)
61{ 61{
62 return css_freezer(css_parent(&freezer->css)); 62 return css_freezer(freezer->css.parent);
63} 63}
64 64
65bool cgroup_freezing(struct task_struct *task) 65bool cgroup_freezing(struct task_struct *task)
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 2f4b08b8db24..5b2a31082f4f 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -124,7 +124,7 @@ static inline struct cpuset *task_cs(struct task_struct *task)
124 124
125static inline struct cpuset *parent_cs(struct cpuset *cs) 125static inline struct cpuset *parent_cs(struct cpuset *cs)
126{ 126{
127 return css_cs(css_parent(&cs->css)); 127 return css_cs(cs->css.parent);
128} 128}
129 129
130#ifdef CONFIG_NUMA 130#ifdef CONFIG_NUMA
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 268a45ea238c..ac61ad1a5f9f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7586,7 +7586,7 @@ cpu_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
7586static int cpu_cgroup_css_online(struct cgroup_subsys_state *css) 7586static int cpu_cgroup_css_online(struct cgroup_subsys_state *css)
7587{ 7587{
7588 struct task_group *tg = css_tg(css); 7588 struct task_group *tg = css_tg(css);
7589 struct task_group *parent = css_tg(css_parent(css)); 7589 struct task_group *parent = css_tg(css->parent);
7590 7590
7591 if (parent) 7591 if (parent)
7592 sched_online_group(tg, parent); 7592 sched_online_group(tg, parent);
diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index c143ee380e3a..9cf350c94ec4 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -46,7 +46,7 @@ static inline struct cpuacct *task_ca(struct task_struct *tsk)
46 46
47static inline struct cpuacct *parent_ca(struct cpuacct *ca) 47static inline struct cpuacct *parent_ca(struct cpuacct *ca)
48{ 48{
49 return css_ca(css_parent(&ca->css)); 49 return css_ca(ca->css.parent);
50} 50}
51 51
52static DEFINE_PER_CPU(u64, root_cpuacct_cpuusage); 52static DEFINE_PER_CPU(u64, root_cpuacct_cpuusage);
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index a380681ab3cf..493f758445e7 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -52,7 +52,7 @@ static inline bool hugetlb_cgroup_is_root(struct hugetlb_cgroup *h_cg)
52static inline struct hugetlb_cgroup * 52static inline struct hugetlb_cgroup *
53parent_hugetlb_cgroup(struct hugetlb_cgroup *h_cg) 53parent_hugetlb_cgroup(struct hugetlb_cgroup *h_cg)
54{ 54{
55 return hugetlb_cgroup_from_css(css_parent(&h_cg->css)); 55 return hugetlb_cgroup_from_css(h_cg->css.parent);
56} 56}
57 57
58static inline bool hugetlb_cgroup_have_usage(struct hugetlb_cgroup *h_cg) 58static inline bool hugetlb_cgroup_have_usage(struct hugetlb_cgroup *h_cg)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b638a79209ee..a5e0417b4f9a 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1540,7 +1540,7 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
1540int mem_cgroup_swappiness(struct mem_cgroup *memcg) 1540int mem_cgroup_swappiness(struct mem_cgroup *memcg)
1541{ 1541{
1542 /* root ? */ 1542 /* root ? */
1543 if (!css_parent(&memcg->css)) 1543 if (!memcg->css.parent)
1544 return vm_swappiness; 1544 return vm_swappiness;
1545 1545
1546 return memcg->swappiness; 1546 return memcg->swappiness;
@@ -4909,7 +4909,7 @@ static int mem_cgroup_hierarchy_write(struct cgroup_subsys_state *css,
4909{ 4909{
4910 int retval = 0; 4910 int retval = 0;
4911 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 4911 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
4912 struct mem_cgroup *parent_memcg = mem_cgroup_from_css(css_parent(&memcg->css)); 4912 struct mem_cgroup *parent_memcg = mem_cgroup_from_css(memcg->css.parent);
4913 4913
4914 mutex_lock(&memcg_create_mutex); 4914 mutex_lock(&memcg_create_mutex);
4915 4915
@@ -5207,8 +5207,8 @@ static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg,
5207 if (!memcg->use_hierarchy) 5207 if (!memcg->use_hierarchy)
5208 goto out; 5208 goto out;
5209 5209
5210 while (css_parent(&memcg->css)) { 5210 while (memcg->css.parent) {
5211 memcg = mem_cgroup_from_css(css_parent(&memcg->css)); 5211 memcg = mem_cgroup_from_css(memcg->css.parent);
5212 if (!memcg->use_hierarchy) 5212 if (!memcg->use_hierarchy)
5213 break; 5213 break;
5214 tmp = res_counter_read_u64(&memcg->res, RES_LIMIT); 5214 tmp = res_counter_read_u64(&memcg->res, RES_LIMIT);
@@ -5443,7 +5443,7 @@ static int mem_cgroup_swappiness_write(struct cgroup_subsys_state *css,
5443 struct cftype *cft, u64 val) 5443 struct cftype *cft, u64 val)
5444{ 5444{
5445 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 5445 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5446 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css)); 5446 struct mem_cgroup *parent = mem_cgroup_from_css(memcg->css.parent);
5447 5447
5448 if (val > 100 || !parent) 5448 if (val > 100 || !parent)
5449 return -EINVAL; 5449 return -EINVAL;
@@ -5790,7 +5790,7 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css,
5790 struct cftype *cft, u64 val) 5790 struct cftype *cft, u64 val)
5791{ 5791{
5792 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 5792 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5793 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css)); 5793 struct mem_cgroup *parent = mem_cgroup_from_css(memcg->css.parent);
5794 5794
5795 /* cannot set to root cgroup and only 0 and 1 are allowed */ 5795 /* cannot set to root cgroup and only 0 and 1 are allowed */
5796 if (!parent || !((val == 0) || (val == 1))) 5796 if (!parent || !((val == 0) || (val == 1)))
@@ -6407,7 +6407,7 @@ static int
6407mem_cgroup_css_online(struct cgroup_subsys_state *css) 6407mem_cgroup_css_online(struct cgroup_subsys_state *css)
6408{ 6408{
6409 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 6409 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
6410 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(css)); 6410 struct mem_cgroup *parent = mem_cgroup_from_css(css->parent);
6411 6411
6412 if (css->id > MEM_CGROUP_ID_MAX) 6412 if (css->id > MEM_CGROUP_ID_MAX)
6413 return -ENOSPC; 6413 return -ENOSPC;
diff --git a/net/core/netclassid_cgroup.c b/net/core/netclassid_cgroup.c
index 22931e1b99b4..30d903b19c62 100644
--- a/net/core/netclassid_cgroup.c
+++ b/net/core/netclassid_cgroup.c
@@ -42,7 +42,7 @@ cgrp_css_alloc(struct cgroup_subsys_state *parent_css)
42static int cgrp_css_online(struct cgroup_subsys_state *css) 42static int cgrp_css_online(struct cgroup_subsys_state *css)
43{ 43{
44 struct cgroup_cls_state *cs = css_cls_state(css); 44 struct cgroup_cls_state *cs = css_cls_state(css);
45 struct cgroup_cls_state *parent = css_cls_state(css_parent(css)); 45 struct cgroup_cls_state *parent = css_cls_state(css->parent);
46 46
47 if (parent) 47 if (parent)
48 cs->classid = parent->classid; 48 cs->classid = parent->classid;
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index b990cefd906b..2f385b9bccc0 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -140,7 +140,7 @@ cgrp_css_alloc(struct cgroup_subsys_state *parent_css)
140 140
141static int cgrp_css_online(struct cgroup_subsys_state *css) 141static int cgrp_css_online(struct cgroup_subsys_state *css)
142{ 142{
143 struct cgroup_subsys_state *parent_css = css_parent(css); 143 struct cgroup_subsys_state *parent_css = css->parent;
144 struct net_device *dev; 144 struct net_device *dev;
145 int ret = 0; 145 int ret = 0;
146 146
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 7dbac4061b1c..ce14a31b1337 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -182,7 +182,7 @@ static inline bool is_devcg_online(const struct dev_cgroup *devcg)
182static int devcgroup_online(struct cgroup_subsys_state *css) 182static int devcgroup_online(struct cgroup_subsys_state *css)
183{ 183{
184 struct dev_cgroup *dev_cgroup = css_to_devcgroup(css); 184 struct dev_cgroup *dev_cgroup = css_to_devcgroup(css);
185 struct dev_cgroup *parent_dev_cgroup = css_to_devcgroup(css_parent(css)); 185 struct dev_cgroup *parent_dev_cgroup = css_to_devcgroup(css->parent);
186 int ret = 0; 186 int ret = 0;
187 187
188 mutex_lock(&devcgroup_mutex); 188 mutex_lock(&devcgroup_mutex);
@@ -455,7 +455,7 @@ static bool verify_new_ex(struct dev_cgroup *dev_cgroup,
455static int parent_has_perm(struct dev_cgroup *childcg, 455static int parent_has_perm(struct dev_cgroup *childcg,
456 struct dev_exception_item *ex) 456 struct dev_exception_item *ex)
457{ 457{
458 struct dev_cgroup *parent = css_to_devcgroup(css_parent(&childcg->css)); 458 struct dev_cgroup *parent = css_to_devcgroup(childcg->css.parent);
459 459
460 if (!parent) 460 if (!parent)
461 return 1; 461 return 1;
@@ -476,7 +476,7 @@ static int parent_has_perm(struct dev_cgroup *childcg,
476static bool parent_allows_removal(struct dev_cgroup *childcg, 476static bool parent_allows_removal(struct dev_cgroup *childcg,
477 struct dev_exception_item *ex) 477 struct dev_exception_item *ex)
478{ 478{
479 struct dev_cgroup *parent = css_to_devcgroup(css_parent(&childcg->css)); 479 struct dev_cgroup *parent = css_to_devcgroup(childcg->css.parent);
480 480
481 if (!parent) 481 if (!parent)
482 return true; 482 return true;
@@ -614,7 +614,7 @@ static int devcgroup_update_access(struct dev_cgroup *devcgroup,
614 char temp[12]; /* 11 + 1 characters needed for a u32 */ 614 char temp[12]; /* 11 + 1 characters needed for a u32 */
615 int count, rc = 0; 615 int count, rc = 0;
616 struct dev_exception_item ex; 616 struct dev_exception_item ex;
617 struct dev_cgroup *parent = css_to_devcgroup(css_parent(&devcgroup->css)); 617 struct dev_cgroup *parent = css_to_devcgroup(devcgroup->css.parent);
618 618
619 if (!capable(CAP_SYS_ADMIN)) 619 if (!capable(CAP_SYS_ADMIN))
620 return -EPERM; 620 return -EPERM;