diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-08 20:11:24 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-08 20:11:24 -0400 |
commit | 67f4c36f83455b253445b2cb28ac9a2c4f85d99a (patch) | |
tree | 3c7aecc6fc830799cf36716ea64583cc10cb9d40 | |
parent | f7d58818ba4249f04a83b73aaac135640050bb4f (diff) |
cgroup: add cgroup->dummy_css
cgroup subsystem API is being converted to use css
(cgroup_subsys_state) as the main handle, which makes things a bit
awkward for subsystem agnostic core features - the "cgroup.*"
interface files and various iterations - a bit awkward as they don't
have a css to use.
This patch adds cgroup->dummy_css which has NULL ->ss and whose only
role is pointing back to the cgroup. This will be used to support
subsystem agnostic features on the coming css based API.
css_parent() is updated to handle dummy_css's. Note that css will
soon grow its own ->parent field and css_parent() will be made
trivial.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r-- | include/linux/cgroup.h | 11 | ||||
-rw-r--r-- | kernel/cgroup.c | 9 |
2 files changed, 15 insertions, 5 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 5db8138a0482..b0d5f53ae5e1 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -225,6 +225,9 @@ struct cgroup { | |||
225 | struct list_head pidlists; | 225 | struct list_head pidlists; |
226 | struct mutex pidlist_mutex; | 226 | struct mutex pidlist_mutex; |
227 | 227 | ||
228 | /* dummy css with NULL ->ss, points back to this cgroup */ | ||
229 | struct cgroup_subsys_state dummy_css; | ||
230 | |||
228 | /* For css percpu_ref killing and RCU-protected deletion */ | 231 | /* For css percpu_ref killing and RCU-protected deletion */ |
229 | struct rcu_head rcu_head; | 232 | struct rcu_head rcu_head; |
230 | struct work_struct destroy_work; | 233 | struct work_struct destroy_work; |
@@ -668,7 +671,13 @@ struct cgroup_subsys_state *css_parent(struct cgroup_subsys_state *css) | |||
668 | { | 671 | { |
669 | struct cgroup *parent_cgrp = css->cgroup->parent; | 672 | struct cgroup *parent_cgrp = css->cgroup->parent; |
670 | 673 | ||
671 | return parent_cgrp ? parent_cgrp->subsys[css->ss->subsys_id] : NULL; | 674 | if (!parent_cgrp) |
675 | return NULL; | ||
676 | |||
677 | if (css->ss) | ||
678 | return parent_cgrp->subsys[css->ss->subsys_id]; | ||
679 | else | ||
680 | return &parent_cgrp->dummy_css; | ||
672 | } | 681 | } |
673 | 682 | ||
674 | /** | 683 | /** |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 583f8f66a7e1..c049992f1ffa 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -1365,6 +1365,7 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) | |||
1365 | INIT_LIST_HEAD(&cgrp->release_list); | 1365 | INIT_LIST_HEAD(&cgrp->release_list); |
1366 | INIT_LIST_HEAD(&cgrp->pidlists); | 1366 | INIT_LIST_HEAD(&cgrp->pidlists); |
1367 | mutex_init(&cgrp->pidlist_mutex); | 1367 | mutex_init(&cgrp->pidlist_mutex); |
1368 | cgrp->dummy_css.cgroup = cgrp; | ||
1368 | INIT_LIST_HEAD(&cgrp->event_list); | 1369 | INIT_LIST_HEAD(&cgrp->event_list); |
1369 | spin_lock_init(&cgrp->event_list_lock); | 1370 | spin_lock_init(&cgrp->event_list_lock); |
1370 | simple_xattrs_init(&cgrp->xattrs); | 1371 | simple_xattrs_init(&cgrp->xattrs); |
@@ -2285,7 +2286,7 @@ static struct cgroup_subsys_state *cgroup_file_css(struct cfent *cfe) | |||
2285 | 2286 | ||
2286 | if (cft->ss) | 2287 | if (cft->ss) |
2287 | return cgrp->subsys[cft->ss->subsys_id]; | 2288 | return cgrp->subsys[cft->ss->subsys_id]; |
2288 | return NULL; | 2289 | return &cgrp->dummy_css; |
2289 | } | 2290 | } |
2290 | 2291 | ||
2291 | /* A buffer size big enough for numbers or short strings */ | 2292 | /* A buffer size big enough for numbers or short strings */ |
@@ -2467,7 +2468,7 @@ static int cgroup_file_open(struct inode *inode, struct file *file) | |||
2467 | * unpinned either on open failure or release. This ensures that | 2468 | * unpinned either on open failure or release. This ensures that |
2468 | * @css stays alive for all file operations. | 2469 | * @css stays alive for all file operations. |
2469 | */ | 2470 | */ |
2470 | if (css && !css_tryget(css)) | 2471 | if (css->ss && !css_tryget(css)) |
2471 | return -ENODEV; | 2472 | return -ENODEV; |
2472 | 2473 | ||
2473 | if (cft->read_map || cft->read_seq_string) { | 2474 | if (cft->read_map || cft->read_seq_string) { |
@@ -2477,7 +2478,7 @@ static int cgroup_file_open(struct inode *inode, struct file *file) | |||
2477 | err = cft->open(inode, file); | 2478 | err = cft->open(inode, file); |
2478 | } | 2479 | } |
2479 | 2480 | ||
2480 | if (css && err) | 2481 | if (css->ss && err) |
2481 | css_put(css); | 2482 | css_put(css); |
2482 | return err; | 2483 | return err; |
2483 | } | 2484 | } |
@@ -2491,7 +2492,7 @@ static int cgroup_file_release(struct inode *inode, struct file *file) | |||
2491 | 2492 | ||
2492 | if (cft->release) | 2493 | if (cft->release) |
2493 | ret = cft->release(inode, file); | 2494 | ret = cft->release(inode, file); |
2494 | if (css) | 2495 | if (css->ss) |
2495 | css_put(css); | 2496 | css_put(css); |
2496 | return ret; | 2497 | return ret; |
2497 | } | 2498 | } |