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