cgroup.h 20 KB

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