diff options
Diffstat (limited to 'include/linux/cgroup.h')
-rw-r--r-- | include/linux/cgroup.h | 178 |
1 files changed, 152 insertions, 26 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 900af5964f55..646ab9d15e42 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/idr.h> | 19 | #include <linux/idr.h> |
20 | #include <linux/workqueue.h> | 20 | #include <linux/workqueue.h> |
21 | #include <linux/xattr.h> | 21 | #include <linux/xattr.h> |
22 | #include <linux/fs.h> | ||
22 | 23 | ||
23 | #ifdef CONFIG_CGROUPS | 24 | #ifdef CONFIG_CGROUPS |
24 | 25 | ||
@@ -30,10 +31,6 @@ struct css_id; | |||
30 | 31 | ||
31 | extern int cgroup_init_early(void); | 32 | extern int cgroup_init_early(void); |
32 | extern int cgroup_init(void); | 33 | extern int cgroup_init(void); |
33 | extern void cgroup_lock(void); | ||
34 | extern int cgroup_lock_is_held(void); | ||
35 | extern bool cgroup_lock_live_group(struct cgroup *cgrp); | ||
36 | extern void cgroup_unlock(void); | ||
37 | extern void cgroup_fork(struct task_struct *p); | 34 | extern void cgroup_fork(struct task_struct *p); |
38 | extern void cgroup_post_fork(struct task_struct *p); | 35 | extern void cgroup_post_fork(struct task_struct *p); |
39 | extern void cgroup_exit(struct task_struct *p, int run_callbacks); | 36 | extern void cgroup_exit(struct task_struct *p, int run_callbacks); |
@@ -44,14 +41,25 @@ extern void cgroup_unload_subsys(struct cgroup_subsys *ss); | |||
44 | 41 | ||
45 | extern const struct file_operations proc_cgroup_operations; | 42 | extern const struct file_operations proc_cgroup_operations; |
46 | 43 | ||
47 | /* Define the enumeration of all builtin cgroup subsystems */ | 44 | /* |
45 | * Define the enumeration of all cgroup subsystems. | ||
46 | * | ||
47 | * We define ids for builtin subsystems and then modular ones. | ||
48 | */ | ||
48 | #define SUBSYS(_x) _x ## _subsys_id, | 49 | #define SUBSYS(_x) _x ## _subsys_id, |
49 | #define IS_SUBSYS_ENABLED(option) IS_ENABLED(option) | ||
50 | enum cgroup_subsys_id { | 50 | enum cgroup_subsys_id { |
51 | #define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option) | ||
51 | #include <linux/cgroup_subsys.h> | 52 | #include <linux/cgroup_subsys.h> |
53 | #undef IS_SUBSYS_ENABLED | ||
54 | CGROUP_BUILTIN_SUBSYS_COUNT, | ||
55 | |||
56 | __CGROUP_SUBSYS_TEMP_PLACEHOLDER = CGROUP_BUILTIN_SUBSYS_COUNT - 1, | ||
57 | |||
58 | #define IS_SUBSYS_ENABLED(option) IS_MODULE(option) | ||
59 | #include <linux/cgroup_subsys.h> | ||
60 | #undef IS_SUBSYS_ENABLED | ||
52 | CGROUP_SUBSYS_COUNT, | 61 | CGROUP_SUBSYS_COUNT, |
53 | }; | 62 | }; |
54 | #undef IS_SUBSYS_ENABLED | ||
55 | #undef SUBSYS | 63 | #undef SUBSYS |
56 | 64 | ||
57 | /* Per-subsystem/per-cgroup state maintained by the system. */ | 65 | /* Per-subsystem/per-cgroup state maintained by the system. */ |
@@ -148,6 +156,13 @@ enum { | |||
148 | * specified at mount time and thus is implemented here. | 156 | * specified at mount time and thus is implemented here. |
149 | */ | 157 | */ |
150 | CGRP_CPUSET_CLONE_CHILDREN, | 158 | CGRP_CPUSET_CLONE_CHILDREN, |
159 | /* see the comment above CGRP_ROOT_SANE_BEHAVIOR for details */ | ||
160 | CGRP_SANE_BEHAVIOR, | ||
161 | }; | ||
162 | |||
163 | struct cgroup_name { | ||
164 | struct rcu_head rcu_head; | ||
165 | char name[]; | ||
151 | }; | 166 | }; |
152 | 167 | ||
153 | struct cgroup { | 168 | struct cgroup { |
@@ -172,11 +187,23 @@ struct cgroup { | |||
172 | struct cgroup *parent; /* my parent */ | 187 | struct cgroup *parent; /* my parent */ |
173 | struct dentry *dentry; /* cgroup fs entry, RCU protected */ | 188 | struct dentry *dentry; /* cgroup fs entry, RCU protected */ |
174 | 189 | ||
190 | /* | ||
191 | * This is a copy of dentry->d_name, and it's needed because | ||
192 | * we can't use dentry->d_name in cgroup_path(). | ||
193 | * | ||
194 | * You must acquire rcu_read_lock() to access cgrp->name, and | ||
195 | * the only place that can change it is rename(), which is | ||
196 | * protected by parent dir's i_mutex. | ||
197 | * | ||
198 | * Normally you should use cgroup_name() wrapper rather than | ||
199 | * access it directly. | ||
200 | */ | ||
201 | struct cgroup_name __rcu *name; | ||
202 | |||
175 | /* Private pointers for each registered subsystem */ | 203 | /* Private pointers for each registered subsystem */ |
176 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; | 204 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; |
177 | 205 | ||
178 | struct cgroupfs_root *root; | 206 | struct cgroupfs_root *root; |
179 | struct cgroup *top_cgroup; | ||
180 | 207 | ||
181 | /* | 208 | /* |
182 | * List of cg_cgroup_links pointing at css_sets with | 209 | * List of cg_cgroup_links pointing at css_sets with |
@@ -213,6 +240,96 @@ struct cgroup { | |||
213 | struct simple_xattrs xattrs; | 240 | struct simple_xattrs xattrs; |
214 | }; | 241 | }; |
215 | 242 | ||
243 | #define MAX_CGROUP_ROOT_NAMELEN 64 | ||
244 | |||
245 | /* cgroupfs_root->flags */ | ||
246 | enum { | ||
247 | /* | ||
248 | * Unfortunately, cgroup core and various controllers are riddled | ||
249 | * with idiosyncrasies and pointless options. The following flag, | ||
250 | * when set, will force sane behavior - some options are forced on, | ||
251 | * others are disallowed, and some controllers will change their | ||
252 | * hierarchical or other behaviors. | ||
253 | * | ||
254 | * The set of behaviors affected by this flag are still being | ||
255 | * determined and developed and the mount option for this flag is | ||
256 | * prefixed with __DEVEL__. The prefix will be dropped once we | ||
257 | * reach the point where all behaviors are compatible with the | ||
258 | * planned unified hierarchy, which will automatically turn on this | ||
259 | * flag. | ||
260 | * | ||
261 | * The followings are the behaviors currently affected this flag. | ||
262 | * | ||
263 | * - Mount options "noprefix" and "clone_children" are disallowed. | ||
264 | * Also, cgroupfs file cgroup.clone_children is not created. | ||
265 | * | ||
266 | * - When mounting an existing superblock, mount options should | ||
267 | * match. | ||
268 | * | ||
269 | * - Remount is disallowed. | ||
270 | * | ||
271 | * - memcg: use_hierarchy is on by default and the cgroup file for | ||
272 | * the flag is not created. | ||
273 | * | ||
274 | * The followings are planned changes. | ||
275 | * | ||
276 | * - release_agent will be disallowed once replacement notification | ||
277 | * mechanism is implemented. | ||
278 | */ | ||
279 | CGRP_ROOT_SANE_BEHAVIOR = (1 << 0), | ||
280 | |||
281 | CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */ | ||
282 | CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */ | ||
283 | }; | ||
284 | |||
285 | /* | ||
286 | * A cgroupfs_root represents the root of a cgroup hierarchy, and may be | ||
287 | * associated with a superblock to form an active hierarchy. This is | ||
288 | * internal to cgroup core. Don't access directly from controllers. | ||
289 | */ | ||
290 | struct cgroupfs_root { | ||
291 | struct super_block *sb; | ||
292 | |||
293 | /* | ||
294 | * The bitmask of subsystems intended to be attached to this | ||
295 | * hierarchy | ||
296 | */ | ||
297 | unsigned long subsys_mask; | ||
298 | |||
299 | /* Unique id for this hierarchy. */ | ||
300 | int hierarchy_id; | ||
301 | |||
302 | /* The bitmask of subsystems currently attached to this hierarchy */ | ||
303 | unsigned long actual_subsys_mask; | ||
304 | |||
305 | /* A list running through the attached subsystems */ | ||
306 | struct list_head subsys_list; | ||
307 | |||
308 | /* The root cgroup for this hierarchy */ | ||
309 | struct cgroup top_cgroup; | ||
310 | |||
311 | /* Tracks how many cgroups are currently defined in hierarchy.*/ | ||
312 | int number_of_cgroups; | ||
313 | |||
314 | /* A list running through the active hierarchies */ | ||
315 | struct list_head root_list; | ||
316 | |||
317 | /* All cgroups on this root, cgroup_mutex protected */ | ||
318 | struct list_head allcg_list; | ||
319 | |||
320 | /* Hierarchy-specific flags */ | ||
321 | unsigned long flags; | ||
322 | |||
323 | /* IDs for cgroups in this hierarchy */ | ||
324 | struct ida cgroup_ida; | ||
325 | |||
326 | /* The path to use for release notifications. */ | ||
327 | char release_agent_path[PATH_MAX]; | ||
328 | |||
329 | /* The name for this hierarchy - may be empty */ | ||
330 | char name[MAX_CGROUP_ROOT_NAMELEN]; | ||
331 | }; | ||
332 | |||
216 | /* | 333 | /* |
217 | * A css_set is a structure holding pointers to a set of | 334 | * A css_set is a structure holding pointers to a set of |
218 | * cgroup_subsys_state objects. This saves space in the task struct | 335 | * cgroup_subsys_state objects. This saves space in the task struct |
@@ -278,6 +395,7 @@ struct cgroup_map_cb { | |||
278 | /* cftype->flags */ | 395 | /* cftype->flags */ |
279 | #define CFTYPE_ONLY_ON_ROOT (1U << 0) /* only create on root cg */ | 396 | #define CFTYPE_ONLY_ON_ROOT (1U << 0) /* only create on root cg */ |
280 | #define CFTYPE_NOT_ON_ROOT (1U << 1) /* don't create on root cg */ | 397 | #define CFTYPE_NOT_ON_ROOT (1U << 1) /* don't create on root cg */ |
398 | #define CFTYPE_INSANE (1U << 2) /* don't create if sane_behavior */ | ||
281 | 399 | ||
282 | #define MAX_CFTYPE_NAME 64 | 400 | #define MAX_CFTYPE_NAME 64 |
283 | 401 | ||
@@ -304,9 +422,6 @@ struct cftype { | |||
304 | /* CFTYPE_* flags */ | 422 | /* CFTYPE_* flags */ |
305 | unsigned int flags; | 423 | unsigned int flags; |
306 | 424 | ||
307 | /* file xattrs */ | ||
308 | struct simple_xattrs xattrs; | ||
309 | |||
310 | int (*open)(struct inode *inode, struct file *file); | 425 | int (*open)(struct inode *inode, struct file *file); |
311 | ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft, | 426 | ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft, |
312 | struct file *file, | 427 | struct file *file, |
@@ -404,18 +519,31 @@ struct cgroup_scanner { | |||
404 | void *data; | 519 | void *data; |
405 | }; | 520 | }; |
406 | 521 | ||
522 | /* | ||
523 | * See the comment above CGRP_ROOT_SANE_BEHAVIOR for details. This | ||
524 | * function can be called as long as @cgrp is accessible. | ||
525 | */ | ||
526 | static inline bool cgroup_sane_behavior(const struct cgroup *cgrp) | ||
527 | { | ||
528 | return cgrp->root->flags & CGRP_ROOT_SANE_BEHAVIOR; | ||
529 | } | ||
530 | |||
531 | /* Caller should hold rcu_read_lock() */ | ||
532 | static inline const char *cgroup_name(const struct cgroup *cgrp) | ||
533 | { | ||
534 | return rcu_dereference(cgrp->name)->name; | ||
535 | } | ||
536 | |||
407 | int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts); | 537 | int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts); |
408 | int cgroup_rm_cftypes(struct cgroup_subsys *ss, struct cftype *cfts); | 538 | int cgroup_rm_cftypes(struct cgroup_subsys *ss, struct cftype *cfts); |
409 | 539 | ||
410 | int cgroup_is_removed(const struct cgroup *cgrp); | 540 | int cgroup_is_removed(const struct cgroup *cgrp); |
541 | bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor); | ||
411 | 542 | ||
412 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); | 543 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); |
413 | 544 | ||
414 | int cgroup_task_count(const struct cgroup *cgrp); | 545 | int cgroup_task_count(const struct cgroup *cgrp); |
415 | 546 | ||
416 | /* Return true if cgrp is a descendant of the task's cgroup */ | ||
417 | int cgroup_is_descendant(const struct cgroup *cgrp, struct task_struct *task); | ||
418 | |||
419 | /* | 547 | /* |
420 | * Control Group taskset, used to pass around set of tasks to cgroup_subsys | 548 | * Control Group taskset, used to pass around set of tasks to cgroup_subsys |
421 | * methods. | 549 | * methods. |
@@ -458,7 +586,6 @@ struct cgroup_subsys { | |||
458 | void (*bind)(struct cgroup *root); | 586 | void (*bind)(struct cgroup *root); |
459 | 587 | ||
460 | int subsys_id; | 588 | int subsys_id; |
461 | int active; | ||
462 | int disabled; | 589 | int disabled; |
463 | int early_init; | 590 | int early_init; |
464 | /* | 591 | /* |
@@ -523,10 +650,16 @@ static inline struct cgroup_subsys_state *cgroup_subsys_state( | |||
523 | * rcu_dereference_check() conditions, such as locks used during the | 650 | * rcu_dereference_check() conditions, such as locks used during the |
524 | * cgroup_subsys::attach() methods. | 651 | * cgroup_subsys::attach() methods. |
525 | */ | 652 | */ |
653 | #ifdef CONFIG_PROVE_RCU | ||
654 | extern struct mutex cgroup_mutex; | ||
526 | #define task_subsys_state_check(task, subsys_id, __c) \ | 655 | #define task_subsys_state_check(task, subsys_id, __c) \ |
527 | rcu_dereference_check(task->cgroups->subsys[subsys_id], \ | 656 | rcu_dereference_check((task)->cgroups->subsys[(subsys_id)], \ |
528 | lockdep_is_held(&task->alloc_lock) || \ | 657 | lockdep_is_held(&(task)->alloc_lock) || \ |
529 | cgroup_lock_is_held() || (__c)) | 658 | lockdep_is_held(&cgroup_mutex) || (__c)) |
659 | #else | ||
660 | #define task_subsys_state_check(task, subsys_id, __c) \ | ||
661 | rcu_dereference((task)->cgroups->subsys[(subsys_id)]) | ||
662 | #endif | ||
530 | 663 | ||
531 | static inline struct cgroup_subsys_state * | 664 | static inline struct cgroup_subsys_state * |
532 | task_subsys_state(struct task_struct *task, int subsys_id) | 665 | task_subsys_state(struct task_struct *task, int subsys_id) |
@@ -661,8 +794,8 @@ struct task_struct *cgroup_iter_next(struct cgroup *cgrp, | |||
661 | struct cgroup_iter *it); | 794 | struct cgroup_iter *it); |
662 | void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it); | 795 | void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it); |
663 | int cgroup_scan_tasks(struct cgroup_scanner *scan); | 796 | int cgroup_scan_tasks(struct cgroup_scanner *scan); |
664 | int cgroup_attach_task(struct cgroup *, struct task_struct *); | ||
665 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); | 797 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); |
798 | int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); | ||
666 | 799 | ||
667 | /* | 800 | /* |
668 | * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works | 801 | * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works |
@@ -687,13 +820,6 @@ void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css); | |||
687 | 820 | ||
688 | struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id); | 821 | struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id); |
689 | 822 | ||
690 | /* | ||
691 | * Get a cgroup whose id is greater than or equal to id under tree of root. | ||
692 | * Returning a cgroup_subsys_state or NULL. | ||
693 | */ | ||
694 | struct cgroup_subsys_state *css_get_next(struct cgroup_subsys *ss, int id, | ||
695 | struct cgroup_subsys_state *root, int *foundid); | ||
696 | |||
697 | /* Returns true if root is ancestor of cg */ | 823 | /* Returns true if root is ancestor of cg */ |
698 | bool css_is_ancestor(struct cgroup_subsys_state *cg, | 824 | bool css_is_ancestor(struct cgroup_subsys_state *cg, |
699 | const struct cgroup_subsys_state *root); | 825 | const struct cgroup_subsys_state *root); |