cgroup: implement cgroup_is_descendant()
[deliverable/linux.git] / include / linux / cgroup.h
1 #ifndef _LINUX_CGROUP_H
2 #define _LINUX_CGROUP_H
3 /*
4 * cgroup interface
5 *
6 * Copyright (C) 2003 BULL SA
7 * Copyright (C) 2004-2006 Silicon Graphics, Inc.
8 *
9 */
10
11 #include <linux/sched.h>
12 #include <linux/cpumask.h>
13 #include <linux/nodemask.h>
14 #include <linux/rcupdate.h>
15 #include <linux/rculist.h>
16 #include <linux/cgroupstats.h>
17 #include <linux/prio_heap.h>
18 #include <linux/rwsem.h>
19 #include <linux/idr.h>
20 #include <linux/workqueue.h>
21 #include <linux/xattr.h>
22
23 #ifdef CONFIG_CGROUPS
24
25 struct cgroupfs_root;
26 struct cgroup_subsys;
27 struct inode;
28 struct cgroup;
29 struct css_id;
30
31 extern int cgroup_init_early(void);
32 extern int cgroup_init(void);
33 extern void cgroup_fork(struct task_struct *p);
34 extern void cgroup_post_fork(struct task_struct *p);
35 extern void cgroup_exit(struct task_struct *p, int run_callbacks);
36 extern int cgroupstats_build(struct cgroupstats *stats,
37 struct dentry *dentry);
38 extern int cgroup_load_subsys(struct cgroup_subsys *ss);
39 extern void cgroup_unload_subsys(struct cgroup_subsys *ss);
40
41 extern const struct file_operations proc_cgroup_operations;
42
43 /*
44 * Define the enumeration of all cgroup subsystems.
45 *
46 * We define ids for builtin subsystems and then modular ones.
47 */
48 #define SUBSYS(_x) _x ## _subsys_id,
49 enum cgroup_subsys_id {
50 #define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option)
51 #include <linux/cgroup_subsys.h>
52 #undef IS_SUBSYS_ENABLED
53 CGROUP_BUILTIN_SUBSYS_COUNT,
54
55 __CGROUP_SUBSYS_TEMP_PLACEHOLDER = CGROUP_BUILTIN_SUBSYS_COUNT - 1,
56
57 #define IS_SUBSYS_ENABLED(option) IS_MODULE(option)
58 #include <linux/cgroup_subsys.h>
59 #undef IS_SUBSYS_ENABLED
60 CGROUP_SUBSYS_COUNT,
61 };
62 #undef SUBSYS
63
64 /* Per-subsystem/per-cgroup state maintained by the system. */
65 struct cgroup_subsys_state {
66 /*
67 * The cgroup that this subsystem is attached to. Useful
68 * for subsystems that want to know about the cgroup
69 * hierarchy structure
70 */
71 struct cgroup *cgroup;
72
73 /*
74 * State maintained by the cgroup system to allow subsystems
75 * to be "busy". Should be accessed via css_get(),
76 * css_tryget() and css_put().
77 */
78
79 atomic_t refcnt;
80
81 unsigned long flags;
82 /* ID for this css, if possible */
83 struct css_id __rcu *id;
84
85 /* Used to put @cgroup->dentry on the last css_put() */
86 struct work_struct dput_work;
87 };
88
89 /* bits in struct cgroup_subsys_state flags field */
90 enum {
91 CSS_ROOT = (1 << 0), /* this CSS is the root of the subsystem */
92 CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */
93 };
94
95 /* Caller must verify that the css is not for root cgroup */
96 static inline void __css_get(struct cgroup_subsys_state *css, int count)
97 {
98 atomic_add(count, &css->refcnt);
99 }
100
101 /*
102 * Call css_get() to hold a reference on the css; it can be used
103 * for a reference obtained via:
104 * - an existing ref-counted reference to the css
105 * - task->cgroups for a locked task
106 */
107
108 static inline void css_get(struct cgroup_subsys_state *css)
109 {
110 /* We don't need to reference count the root state */
111 if (!(css->flags & CSS_ROOT))
112 __css_get(css, 1);
113 }
114
115 /*
116 * Call css_tryget() to take a reference on a css if your existing
117 * (known-valid) reference isn't already ref-counted. Returns false if
118 * the css has been destroyed.
119 */
120
121 extern bool __css_tryget(struct cgroup_subsys_state *css);
122 static inline bool css_tryget(struct cgroup_subsys_state *css)
123 {
124 if (css->flags & CSS_ROOT)
125 return true;
126 return __css_tryget(css);
127 }
128
129 /*
130 * css_put() should be called to release a reference taken by
131 * css_get() or css_tryget()
132 */
133
134 extern void __css_put(struct cgroup_subsys_state *css);
135 static inline void css_put(struct cgroup_subsys_state *css)
136 {
137 if (!(css->flags & CSS_ROOT))
138 __css_put(css);
139 }
140
141 /* bits in struct cgroup flags field */
142 enum {
143 /* Control Group is dead */
144 CGRP_REMOVED,
145 /*
146 * Control Group has previously had a child cgroup or a task,
147 * but no longer (only if CGRP_NOTIFY_ON_RELEASE is set)
148 */
149 CGRP_RELEASABLE,
150 /* Control Group requires release notifications to userspace */
151 CGRP_NOTIFY_ON_RELEASE,
152 /*
153 * Clone the parent's configuration when creating a new child
154 * cpuset cgroup. For historical reasons, this option can be
155 * specified at mount time and thus is implemented here.
156 */
157 CGRP_CPUSET_CLONE_CHILDREN,
158 };
159
160 struct cgroup_name {
161 struct rcu_head rcu_head;
162 char name[];
163 };
164
165 struct cgroup {
166 unsigned long flags; /* "unsigned long" so bitops work */
167
168 /*
169 * count users of this cgroup. >0 means busy, but doesn't
170 * necessarily indicate the number of tasks in the cgroup
171 */
172 atomic_t count;
173
174 int id; /* ida allocated in-hierarchy ID */
175
176 /*
177 * We link our 'sibling' struct into our parent's 'children'.
178 * Our children link their 'sibling' into our 'children'.
179 */
180 struct list_head sibling; /* my parent's children */
181 struct list_head children; /* my children */
182 struct list_head files; /* my files */
183
184 struct cgroup *parent; /* my parent */
185 struct dentry *dentry; /* cgroup fs entry, RCU protected */
186
187 /*
188 * This is a copy of dentry->d_name, and it's needed because
189 * we can't use dentry->d_name in cgroup_path().
190 *
191 * You must acquire rcu_read_lock() to access cgrp->name, and
192 * the only place that can change it is rename(), which is
193 * protected by parent dir's i_mutex.
194 *
195 * Normally you should use cgroup_name() wrapper rather than
196 * access it directly.
197 */
198 struct cgroup_name __rcu *name;
199
200 /* Private pointers for each registered subsystem */
201 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
202
203 struct cgroupfs_root *root;
204 struct cgroup *top_cgroup;
205
206 /*
207 * List of cg_cgroup_links pointing at css_sets with
208 * tasks in this cgroup. Protected by css_set_lock
209 */
210 struct list_head css_sets;
211
212 struct list_head allcg_node; /* cgroupfs_root->allcg_list */
213 struct list_head cft_q_node; /* used during cftype add/rm */
214
215 /*
216 * Linked list running through all cgroups that can
217 * potentially be reaped by the release agent. Protected by
218 * release_list_lock
219 */
220 struct list_head release_list;
221
222 /*
223 * list of pidlists, up to two for each namespace (one for procs, one
224 * for tasks); created on demand.
225 */
226 struct list_head pidlists;
227 struct mutex pidlist_mutex;
228
229 /* For RCU-protected deletion */
230 struct rcu_head rcu_head;
231 struct work_struct free_work;
232
233 /* List of events which userspace want to receive */
234 struct list_head event_list;
235 spinlock_t event_list_lock;
236
237 /* directory xattrs */
238 struct simple_xattrs xattrs;
239 };
240
241 /*
242 * A css_set is a structure holding pointers to a set of
243 * cgroup_subsys_state objects. This saves space in the task struct
244 * object and speeds up fork()/exit(), since a single inc/dec and a
245 * list_add()/del() can bump the reference count on the entire cgroup
246 * set for a task.
247 */
248
249 struct css_set {
250
251 /* Reference count */
252 atomic_t refcount;
253
254 /*
255 * List running through all cgroup groups in the same hash
256 * slot. Protected by css_set_lock
257 */
258 struct hlist_node hlist;
259
260 /*
261 * List running through all tasks using this cgroup
262 * group. Protected by css_set_lock
263 */
264 struct list_head tasks;
265
266 /*
267 * List of cg_cgroup_link objects on link chains from
268 * cgroups referenced from this css_set. Protected by
269 * css_set_lock
270 */
271 struct list_head cg_links;
272
273 /*
274 * Set of subsystem states, one for each subsystem. This array
275 * is immutable after creation apart from the init_css_set
276 * during subsystem registration (at boot time) and modular subsystem
277 * loading/unloading.
278 */
279 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
280
281 /* For RCU-protected deletion */
282 struct rcu_head rcu_head;
283 };
284
285 /*
286 * cgroup_map_cb is an abstract callback API for reporting map-valued
287 * control files
288 */
289
290 struct cgroup_map_cb {
291 int (*fill)(struct cgroup_map_cb *cb, const char *key, u64 value);
292 void *state;
293 };
294
295 /*
296 * struct cftype: handler definitions for cgroup control files
297 *
298 * When reading/writing to a file:
299 * - the cgroup to use is file->f_dentry->d_parent->d_fsdata
300 * - the 'cftype' of the file is file->f_dentry->d_fsdata
301 */
302
303 /* cftype->flags */
304 #define CFTYPE_ONLY_ON_ROOT (1U << 0) /* only create on root cg */
305 #define CFTYPE_NOT_ON_ROOT (1U << 1) /* don't create on root cg */
306
307 #define MAX_CFTYPE_NAME 64
308
309 struct cftype {
310 /*
311 * By convention, the name should begin with the name of the
312 * subsystem, followed by a period. Zero length string indicates
313 * end of cftype array.
314 */
315 char name[MAX_CFTYPE_NAME];
316 int private;
317 /*
318 * If not 0, file mode is set to this value, otherwise it will
319 * be figured out automatically
320 */
321 umode_t mode;
322
323 /*
324 * If non-zero, defines the maximum length of string that can
325 * be passed to write_string; defaults to 64
326 */
327 size_t max_write_len;
328
329 /* CFTYPE_* flags */
330 unsigned int flags;
331
332 /* file xattrs */
333 struct simple_xattrs xattrs;
334
335 int (*open)(struct inode *inode, struct file *file);
336 ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
337 struct file *file,
338 char __user *buf, size_t nbytes, loff_t *ppos);
339 /*
340 * read_u64() is a shortcut for the common case of returning a
341 * single integer. Use it in place of read()
342 */
343 u64 (*read_u64)(struct cgroup *cgrp, struct cftype *cft);
344 /*
345 * read_s64() is a signed version of read_u64()
346 */
347 s64 (*read_s64)(struct cgroup *cgrp, struct cftype *cft);
348 /*
349 * read_map() is used for defining a map of key/value
350 * pairs. It should call cb->fill(cb, key, value) for each
351 * entry. The key/value pairs (and their ordering) should not
352 * change between reboots.
353 */
354 int (*read_map)(struct cgroup *cont, struct cftype *cft,
355 struct cgroup_map_cb *cb);
356 /*
357 * read_seq_string() is used for outputting a simple sequence
358 * using seqfile.
359 */
360 int (*read_seq_string)(struct cgroup *cont, struct cftype *cft,
361 struct seq_file *m);
362
363 ssize_t (*write)(struct cgroup *cgrp, struct cftype *cft,
364 struct file *file,
365 const char __user *buf, size_t nbytes, loff_t *ppos);
366
367 /*
368 * write_u64() is a shortcut for the common case of accepting
369 * a single integer (as parsed by simple_strtoull) from
370 * userspace. Use in place of write(); return 0 or error.
371 */
372 int (*write_u64)(struct cgroup *cgrp, struct cftype *cft, u64 val);
373 /*
374 * write_s64() is a signed version of write_u64()
375 */
376 int (*write_s64)(struct cgroup *cgrp, struct cftype *cft, s64 val);
377
378 /*
379 * write_string() is passed a nul-terminated kernelspace
380 * buffer of maximum length determined by max_write_len.
381 * Returns 0 or -ve error code.
382 */
383 int (*write_string)(struct cgroup *cgrp, struct cftype *cft,
384 const char *buffer);
385 /*
386 * trigger() callback can be used to get some kick from the
387 * userspace, when the actual string written is not important
388 * at all. The private field can be used to determine the
389 * kick type for multiplexing.
390 */
391 int (*trigger)(struct cgroup *cgrp, unsigned int event);
392
393 int (*release)(struct inode *inode, struct file *file);
394
395 /*
396 * register_event() callback will be used to add new userspace
397 * waiter for changes related to the cftype. Implement it if
398 * you want to provide this functionality. Use eventfd_signal()
399 * on eventfd to send notification to userspace.
400 */
401 int (*register_event)(struct cgroup *cgrp, struct cftype *cft,
402 struct eventfd_ctx *eventfd, const char *args);
403 /*
404 * unregister_event() callback will be called when userspace
405 * closes the eventfd or on cgroup removing.
406 * This callback must be implemented, if you want provide
407 * notification functionality.
408 */
409 void (*unregister_event)(struct cgroup *cgrp, struct cftype *cft,
410 struct eventfd_ctx *eventfd);
411 };
412
413 /*
414 * cftype_sets describe cftypes belonging to a subsystem and are chained at
415 * cgroup_subsys->cftsets. Each cftset points to an array of cftypes
416 * terminated by zero length name.
417 */
418 struct cftype_set {
419 struct list_head node; /* chained at subsys->cftsets */
420 struct cftype *cfts;
421 };
422
423 struct cgroup_scanner {
424 struct cgroup *cg;
425 int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan);
426 void (*process_task)(struct task_struct *p,
427 struct cgroup_scanner *scan);
428 struct ptr_heap *heap;
429 void *data;
430 };
431
432 /* Caller should hold rcu_read_lock() */
433 static inline const char *cgroup_name(const struct cgroup *cgrp)
434 {
435 return rcu_dereference(cgrp->name)->name;
436 }
437
438 int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
439 int cgroup_rm_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
440
441 int cgroup_is_removed(const struct cgroup *cgrp);
442 bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
443
444 int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
445
446 int cgroup_task_count(const struct cgroup *cgrp);
447
448 /*
449 * Control Group taskset, used to pass around set of tasks to cgroup_subsys
450 * methods.
451 */
452 struct cgroup_taskset;
453 struct task_struct *cgroup_taskset_first(struct cgroup_taskset *tset);
454 struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset);
455 struct cgroup *cgroup_taskset_cur_cgroup(struct cgroup_taskset *tset);
456 int cgroup_taskset_size(struct cgroup_taskset *tset);
457
458 /**
459 * cgroup_taskset_for_each - iterate cgroup_taskset
460 * @task: the loop cursor
461 * @skip_cgrp: skip if task's cgroup matches this, %NULL to iterate through all
462 * @tset: taskset to iterate
463 */
464 #define cgroup_taskset_for_each(task, skip_cgrp, tset) \
465 for ((task) = cgroup_taskset_first((tset)); (task); \
466 (task) = cgroup_taskset_next((tset))) \
467 if (!(skip_cgrp) || \
468 cgroup_taskset_cur_cgroup((tset)) != (skip_cgrp))
469
470 /*
471 * Control Group subsystem type.
472 * See Documentation/cgroups/cgroups.txt for details
473 */
474
475 struct cgroup_subsys {
476 struct cgroup_subsys_state *(*css_alloc)(struct cgroup *cgrp);
477 int (*css_online)(struct cgroup *cgrp);
478 void (*css_offline)(struct cgroup *cgrp);
479 void (*css_free)(struct cgroup *cgrp);
480
481 int (*can_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
482 void (*cancel_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
483 void (*attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
484 void (*fork)(struct task_struct *task);
485 void (*exit)(struct cgroup *cgrp, struct cgroup *old_cgrp,
486 struct task_struct *task);
487 int subsys_id;
488 int active;
489 int disabled;
490 int early_init;
491 /*
492 * True if this subsys uses ID. ID is not available before cgroup_init()
493 * (not available in early_init time.)
494 */
495 bool use_id;
496
497 /*
498 * If %false, this subsystem is properly hierarchical -
499 * configuration, resource accounting and restriction on a parent
500 * cgroup cover those of its children. If %true, hierarchy support
501 * is broken in some ways - some subsystems ignore hierarchy
502 * completely while others are only implemented half-way.
503 *
504 * It's now disallowed to create nested cgroups if the subsystem is
505 * broken and cgroup core will emit a warning message on such
506 * cases. Eventually, all subsystems will be made properly
507 * hierarchical and this will go away.
508 */
509 bool broken_hierarchy;
510 bool warned_broken_hierarchy;
511
512 #define MAX_CGROUP_TYPE_NAMELEN 32
513 const char *name;
514
515 /*
516 * Link to parent, and list entry in parent's children.
517 * Protected by cgroup_lock()
518 */
519 struct cgroupfs_root *root;
520 struct list_head sibling;
521 /* used when use_id == true */
522 struct idr idr;
523 spinlock_t id_lock;
524
525 /* list of cftype_sets */
526 struct list_head cftsets;
527
528 /* base cftypes, automatically [de]registered with subsys itself */
529 struct cftype *base_cftypes;
530 struct cftype_set base_cftset;
531
532 /* should be defined only by modular subsystems */
533 struct module *module;
534 };
535
536 #define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys;
537 #define IS_SUBSYS_ENABLED(option) IS_BUILTIN(option)
538 #include <linux/cgroup_subsys.h>
539 #undef IS_SUBSYS_ENABLED
540 #undef SUBSYS
541
542 static inline struct cgroup_subsys_state *cgroup_subsys_state(
543 struct cgroup *cgrp, int subsys_id)
544 {
545 return cgrp->subsys[subsys_id];
546 }
547
548 /*
549 * function to get the cgroup_subsys_state which allows for extra
550 * rcu_dereference_check() conditions, such as locks used during the
551 * cgroup_subsys::attach() methods.
552 */
553 #ifdef CONFIG_PROVE_RCU
554 extern struct mutex cgroup_mutex;
555 #define task_subsys_state_check(task, subsys_id, __c) \
556 rcu_dereference_check((task)->cgroups->subsys[(subsys_id)], \
557 lockdep_is_held(&(task)->alloc_lock) || \
558 lockdep_is_held(&cgroup_mutex) || (__c))
559 #else
560 #define task_subsys_state_check(task, subsys_id, __c) \
561 rcu_dereference((task)->cgroups->subsys[(subsys_id)])
562 #endif
563
564 static inline struct cgroup_subsys_state *
565 task_subsys_state(struct task_struct *task, int subsys_id)
566 {
567 return task_subsys_state_check(task, subsys_id, false);
568 }
569
570 static inline struct cgroup* task_cgroup(struct task_struct *task,
571 int subsys_id)
572 {
573 return task_subsys_state(task, subsys_id)->cgroup;
574 }
575
576 /**
577 * cgroup_for_each_child - iterate through children of a cgroup
578 * @pos: the cgroup * to use as the loop cursor
579 * @cgroup: cgroup whose children to walk
580 *
581 * Walk @cgroup's children. Must be called under rcu_read_lock(). A child
582 * cgroup which hasn't finished ->css_online() or already has finished
583 * ->css_offline() may show up during traversal and it's each subsystem's
584 * responsibility to verify that each @pos is alive.
585 *
586 * If a subsystem synchronizes against the parent in its ->css_online() and
587 * before starting iterating, a cgroup which finished ->css_online() is
588 * guaranteed to be visible in the future iterations.
589 */
590 #define cgroup_for_each_child(pos, cgroup) \
591 list_for_each_entry_rcu(pos, &(cgroup)->children, sibling)
592
593 struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,
594 struct cgroup *cgroup);
595 struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos);
596
597 /**
598 * cgroup_for_each_descendant_pre - pre-order walk of a cgroup's descendants
599 * @pos: the cgroup * to use as the loop cursor
600 * @cgroup: cgroup whose descendants to walk
601 *
602 * Walk @cgroup's descendants. Must be called under rcu_read_lock(). A
603 * descendant cgroup which hasn't finished ->css_online() or already has
604 * finished ->css_offline() may show up during traversal and it's each
605 * subsystem's responsibility to verify that each @pos is alive.
606 *
607 * If a subsystem synchronizes against the parent in its ->css_online() and
608 * before starting iterating, and synchronizes against @pos on each
609 * iteration, any descendant cgroup which finished ->css_offline() is
610 * guaranteed to be visible in the future iterations.
611 *
612 * In other words, the following guarantees that a descendant can't escape
613 * state updates of its ancestors.
614 *
615 * my_online(@cgrp)
616 * {
617 * Lock @cgrp->parent and @cgrp;
618 * Inherit state from @cgrp->parent;
619 * Unlock both.
620 * }
621 *
622 * my_update_state(@cgrp)
623 * {
624 * Lock @cgrp;
625 * Update @cgrp's state;
626 * Unlock @cgrp;
627 *
628 * cgroup_for_each_descendant_pre(@pos, @cgrp) {
629 * Lock @pos;
630 * Verify @pos is alive and inherit state from @pos->parent;
631 * Unlock @pos;
632 * }
633 * }
634 *
635 * As long as the inheriting step, including checking the parent state, is
636 * enclosed inside @pos locking, double-locking the parent isn't necessary
637 * while inheriting. The state update to the parent is guaranteed to be
638 * visible by walking order and, as long as inheriting operations to the
639 * same @pos are atomic to each other, multiple updates racing each other
640 * still result in the correct state. It's guaranateed that at least one
641 * inheritance happens for any cgroup after the latest update to its
642 * parent.
643 *
644 * If checking parent's state requires locking the parent, each inheriting
645 * iteration should lock and unlock both @pos->parent and @pos.
646 *
647 * Alternatively, a subsystem may choose to use a single global lock to
648 * synchronize ->css_online() and ->css_offline() against tree-walking
649 * operations.
650 */
651 #define cgroup_for_each_descendant_pre(pos, cgroup) \
652 for (pos = cgroup_next_descendant_pre(NULL, (cgroup)); (pos); \
653 pos = cgroup_next_descendant_pre((pos), (cgroup)))
654
655 struct cgroup *cgroup_next_descendant_post(struct cgroup *pos,
656 struct cgroup *cgroup);
657
658 /**
659 * cgroup_for_each_descendant_post - post-order walk of a cgroup's descendants
660 * @pos: the cgroup * to use as the loop cursor
661 * @cgroup: cgroup whose descendants to walk
662 *
663 * Similar to cgroup_for_each_descendant_pre() but performs post-order
664 * traversal instead. Note that the walk visibility guarantee described in
665 * pre-order walk doesn't apply the same to post-order walks.
666 */
667 #define cgroup_for_each_descendant_post(pos, cgroup) \
668 for (pos = cgroup_next_descendant_post(NULL, (cgroup)); (pos); \
669 pos = cgroup_next_descendant_post((pos), (cgroup)))
670
671 /* A cgroup_iter should be treated as an opaque object */
672 struct cgroup_iter {
673 struct list_head *cg_link;
674 struct list_head *task;
675 };
676
677 /*
678 * To iterate across the tasks in a cgroup:
679 *
680 * 1) call cgroup_iter_start to initialize an iterator
681 *
682 * 2) call cgroup_iter_next() to retrieve member tasks until it
683 * returns NULL or until you want to end the iteration
684 *
685 * 3) call cgroup_iter_end() to destroy the iterator.
686 *
687 * Or, call cgroup_scan_tasks() to iterate through every task in a
688 * cgroup - cgroup_scan_tasks() holds the css_set_lock when calling
689 * the test_task() callback, but not while calling the process_task()
690 * callback.
691 */
692 void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it);
693 struct task_struct *cgroup_iter_next(struct cgroup *cgrp,
694 struct cgroup_iter *it);
695 void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it);
696 int cgroup_scan_tasks(struct cgroup_scanner *scan);
697 int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
698 int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
699
700 /*
701 * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works
702 * if cgroup_subsys.use_id == true. It can be used for looking up and scanning.
703 * CSS ID is assigned at cgroup allocation (create) automatically
704 * and removed when subsys calls free_css_id() function. This is because
705 * the lifetime of cgroup_subsys_state is subsys's matter.
706 *
707 * Looking up and scanning function should be called under rcu_read_lock().
708 * Taking cgroup_mutex is not necessary for following calls.
709 * But the css returned by this routine can be "not populated yet" or "being
710 * destroyed". The caller should check css and cgroup's status.
711 */
712
713 /*
714 * Typically Called at ->destroy(), or somewhere the subsys frees
715 * cgroup_subsys_state.
716 */
717 void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css);
718
719 /* Find a cgroup_subsys_state which has given ID */
720
721 struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id);
722
723 /*
724 * Get a cgroup whose id is greater than or equal to id under tree of root.
725 * Returning a cgroup_subsys_state or NULL.
726 */
727 struct cgroup_subsys_state *css_get_next(struct cgroup_subsys *ss, int id,
728 struct cgroup_subsys_state *root, int *foundid);
729
730 /* Returns true if root is ancestor of cg */
731 bool css_is_ancestor(struct cgroup_subsys_state *cg,
732 const struct cgroup_subsys_state *root);
733
734 /* Get id and depth of css */
735 unsigned short css_id(struct cgroup_subsys_state *css);
736 unsigned short css_depth(struct cgroup_subsys_state *css);
737 struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id);
738
739 #else /* !CONFIG_CGROUPS */
740
741 static inline int cgroup_init_early(void) { return 0; }
742 static inline int cgroup_init(void) { return 0; }
743 static inline void cgroup_fork(struct task_struct *p) {}
744 static inline void cgroup_post_fork(struct task_struct *p) {}
745 static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
746
747 static inline void cgroup_lock(void) {}
748 static inline void cgroup_unlock(void) {}
749 static inline int cgroupstats_build(struct cgroupstats *stats,
750 struct dentry *dentry)
751 {
752 return -EINVAL;
753 }
754
755 /* No cgroups - nothing to do */
756 static inline int cgroup_attach_task_all(struct task_struct *from,
757 struct task_struct *t)
758 {
759 return 0;
760 }
761
762 #endif /* !CONFIG_CGROUPS */
763
764 #endif /* _LINUX_CGROUP_H */
This page took 0.046983 seconds and 6 git commands to generate.