cgroup.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. #include <linux/sched.h>
  11. #include <linux/cpumask.h>
  12. #include <linux/nodemask.h>
  13. #include <linux/rcupdate.h>
  14. #include <linux/cgroupstats.h>
  15. #include <linux/prio_heap.h>
  16. #include <linux/rwsem.h>
  17. #include <linux/idr.h>
  18. #ifdef CONFIG_CGROUPS
  19. struct cgroupfs_root;
  20. struct cgroup_subsys;
  21. struct inode;
  22. struct cgroup;
  23. struct css_id;
  24. extern int cgroup_init_early(void);
  25. extern int cgroup_init(void);
  26. extern void cgroup_lock(void);
  27. extern int cgroup_lock_is_held(void);
  28. extern bool cgroup_lock_live_group(struct cgroup *cgrp);
  29. extern void cgroup_unlock(void);
  30. extern void cgroup_fork(struct task_struct *p);
  31. extern void cgroup_post_fork(struct task_struct *p);
  32. extern void cgroup_exit(struct task_struct *p, int run_callbacks);
  33. extern int cgroupstats_build(struct cgroupstats *stats,
  34. struct dentry *dentry);
  35. extern int cgroup_load_subsys(struct cgroup_subsys *ss);
  36. extern void cgroup_unload_subsys(struct cgroup_subsys *ss);
  37. extern const struct file_operations proc_cgroup_operations;
  38. /* Define the enumeration of all builtin cgroup subsystems */
  39. #define SUBSYS(_x) _x ## _subsys_id,
  40. enum cgroup_subsys_id {
  41. #include <linux/cgroup_subsys.h>
  42. CGROUP_BUILTIN_SUBSYS_COUNT
  43. };
  44. #undef SUBSYS
  45. /*
  46. * This define indicates the maximum number of subsystems that can be loaded
  47. * at once. We limit to this many since cgroupfs_root has subsys_bits to keep
  48. * track of all of them.
  49. */
  50. #define CGROUP_SUBSYS_COUNT (BITS_PER_BYTE*sizeof(unsigned long))
  51. /* Per-subsystem/per-cgroup state maintained by the system. */
  52. struct cgroup_subsys_state {
  53. /*
  54. * The cgroup that this subsystem is attached to. Useful
  55. * for subsystems that want to know about the cgroup
  56. * hierarchy structure
  57. */
  58. struct cgroup *cgroup;
  59. /*
  60. * State maintained by the cgroup system to allow subsystems
  61. * to be "busy". Should be accessed via css_get(),
  62. * css_tryget() and and css_put().
  63. */
  64. atomic_t refcnt;
  65. unsigned long flags;
  66. /* ID for this css, if possible */
  67. struct css_id __rcu *id;
  68. };
  69. /* bits in struct cgroup_subsys_state flags field */
  70. enum {
  71. CSS_ROOT, /* This CSS is the root of the subsystem */
  72. CSS_REMOVED, /* This CSS is dead */
  73. };
  74. /*
  75. * Call css_get() to hold a reference on the css; it can be used
  76. * for a reference obtained via:
  77. * - an existing ref-counted reference to the css
  78. * - task->cgroups for a locked task
  79. */
  80. extern void __css_get(struct cgroup_subsys_state *css, int count);
  81. static inline void css_get(struct cgroup_subsys_state *css)
  82. {
  83. /* We don't need to reference count the root state */
  84. if (!test_bit(CSS_ROOT, &css->flags))
  85. __css_get(css, 1);
  86. }
  87. static inline bool css_is_removed(struct cgroup_subsys_state *css)
  88. {
  89. return test_bit(CSS_REMOVED, &css->flags);
  90. }
  91. /*
  92. * Call css_tryget() to take a reference on a css if your existing
  93. * (known-valid) reference isn't already ref-counted. Returns false if
  94. * the css has been destroyed.
  95. */
  96. static inline bool css_tryget(struct cgroup_subsys_state *css)
  97. {
  98. if (test_bit(CSS_ROOT, &css->flags))
  99. return true;
  100. while (!atomic_inc_not_zero(&css->refcnt)) {
  101. if (test_bit(CSS_REMOVED, &css->flags))
  102. return false;
  103. cpu_relax();
  104. }
  105. return true;
  106. }
  107. /*
  108. * css_put() should be called to release a reference taken by
  109. * css_get() or css_tryget()
  110. */
  111. extern void __css_put(struct cgroup_subsys_state *css, int count);
  112. static inline void css_put(struct cgroup_subsys_state *css)
  113. {
  114. if (!test_bit(CSS_ROOT, &css->flags))
  115. __css_put(css, 1);
  116. }
  117. /* bits in struct cgroup flags field */
  118. enum {
  119. /* Control Group is dead */
  120. CGRP_REMOVED,
  121. /* Control Group has ever had a child cgroup or a task */
  122. CGRP_RELEASABLE,
  123. /* Control Group requires release notifications to userspace */
  124. CGRP_NOTIFY_ON_RELEASE,
  125. /*
  126. * A thread in rmdir() is wating for this cgroup.
  127. */
  128. CGRP_WAIT_ON_RMDIR,
  129. /*
  130. * Clone cgroup values when creating a new child cgroup
  131. */
  132. CGRP_CLONE_CHILDREN,
  133. };
  134. struct cgroup {
  135. unsigned long flags; /* "unsigned long" so bitops work */
  136. /*
  137. * count users of this cgroup. >0 means busy, but doesn't
  138. * necessarily indicate the number of tasks in the cgroup
  139. */
  140. atomic_t count;
  141. /*
  142. * We link our 'sibling' struct into our parent's 'children'.
  143. * Our children link their 'sibling' into our 'children'.
  144. */
  145. struct list_head sibling; /* my parent's children */
  146. struct list_head children; /* my children */
  147. struct cgroup *parent; /* my parent */
  148. struct dentry __rcu *dentry; /* cgroup fs entry, RCU protected */
  149. /* Private pointers for each registered subsystem */
  150. struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
  151. struct cgroupfs_root *root;
  152. struct cgroup *top_cgroup;
  153. /*
  154. * List of cg_cgroup_links pointing at css_sets with
  155. * tasks in this cgroup. Protected by css_set_lock
  156. */
  157. struct list_head css_sets;
  158. /*
  159. * Linked list running through all cgroups that can
  160. * potentially be reaped by the release agent. Protected by
  161. * release_list_lock
  162. */
  163. struct list_head release_list;
  164. /*
  165. * list of pidlists, up to two for each namespace (one for procs, one
  166. * for tasks); created on demand.
  167. */
  168. struct list_head pidlists;
  169. struct mutex pidlist_mutex;
  170. /* For RCU-protected deletion */
  171. struct rcu_head rcu_head;
  172. /* List of events which userspace want to receive */
  173. struct list_head event_list;
  174. spinlock_t event_list_lock;
  175. };
  176. /*
  177. * A css_set is a structure holding pointers to a set of
  178. * cgroup_subsys_state objects. This saves space in the task struct
  179. * object and speeds up fork()/exit(), since a single inc/dec and a
  180. * list_add()/del() can bump the reference count on the entire cgroup
  181. * set for a task.
  182. */
  183. struct css_set {
  184. /* Reference count */
  185. atomic_t refcount;
  186. /*
  187. * List running through all cgroup groups in the same hash
  188. * slot. Protected by css_set_lock
  189. */
  190. struct hlist_node hlist;
  191. /*
  192. * List running through all tasks using this cgroup
  193. * group. Protected by css_set_lock
  194. */
  195. struct list_head tasks;
  196. /*
  197. * List of cg_cgroup_link objects on link chains from
  198. * cgroups referenced from this css_set. Protected by
  199. * css_set_lock
  200. */
  201. struct list_head cg_links;
  202. /*
  203. * Set of subsystem states, one for each subsystem. This array
  204. * is immutable after creation apart from the init_css_set
  205. * during subsystem registration (at boot time) and modular subsystem
  206. * loading/unloading.
  207. */
  208. struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
  209. /* For RCU-protected deletion */
  210. struct rcu_head rcu_head;
  211. struct work_struct work;
  212. };
  213. /*
  214. * cgroup_map_cb is an abstract callback API for reporting map-valued
  215. * control files
  216. */
  217. struct cgroup_map_cb {
  218. int (*fill)(struct cgroup_map_cb *cb, const char *key, u64 value);
  219. void *state;
  220. };
  221. /*
  222. * struct cftype: handler definitions for cgroup control files
  223. *
  224. * When reading/writing to a file:
  225. * - the cgroup to use is file->f_dentry->d_parent->d_fsdata
  226. * - the 'cftype' of the file is file->f_dentry->d_fsdata
  227. */
  228. #define MAX_CFTYPE_NAME 64
  229. struct cftype {
  230. /*
  231. * By convention, the name should begin with the name of the
  232. * subsystem, followed by a period
  233. */
  234. char name[MAX_CFTYPE_NAME];
  235. int private;
  236. /*
  237. * If not 0, file mode is set to this value, otherwise it will
  238. * be figured out automatically
  239. */
  240. umode_t mode;
  241. /*
  242. * If non-zero, defines the maximum length of string that can
  243. * be passed to write_string; defaults to 64
  244. */
  245. size_t max_write_len;
  246. int (*open)(struct inode *inode, struct file *file);
  247. ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
  248. struct file *file,
  249. char __user *buf, size_t nbytes, loff_t *ppos);
  250. /*
  251. * read_u64() is a shortcut for the common case of returning a
  252. * single integer. Use it in place of read()
  253. */
  254. u64 (*read_u64)(struct cgroup *cgrp, struct cftype *cft);
  255. /*
  256. * read_s64() is a signed version of read_u64()
  257. */
  258. s64 (*read_s64)(struct cgroup *cgrp, struct cftype *cft);
  259. /*
  260. * read_map() is used for defining a map of key/value
  261. * pairs. It should call cb->fill(cb, key, value) for each
  262. * entry. The key/value pairs (and their ordering) should not
  263. * change between reboots.
  264. */
  265. int (*read_map)(struct cgroup *cont, struct cftype *cft,
  266. struct cgroup_map_cb *cb);
  267. /*
  268. * read_seq_string() is used for outputting a simple sequence
  269. * using seqfile.
  270. */
  271. int (*read_seq_string)(struct cgroup *cont, struct cftype *cft,
  272. struct seq_file *m);
  273. ssize_t (*write)(struct cgroup *cgrp, struct cftype *cft,
  274. struct file *file,
  275. const char __user *buf, size_t nbytes, loff_t *ppos);
  276. /*
  277. * write_u64() is a shortcut for the common case of accepting
  278. * a single integer (as parsed by simple_strtoull) from
  279. * userspace. Use in place of write(); return 0 or error.
  280. */
  281. int (*write_u64)(struct cgroup *cgrp, struct cftype *cft, u64 val);
  282. /*
  283. * write_s64() is a signed version of write_u64()
  284. */
  285. int (*write_s64)(struct cgroup *cgrp, struct cftype *cft, s64 val);
  286. /*
  287. * write_string() is passed a nul-terminated kernelspace
  288. * buffer of maximum length determined by max_write_len.
  289. * Returns 0 or -ve error code.
  290. */
  291. int (*write_string)(struct cgroup *cgrp, struct cftype *cft,
  292. const char *buffer);
  293. /*
  294. * trigger() callback can be used to get some kick from the
  295. * userspace, when the actual string written is not important
  296. * at all. The private field can be used to determine the
  297. * kick type for multiplexing.
  298. */
  299. int (*trigger)(struct cgroup *cgrp, unsigned int event);
  300. int (*release)(struct inode *inode, struct file *file);
  301. /*
  302. * register_event() callback will be used to add new userspace
  303. * waiter for changes related to the cftype. Implement it if
  304. * you want to provide this functionality. Use eventfd_signal()
  305. * on eventfd to send notification to userspace.
  306. */
  307. int (*register_event)(struct cgroup *cgrp, struct cftype *cft,
  308. struct eventfd_ctx *eventfd, const char *args);
  309. /*
  310. * unregister_event() callback will be called when userspace
  311. * closes the eventfd or on cgroup removing.
  312. * This callback must be implemented, if you want provide
  313. * notification functionality.
  314. */
  315. void (*unregister_event)(struct cgroup *cgrp, struct cftype *cft,
  316. struct eventfd_ctx *eventfd);
  317. };
  318. struct cgroup_scanner {
  319. struct cgroup *cg;
  320. int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan);
  321. void (*process_task)(struct task_struct *p,
  322. struct cgroup_scanner *scan);
  323. struct ptr_heap *heap;
  324. void *data;
  325. };
  326. /*
  327. * Add a new file to the given cgroup directory. Should only be
  328. * called by subsystems from within a populate() method
  329. */
  330. int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
  331. const struct cftype *cft);
  332. /*
  333. * Add a set of new files to the given cgroup directory. Should
  334. * only be called by subsystems from within a populate() method
  335. */
  336. int cgroup_add_files(struct cgroup *cgrp,
  337. struct cgroup_subsys *subsys,
  338. const struct cftype cft[],
  339. int count);
  340. int cgroup_is_removed(const struct cgroup *cgrp);
  341. int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
  342. int cgroup_task_count(const struct cgroup *cgrp);
  343. /* Return true if cgrp is a descendant of the task's cgroup */
  344. int cgroup_is_descendant(const struct cgroup *cgrp, struct task_struct *task);
  345. /*
  346. * When the subsys has to access css and may add permanent refcnt to css,
  347. * it should take care of racy conditions with rmdir(). Following set of
  348. * functions, is for stop/restart rmdir if necessary.
  349. * Because these will call css_get/put, "css" should be alive css.
  350. *
  351. * cgroup_exclude_rmdir();
  352. * ...do some jobs which may access arbitrary empty cgroup
  353. * cgroup_release_and_wakeup_rmdir();
  354. *
  355. * When someone removes a cgroup while cgroup_exclude_rmdir() holds it,
  356. * it sleeps and cgroup_release_and_wakeup_rmdir() will wake him up.
  357. */
  358. void cgroup_exclude_rmdir(struct cgroup_subsys_state *css);
  359. void cgroup_release_and_wakeup_rmdir(struct cgroup_subsys_state *css);
  360. /*
  361. * Control Group taskset, used to pass around set of tasks to cgroup_subsys
  362. * methods.
  363. */
  364. struct cgroup_taskset;
  365. struct task_struct *cgroup_taskset_first(struct cgroup_taskset *tset);
  366. struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset);
  367. struct cgroup *cgroup_taskset_cur_cgroup(struct cgroup_taskset *tset);
  368. int cgroup_taskset_size(struct cgroup_taskset *tset);
  369. /**
  370. * cgroup_taskset_for_each - iterate cgroup_taskset
  371. * @task: the loop cursor
  372. * @skip_cgrp: skip if task's cgroup matches this, %NULL to iterate through all
  373. * @tset: taskset to iterate
  374. */
  375. #define cgroup_taskset_for_each(task, skip_cgrp, tset) \
  376. for ((task) = cgroup_taskset_first((tset)); (task); \
  377. (task) = cgroup_taskset_next((tset))) \
  378. if (!(skip_cgrp) || \
  379. cgroup_taskset_cur_cgroup((tset)) != (skip_cgrp))
  380. /*
  381. * Control Group subsystem type.
  382. * See Documentation/cgroups/cgroups.txt for details
  383. */
  384. struct cgroup_subsys {
  385. struct cgroup_subsys_state *(*create)(struct cgroup *cgrp);
  386. int (*pre_destroy)(struct cgroup *cgrp);
  387. void (*destroy)(struct cgroup *cgrp);
  388. int (*allow_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
  389. int (*can_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
  390. void (*cancel_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
  391. void (*attach)(struct cgroup *cgrp, struct cgroup_taskset *tset);
  392. void (*fork)(struct task_struct *task);
  393. void (*exit)(struct cgroup *cgrp, struct cgroup *old_cgrp,
  394. struct task_struct *task);
  395. int (*populate)(struct cgroup_subsys *ss, struct cgroup *cgrp);
  396. void (*post_clone)(struct cgroup *cgrp);
  397. void (*bind)(struct cgroup *root);
  398. int subsys_id;
  399. int active;
  400. int disabled;
  401. int early_init;
  402. /*
  403. * True if this subsys uses ID. ID is not available before cgroup_init()
  404. * (not available in early_init time.)
  405. */
  406. bool use_id;
  407. #define MAX_CGROUP_TYPE_NAMELEN 32
  408. const char *name;
  409. /*
  410. * Protects sibling/children links of cgroups in this
  411. * hierarchy, plus protects which hierarchy (or none) the
  412. * subsystem is a part of (i.e. root/sibling). To avoid
  413. * potential deadlocks, the following operations should not be
  414. * undertaken while holding any hierarchy_mutex:
  415. *
  416. * - allocating memory
  417. * - initiating hotplug events
  418. */
  419. struct mutex hierarchy_mutex;
  420. struct lock_class_key subsys_key;
  421. /*
  422. * Link to parent, and list entry in parent's children.
  423. * Protected by this->hierarchy_mutex and cgroup_lock()
  424. */
  425. struct cgroupfs_root *root;
  426. struct list_head sibling;
  427. /* used when use_id == true */
  428. struct idr idr;
  429. spinlock_t id_lock;
  430. /* should be defined only by modular subsystems */
  431. struct module *module;
  432. };
  433. #define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys;
  434. #include <linux/cgroup_subsys.h>
  435. #undef SUBSYS
  436. static inline struct cgroup_subsys_state *cgroup_subsys_state(
  437. struct cgroup *cgrp, int subsys_id)
  438. {
  439. return cgrp->subsys[subsys_id];
  440. }
  441. /**
  442. * task_css_set_check - obtain a task's css_set with extra access conditions
  443. * @task: the task to obtain css_set for
  444. * @__c: extra condition expression to be passed to rcu_dereference_check()
  445. *
  446. * A task's css_set is RCU protected, initialized and exited while holding
  447. * task_lock(), and can only be modified while holding both cgroup_mutex
  448. * and task_lock() while the task is alive. This macro verifies that the
  449. * caller is inside proper critical section and returns @task's css_set.
  450. *
  451. * The caller can also specify additional allowed conditions via @__c, such
  452. * as locks used during the cgroup_subsys::attach() methods.
  453. */
  454. #define task_css_set_check(task, __c) \
  455. rcu_dereference_check((task)->cgroups, \
  456. lockdep_is_held(&(task)->alloc_lock) || \
  457. cgroup_lock_is_held() || (__c))
  458. /**
  459. * task_subsys_state_check - obtain css for (task, subsys) w/ extra access conds
  460. * @task: the target task
  461. * @subsys_id: the target subsystem ID
  462. * @__c: extra condition expression to be passed to rcu_dereference_check()
  463. *
  464. * Return the cgroup_subsys_state for the (@task, @subsys_id) pair. The
  465. * synchronization rules are the same as task_css_set_check().
  466. */
  467. #define task_subsys_state_check(task, subsys_id, __c) \
  468. task_css_set_check((task), (__c))->subsys[(subsys_id)]
  469. /**
  470. * task_css_set - obtain a task's css_set
  471. * @task: the task to obtain css_set for
  472. *
  473. * See task_css_set_check().
  474. */
  475. static inline struct css_set *task_css_set(struct task_struct *task)
  476. {
  477. return task_css_set_check(task, false);
  478. }
  479. /**
  480. * task_subsys_state - obtain css for (task, subsys)
  481. * @task: the target task
  482. * @subsys_id: the target subsystem ID
  483. *
  484. * See task_subsys_state_check().
  485. */
  486. static inline struct cgroup_subsys_state *
  487. task_subsys_state(struct task_struct *task, int subsys_id)
  488. {
  489. return task_subsys_state_check(task, subsys_id, false);
  490. }
  491. static inline struct cgroup* task_cgroup(struct task_struct *task,
  492. int subsys_id)
  493. {
  494. return task_subsys_state(task, subsys_id)->cgroup;
  495. }
  496. /* A cgroup_iter should be treated as an opaque object */
  497. struct cgroup_iter {
  498. struct list_head *cg_link;
  499. struct list_head *task;
  500. };
  501. /*
  502. * To iterate across the tasks in a cgroup:
  503. *
  504. * 1) call cgroup_iter_start to initialize an iterator
  505. *
  506. * 2) call cgroup_iter_next() to retrieve member tasks until it
  507. * returns NULL or until you want to end the iteration
  508. *
  509. * 3) call cgroup_iter_end() to destroy the iterator.
  510. *
  511. * Or, call cgroup_scan_tasks() to iterate through every task in a
  512. * cgroup - cgroup_scan_tasks() holds the css_set_lock when calling
  513. * the test_task() callback, but not while calling the process_task()
  514. * callback.
  515. */
  516. void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it);
  517. struct task_struct *cgroup_iter_next(struct cgroup *cgrp,
  518. struct cgroup_iter *it);
  519. void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it);
  520. int cgroup_scan_tasks(struct cgroup_scanner *scan);
  521. int cgroup_attach_task(struct cgroup *, struct task_struct *);
  522. int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
  523. /*
  524. * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works
  525. * if cgroup_subsys.use_id == true. It can be used for looking up and scanning.
  526. * CSS ID is assigned at cgroup allocation (create) automatically
  527. * and removed when subsys calls free_css_id() function. This is because
  528. * the lifetime of cgroup_subsys_state is subsys's matter.
  529. *
  530. * Looking up and scanning function should be called under rcu_read_lock().
  531. * Taking cgroup_mutex()/hierarchy_mutex() is not necessary for following calls.
  532. * But the css returned by this routine can be "not populated yet" or "being
  533. * destroyed". The caller should check css and cgroup's status.
  534. */
  535. /*
  536. * Typically Called at ->destroy(), or somewhere the subsys frees
  537. * cgroup_subsys_state.
  538. */
  539. void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css);
  540. /* Find a cgroup_subsys_state which has given ID */
  541. struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id);
  542. /*
  543. * Get a cgroup whose id is greater than or equal to id under tree of root.
  544. * Returning a cgroup_subsys_state or NULL.
  545. */
  546. struct cgroup_subsys_state *css_get_next(struct cgroup_subsys *ss, int id,
  547. struct cgroup_subsys_state *root, int *foundid);
  548. /* Returns true if root is ancestor of cg */
  549. bool css_is_ancestor(struct cgroup_subsys_state *cg,
  550. const struct cgroup_subsys_state *root);
  551. /* Get id and depth of css */
  552. unsigned short css_id(struct cgroup_subsys_state *css);
  553. unsigned short css_depth(struct cgroup_subsys_state *css);
  554. struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id);
  555. #else /* !CONFIG_CGROUPS */
  556. static inline int cgroup_init_early(void) { return 0; }
  557. static inline int cgroup_init(void) { return 0; }
  558. static inline void cgroup_fork(struct task_struct *p) {}
  559. static inline void cgroup_fork_callbacks(struct task_struct *p) {}
  560. static inline void cgroup_post_fork(struct task_struct *p) {}
  561. static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
  562. static inline void cgroup_lock(void) {}
  563. static inline void cgroup_unlock(void) {}
  564. static inline int cgroupstats_build(struct cgroupstats *stats,
  565. struct dentry *dentry)
  566. {
  567. return -EINVAL;
  568. }
  569. /* No cgroups - nothing to do */
  570. static inline int cgroup_attach_task_all(struct task_struct *from,
  571. struct task_struct *t)
  572. {
  573. return 0;
  574. }
  575. #endif /* !CONFIG_CGROUPS */
  576. #endif /* _LINUX_CGROUP_H */