cgroup.h 20 KB

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