cgroup.h 19 KB

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