cgroup.h 20 KB

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