diff options
Diffstat (limited to 'include/linux/cgroup.h')
-rw-r--r-- | include/linux/cgroup.h | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 1164963c3a85..e267e62827bb 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -52,9 +52,9 @@ struct cgroup_subsys_state { | |||
52 | * hierarchy structure */ | 52 | * hierarchy structure */ |
53 | struct cgroup *cgroup; | 53 | struct cgroup *cgroup; |
54 | 54 | ||
55 | /* State maintained by the cgroup system to allow | 55 | /* State maintained by the cgroup system to allow subsystems |
56 | * subsystems to be "busy". Should be accessed via css_get() | 56 | * to be "busy". Should be accessed via css_get(), |
57 | * and css_put() */ | 57 | * css_tryget() and and css_put(). */ |
58 | 58 | ||
59 | atomic_t refcnt; | 59 | atomic_t refcnt; |
60 | 60 | ||
@@ -64,11 +64,14 @@ struct cgroup_subsys_state { | |||
64 | /* bits in struct cgroup_subsys_state flags field */ | 64 | /* bits in struct cgroup_subsys_state flags field */ |
65 | enum { | 65 | enum { |
66 | CSS_ROOT, /* This CSS is the root of the subsystem */ | 66 | CSS_ROOT, /* This CSS is the root of the subsystem */ |
67 | CSS_REMOVED, /* This CSS is dead */ | ||
67 | }; | 68 | }; |
68 | 69 | ||
69 | /* | 70 | /* |
70 | * Call css_get() to hold a reference on the cgroup; | 71 | * Call css_get() to hold a reference on the css; it can be used |
71 | * | 72 | * for a reference obtained via: |
73 | * - an existing ref-counted reference to the css | ||
74 | * - task->cgroups for a locked task | ||
72 | */ | 75 | */ |
73 | 76 | ||
74 | static inline void css_get(struct cgroup_subsys_state *css) | 77 | static inline void css_get(struct cgroup_subsys_state *css) |
@@ -77,9 +80,32 @@ static inline void css_get(struct cgroup_subsys_state *css) | |||
77 | if (!test_bit(CSS_ROOT, &css->flags)) | 80 | if (!test_bit(CSS_ROOT, &css->flags)) |
78 | atomic_inc(&css->refcnt); | 81 | atomic_inc(&css->refcnt); |
79 | } | 82 | } |
83 | |||
84 | static inline bool css_is_removed(struct cgroup_subsys_state *css) | ||
85 | { | ||
86 | return test_bit(CSS_REMOVED, &css->flags); | ||
87 | } | ||
88 | |||
89 | /* | ||
90 | * Call css_tryget() to take a reference on a css if your existing | ||
91 | * (known-valid) reference isn't already ref-counted. Returns false if | ||
92 | * the css has been destroyed. | ||
93 | */ | ||
94 | |||
95 | static inline bool css_tryget(struct cgroup_subsys_state *css) | ||
96 | { | ||
97 | if (test_bit(CSS_ROOT, &css->flags)) | ||
98 | return true; | ||
99 | while (!atomic_inc_not_zero(&css->refcnt)) { | ||
100 | if (test_bit(CSS_REMOVED, &css->flags)) | ||
101 | return false; | ||
102 | } | ||
103 | return true; | ||
104 | } | ||
105 | |||
80 | /* | 106 | /* |
81 | * css_put() should be called to release a reference taken by | 107 | * css_put() should be called to release a reference taken by |
82 | * css_get() | 108 | * css_get() or css_tryget() |
83 | */ | 109 | */ |
84 | 110 | ||
85 | extern void __css_put(struct cgroup_subsys_state *css); | 111 | extern void __css_put(struct cgroup_subsys_state *css); |
@@ -116,7 +142,7 @@ struct cgroup { | |||
116 | struct list_head children; /* my children */ | 142 | struct list_head children; /* my children */ |
117 | 143 | ||
118 | struct cgroup *parent; /* my parent */ | 144 | struct cgroup *parent; /* my parent */ |
119 | struct dentry *dentry; /* cgroup fs entry */ | 145 | struct dentry *dentry; /* cgroup fs entry, RCU protected */ |
120 | 146 | ||
121 | /* Private pointers for each registered subsystem */ | 147 | /* Private pointers for each registered subsystem */ |
122 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; | 148 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; |
@@ -145,6 +171,9 @@ struct cgroup { | |||
145 | int pids_use_count; | 171 | int pids_use_count; |
146 | /* Length of the current tasks_pids array */ | 172 | /* Length of the current tasks_pids array */ |
147 | int pids_length; | 173 | int pids_length; |
174 | |||
175 | /* For RCU-protected deletion */ | ||
176 | struct rcu_head rcu_head; | ||
148 | }; | 177 | }; |
149 | 178 | ||
150 | /* A css_set is a structure holding pointers to a set of | 179 | /* A css_set is a structure holding pointers to a set of |
@@ -329,13 +358,7 @@ struct cgroup_subsys { | |||
329 | struct cgroup *cgrp); | 358 | struct cgroup *cgrp); |
330 | void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cgrp); | 359 | void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cgrp); |
331 | void (*bind)(struct cgroup_subsys *ss, struct cgroup *root); | 360 | void (*bind)(struct cgroup_subsys *ss, struct cgroup *root); |
332 | /* | 361 | |
333 | * This routine is called with the task_lock of mm->owner held | ||
334 | */ | ||
335 | void (*mm_owner_changed)(struct cgroup_subsys *ss, | ||
336 | struct cgroup *old, | ||
337 | struct cgroup *new, | ||
338 | struct task_struct *p); | ||
339 | int subsys_id; | 362 | int subsys_id; |
340 | int active; | 363 | int active; |
341 | int disabled; | 364 | int disabled; |
@@ -343,9 +366,23 @@ struct cgroup_subsys { | |||
343 | #define MAX_CGROUP_TYPE_NAMELEN 32 | 366 | #define MAX_CGROUP_TYPE_NAMELEN 32 |
344 | const char *name; | 367 | const char *name; |
345 | 368 | ||
346 | /* Protected by RCU */ | 369 | /* |
347 | struct cgroupfs_root *root; | 370 | * Protects sibling/children links of cgroups in this |
371 | * hierarchy, plus protects which hierarchy (or none) the | ||
372 | * subsystem is a part of (i.e. root/sibling). To avoid | ||
373 | * potential deadlocks, the following operations should not be | ||
374 | * undertaken while holding any hierarchy_mutex: | ||
375 | * | ||
376 | * - allocating memory | ||
377 | * - initiating hotplug events | ||
378 | */ | ||
379 | struct mutex hierarchy_mutex; | ||
348 | 380 | ||
381 | /* | ||
382 | * Link to parent, and list entry in parent's children. | ||
383 | * Protected by this->hierarchy_mutex and cgroup_lock() | ||
384 | */ | ||
385 | struct cgroupfs_root *root; | ||
349 | struct list_head sibling; | 386 | struct list_head sibling; |
350 | }; | 387 | }; |
351 | 388 | ||
@@ -400,9 +437,6 @@ void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it); | |||
400 | int cgroup_scan_tasks(struct cgroup_scanner *scan); | 437 | int cgroup_scan_tasks(struct cgroup_scanner *scan); |
401 | int cgroup_attach_task(struct cgroup *, struct task_struct *); | 438 | int cgroup_attach_task(struct cgroup *, struct task_struct *); |
402 | 439 | ||
403 | void cgroup_mm_owner_callbacks(struct task_struct *old, | ||
404 | struct task_struct *new); | ||
405 | |||
406 | #else /* !CONFIG_CGROUPS */ | 440 | #else /* !CONFIG_CGROUPS */ |
407 | 441 | ||
408 | static inline int cgroup_init_early(void) { return 0; } | 442 | static inline int cgroup_init_early(void) { return 0; } |
@@ -420,9 +454,6 @@ static inline int cgroupstats_build(struct cgroupstats *stats, | |||
420 | return -EINVAL; | 454 | return -EINVAL; |
421 | } | 455 | } |
422 | 456 | ||
423 | static inline void cgroup_mm_owner_callbacks(struct task_struct *old, | ||
424 | struct task_struct *new) {} | ||
425 | |||
426 | #endif /* !CONFIG_CGROUPS */ | 457 | #endif /* !CONFIG_CGROUPS */ |
427 | 458 | ||
428 | #endif /* _LINUX_CGROUP_H */ | 459 | #endif /* _LINUX_CGROUP_H */ |