cgroup-v1.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. #include "cgroup-internal.h"
  2. #include <linux/ctype.h>
  3. #include <linux/kmod.h>
  4. #include <linux/sort.h>
  5. #include <linux/delay.h>
  6. #include <linux/mm.h>
  7. #include <linux/sched/signal.h>
  8. #include <linux/sched/task.h>
  9. #include <linux/magic.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include <linux/delayacct.h>
  13. #include <linux/pid_namespace.h>
  14. #include <linux/cgroupstats.h>
  15. #include <trace/events/cgroup.h>
  16. /*
  17. * pidlists linger the following amount before being destroyed. The goal
  18. * is avoiding frequent destruction in the middle of consecutive read calls
  19. * Expiring in the middle is a performance problem not a correctness one.
  20. * 1 sec should be enough.
  21. */
  22. #define CGROUP_PIDLIST_DESTROY_DELAY HZ
  23. /* Controllers blocked by the commandline in v1 */
  24. static u16 cgroup_no_v1_mask;
  25. /*
  26. * pidlist destructions need to be flushed on cgroup destruction. Use a
  27. * separate workqueue as flush domain.
  28. */
  29. static struct workqueue_struct *cgroup_pidlist_destroy_wq;
  30. /*
  31. * Protects cgroup_subsys->release_agent_path. Modifying it also requires
  32. * cgroup_mutex. Reading requires either cgroup_mutex or this spinlock.
  33. */
  34. static DEFINE_SPINLOCK(release_agent_path_lock);
  35. bool cgroup1_ssid_disabled(int ssid)
  36. {
  37. return cgroup_no_v1_mask & (1 << ssid);
  38. }
  39. /**
  40. * cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from'
  41. * @from: attach to all cgroups of a given task
  42. * @tsk: the task to be attached
  43. */
  44. int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
  45. {
  46. struct cgroup_root *root;
  47. int retval = 0;
  48. mutex_lock(&cgroup_mutex);
  49. percpu_down_write(&cgroup_threadgroup_rwsem);
  50. for_each_root(root) {
  51. struct cgroup *from_cgrp;
  52. if (root == &cgrp_dfl_root)
  53. continue;
  54. spin_lock_irq(&css_set_lock);
  55. from_cgrp = task_cgroup_from_root(from, root);
  56. spin_unlock_irq(&css_set_lock);
  57. retval = cgroup_attach_task(from_cgrp, tsk, false);
  58. if (retval)
  59. break;
  60. }
  61. percpu_up_write(&cgroup_threadgroup_rwsem);
  62. mutex_unlock(&cgroup_mutex);
  63. return retval;
  64. }
  65. EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
  66. /**
  67. * cgroup_trasnsfer_tasks - move tasks from one cgroup to another
  68. * @to: cgroup to which the tasks will be moved
  69. * @from: cgroup in which the tasks currently reside
  70. *
  71. * Locking rules between cgroup_post_fork() and the migration path
  72. * guarantee that, if a task is forking while being migrated, the new child
  73. * is guaranteed to be either visible in the source cgroup after the
  74. * parent's migration is complete or put into the target cgroup. No task
  75. * can slip out of migration through forking.
  76. */
  77. int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
  78. {
  79. DEFINE_CGROUP_MGCTX(mgctx);
  80. struct cgrp_cset_link *link;
  81. struct css_task_iter it;
  82. struct task_struct *task;
  83. int ret;
  84. if (cgroup_on_dfl(to))
  85. return -EINVAL;
  86. ret = cgroup_migrate_vet_dst(to);
  87. if (ret)
  88. return ret;
  89. mutex_lock(&cgroup_mutex);
  90. percpu_down_write(&cgroup_threadgroup_rwsem);
  91. /* all tasks in @from are being moved, all csets are source */
  92. spin_lock_irq(&css_set_lock);
  93. list_for_each_entry(link, &from->cset_links, cset_link)
  94. cgroup_migrate_add_src(link->cset, to, &mgctx);
  95. spin_unlock_irq(&css_set_lock);
  96. ret = cgroup_migrate_prepare_dst(&mgctx);
  97. if (ret)
  98. goto out_err;
  99. /*
  100. * Migrate tasks one-by-one until @from is empty. This fails iff
  101. * ->can_attach() fails.
  102. */
  103. do {
  104. css_task_iter_start(&from->self, 0, &it);
  105. do {
  106. task = css_task_iter_next(&it);
  107. } while (task && (task->flags & PF_EXITING));
  108. if (task)
  109. get_task_struct(task);
  110. css_task_iter_end(&it);
  111. if (task) {
  112. ret = cgroup_migrate(task, false, &mgctx);
  113. if (!ret)
  114. TRACE_CGROUP_PATH(transfer_tasks, to, task, false);
  115. put_task_struct(task);
  116. }
  117. } while (task && !ret);
  118. out_err:
  119. cgroup_migrate_finish(&mgctx);
  120. percpu_up_write(&cgroup_threadgroup_rwsem);
  121. mutex_unlock(&cgroup_mutex);
  122. return ret;
  123. }
  124. /*
  125. * Stuff for reading the 'tasks'/'procs' files.
  126. *
  127. * Reading this file can return large amounts of data if a cgroup has
  128. * *lots* of attached tasks. So it may need several calls to read(),
  129. * but we cannot guarantee that the information we produce is correct
  130. * unless we produce it entirely atomically.
  131. *
  132. */
  133. /* which pidlist file are we talking about? */
  134. enum cgroup_filetype {
  135. CGROUP_FILE_PROCS,
  136. CGROUP_FILE_TASKS,
  137. };
  138. /*
  139. * A pidlist is a list of pids that virtually represents the contents of one
  140. * of the cgroup files ("procs" or "tasks"). We keep a list of such pidlists,
  141. * a pair (one each for procs, tasks) for each pid namespace that's relevant
  142. * to the cgroup.
  143. */
  144. struct cgroup_pidlist {
  145. /*
  146. * used to find which pidlist is wanted. doesn't change as long as
  147. * this particular list stays in the list.
  148. */
  149. struct { enum cgroup_filetype type; struct pid_namespace *ns; } key;
  150. /* array of xids */
  151. pid_t *list;
  152. /* how many elements the above list has */
  153. int length;
  154. /* each of these stored in a list by its cgroup */
  155. struct list_head links;
  156. /* pointer to the cgroup we belong to, for list removal purposes */
  157. struct cgroup *owner;
  158. /* for delayed destruction */
  159. struct delayed_work destroy_dwork;
  160. };
  161. /*
  162. * The following two functions "fix" the issue where there are more pids
  163. * than kmalloc will give memory for; in such cases, we use vmalloc/vfree.
  164. * TODO: replace with a kernel-wide solution to this problem
  165. */
  166. #define PIDLIST_TOO_LARGE(c) ((c) * sizeof(pid_t) > (PAGE_SIZE * 2))
  167. static void *pidlist_allocate(int count)
  168. {
  169. if (PIDLIST_TOO_LARGE(count))
  170. return vmalloc(array_size(count, sizeof(pid_t)));
  171. else
  172. return kmalloc_array(count, sizeof(pid_t), GFP_KERNEL);
  173. }
  174. static void pidlist_free(void *p)
  175. {
  176. kvfree(p);
  177. }
  178. /*
  179. * Used to destroy all pidlists lingering waiting for destroy timer. None
  180. * should be left afterwards.
  181. */
  182. void cgroup1_pidlist_destroy_all(struct cgroup *cgrp)
  183. {
  184. struct cgroup_pidlist *l, *tmp_l;
  185. mutex_lock(&cgrp->pidlist_mutex);
  186. list_for_each_entry_safe(l, tmp_l, &cgrp->pidlists, links)
  187. mod_delayed_work(cgroup_pidlist_destroy_wq, &l->destroy_dwork, 0);
  188. mutex_unlock(&cgrp->pidlist_mutex);
  189. flush_workqueue(cgroup_pidlist_destroy_wq);
  190. BUG_ON(!list_empty(&cgrp->pidlists));
  191. }
  192. static void cgroup_pidlist_destroy_work_fn(struct work_struct *work)
  193. {
  194. struct delayed_work *dwork = to_delayed_work(work);
  195. struct cgroup_pidlist *l = container_of(dwork, struct cgroup_pidlist,
  196. destroy_dwork);
  197. struct cgroup_pidlist *tofree = NULL;
  198. mutex_lock(&l->owner->pidlist_mutex);
  199. /*
  200. * Destroy iff we didn't get queued again. The state won't change
  201. * as destroy_dwork can only be queued while locked.
  202. */
  203. if (!delayed_work_pending(dwork)) {
  204. list_del(&l->links);
  205. pidlist_free(l->list);
  206. put_pid_ns(l->key.ns);
  207. tofree = l;
  208. }
  209. mutex_unlock(&l->owner->pidlist_mutex);
  210. kfree(tofree);
  211. }
  212. /*
  213. * pidlist_uniq - given a kmalloc()ed list, strip out all duplicate entries
  214. * Returns the number of unique elements.
  215. */
  216. static int pidlist_uniq(pid_t *list, int length)
  217. {
  218. int src, dest = 1;
  219. /*
  220. * we presume the 0th element is unique, so i starts at 1. trivial
  221. * edge cases first; no work needs to be done for either
  222. */
  223. if (length == 0 || length == 1)
  224. return length;
  225. /* src and dest walk down the list; dest counts unique elements */
  226. for (src = 1; src < length; src++) {
  227. /* find next unique element */
  228. while (list[src] == list[src-1]) {
  229. src++;
  230. if (src == length)
  231. goto after;
  232. }
  233. /* dest always points to where the next unique element goes */
  234. list[dest] = list[src];
  235. dest++;
  236. }
  237. after:
  238. return dest;
  239. }
  240. /*
  241. * The two pid files - task and cgroup.procs - guaranteed that the result
  242. * is sorted, which forced this whole pidlist fiasco. As pid order is
  243. * different per namespace, each namespace needs differently sorted list,
  244. * making it impossible to use, for example, single rbtree of member tasks
  245. * sorted by task pointer. As pidlists can be fairly large, allocating one
  246. * per open file is dangerous, so cgroup had to implement shared pool of
  247. * pidlists keyed by cgroup and namespace.
  248. */
  249. static int cmppid(const void *a, const void *b)
  250. {
  251. return *(pid_t *)a - *(pid_t *)b;
  252. }
  253. static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp,
  254. enum cgroup_filetype type)
  255. {
  256. struct cgroup_pidlist *l;
  257. /* don't need task_nsproxy() if we're looking at ourself */
  258. struct pid_namespace *ns = task_active_pid_ns(current);
  259. lockdep_assert_held(&cgrp->pidlist_mutex);
  260. list_for_each_entry(l, &cgrp->pidlists, links)
  261. if (l->key.type == type && l->key.ns == ns)
  262. return l;
  263. return NULL;
  264. }
  265. /*
  266. * find the appropriate pidlist for our purpose (given procs vs tasks)
  267. * returns with the lock on that pidlist already held, and takes care
  268. * of the use count, or returns NULL with no locks held if we're out of
  269. * memory.
  270. */
  271. static struct cgroup_pidlist *cgroup_pidlist_find_create(struct cgroup *cgrp,
  272. enum cgroup_filetype type)
  273. {
  274. struct cgroup_pidlist *l;
  275. lockdep_assert_held(&cgrp->pidlist_mutex);
  276. l = cgroup_pidlist_find(cgrp, type);
  277. if (l)
  278. return l;
  279. /* entry not found; create a new one */
  280. l = kzalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL);
  281. if (!l)
  282. return l;
  283. INIT_DELAYED_WORK(&l->destroy_dwork, cgroup_pidlist_destroy_work_fn);
  284. l->key.type = type;
  285. /* don't need task_nsproxy() if we're looking at ourself */
  286. l->key.ns = get_pid_ns(task_active_pid_ns(current));
  287. l->owner = cgrp;
  288. list_add(&l->links, &cgrp->pidlists);
  289. return l;
  290. }
  291. /**
  292. * cgroup_task_count - count the number of tasks in a cgroup.
  293. * @cgrp: the cgroup in question
  294. */
  295. int cgroup_task_count(const struct cgroup *cgrp)
  296. {
  297. int count = 0;
  298. struct cgrp_cset_link *link;
  299. spin_lock_irq(&css_set_lock);
  300. list_for_each_entry(link, &cgrp->cset_links, cset_link)
  301. count += link->cset->nr_tasks;
  302. spin_unlock_irq(&css_set_lock);
  303. return count;
  304. }
  305. /*
  306. * Load a cgroup's pidarray with either procs' tgids or tasks' pids
  307. */
  308. static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
  309. struct cgroup_pidlist **lp)
  310. {
  311. pid_t *array;
  312. int length;
  313. int pid, n = 0; /* used for populating the array */
  314. struct css_task_iter it;
  315. struct task_struct *tsk;
  316. struct cgroup_pidlist *l;
  317. lockdep_assert_held(&cgrp->pidlist_mutex);
  318. /*
  319. * If cgroup gets more users after we read count, we won't have
  320. * enough space - tough. This race is indistinguishable to the
  321. * caller from the case that the additional cgroup users didn't
  322. * show up until sometime later on.
  323. */
  324. length = cgroup_task_count(cgrp);
  325. array = pidlist_allocate(length);
  326. if (!array)
  327. return -ENOMEM;
  328. /* now, populate the array */
  329. css_task_iter_start(&cgrp->self, 0, &it);
  330. while ((tsk = css_task_iter_next(&it))) {
  331. if (unlikely(n == length))
  332. break;
  333. /* get tgid or pid for procs or tasks file respectively */
  334. if (type == CGROUP_FILE_PROCS)
  335. pid = task_tgid_vnr(tsk);
  336. else
  337. pid = task_pid_vnr(tsk);
  338. if (pid > 0) /* make sure to only use valid results */
  339. array[n++] = pid;
  340. }
  341. css_task_iter_end(&it);
  342. length = n;
  343. /* now sort & (if procs) strip out duplicates */
  344. sort(array, length, sizeof(pid_t), cmppid, NULL);
  345. if (type == CGROUP_FILE_PROCS)
  346. length = pidlist_uniq(array, length);
  347. l = cgroup_pidlist_find_create(cgrp, type);
  348. if (!l) {
  349. pidlist_free(array);
  350. return -ENOMEM;
  351. }
  352. /* store array, freeing old if necessary */
  353. pidlist_free(l->list);
  354. l->list = array;
  355. l->length = length;
  356. *lp = l;
  357. return 0;
  358. }
  359. /*
  360. * seq_file methods for the tasks/procs files. The seq_file position is the
  361. * next pid to display; the seq_file iterator is a pointer to the pid
  362. * in the cgroup->l->list array.
  363. */
  364. static void *cgroup_pidlist_start(struct seq_file *s, loff_t *pos)
  365. {
  366. /*
  367. * Initially we receive a position value that corresponds to
  368. * one more than the last pid shown (or 0 on the first call or
  369. * after a seek to the start). Use a binary-search to find the
  370. * next pid to display, if any
  371. */
  372. struct kernfs_open_file *of = s->private;
  373. struct cgroup *cgrp = seq_css(s)->cgroup;
  374. struct cgroup_pidlist *l;
  375. enum cgroup_filetype type = seq_cft(s)->private;
  376. int index = 0, pid = *pos;
  377. int *iter, ret;
  378. mutex_lock(&cgrp->pidlist_mutex);
  379. /*
  380. * !NULL @of->priv indicates that this isn't the first start()
  381. * after open. If the matching pidlist is around, we can use that.
  382. * Look for it. Note that @of->priv can't be used directly. It
  383. * could already have been destroyed.
  384. */
  385. if (of->priv)
  386. of->priv = cgroup_pidlist_find(cgrp, type);
  387. /*
  388. * Either this is the first start() after open or the matching
  389. * pidlist has been destroyed inbetween. Create a new one.
  390. */
  391. if (!of->priv) {
  392. ret = pidlist_array_load(cgrp, type,
  393. (struct cgroup_pidlist **)&of->priv);
  394. if (ret)
  395. return ERR_PTR(ret);
  396. }
  397. l = of->priv;
  398. if (pid) {
  399. int end = l->length;
  400. while (index < end) {
  401. int mid = (index + end) / 2;
  402. if (l->list[mid] == pid) {
  403. index = mid;
  404. break;
  405. } else if (l->list[mid] <= pid)
  406. index = mid + 1;
  407. else
  408. end = mid;
  409. }
  410. }
  411. /* If we're off the end of the array, we're done */
  412. if (index >= l->length)
  413. return NULL;
  414. /* Update the abstract position to be the actual pid that we found */
  415. iter = l->list + index;
  416. *pos = *iter;
  417. return iter;
  418. }
  419. static void cgroup_pidlist_stop(struct seq_file *s, void *v)
  420. {
  421. struct kernfs_open_file *of = s->private;
  422. struct cgroup_pidlist *l = of->priv;
  423. if (l)
  424. mod_delayed_work(cgroup_pidlist_destroy_wq, &l->destroy_dwork,
  425. CGROUP_PIDLIST_DESTROY_DELAY);
  426. mutex_unlock(&seq_css(s)->cgroup->pidlist_mutex);
  427. }
  428. static void *cgroup_pidlist_next(struct seq_file *s, void *v, loff_t *pos)
  429. {
  430. struct kernfs_open_file *of = s->private;
  431. struct cgroup_pidlist *l = of->priv;
  432. pid_t *p = v;
  433. pid_t *end = l->list + l->length;
  434. /*
  435. * Advance to the next pid in the array. If this goes off the
  436. * end, we're done
  437. */
  438. p++;
  439. if (p >= end) {
  440. return NULL;
  441. } else {
  442. *pos = *p;
  443. return p;
  444. }
  445. }
  446. static int cgroup_pidlist_show(struct seq_file *s, void *v)
  447. {
  448. seq_printf(s, "%d\n", *(int *)v);
  449. return 0;
  450. }
  451. static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of,
  452. char *buf, size_t nbytes, loff_t off,
  453. bool threadgroup)
  454. {
  455. struct cgroup *cgrp;
  456. struct task_struct *task;
  457. const struct cred *cred, *tcred;
  458. ssize_t ret;
  459. cgrp = cgroup_kn_lock_live(of->kn, false);
  460. if (!cgrp)
  461. return -ENODEV;
  462. task = cgroup_procs_write_start(buf, threadgroup);
  463. ret = PTR_ERR_OR_ZERO(task);
  464. if (ret)
  465. goto out_unlock;
  466. /*
  467. * Even if we're attaching all tasks in the thread group, we only
  468. * need to check permissions on one of them.
  469. */
  470. cred = current_cred();
  471. tcred = get_task_cred(task);
  472. if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
  473. !uid_eq(cred->euid, tcred->uid) &&
  474. !uid_eq(cred->euid, tcred->suid))
  475. ret = -EACCES;
  476. put_cred(tcred);
  477. if (ret)
  478. goto out_finish;
  479. ret = cgroup_attach_task(cgrp, task, threadgroup);
  480. out_finish:
  481. cgroup_procs_write_finish(task);
  482. out_unlock:
  483. cgroup_kn_unlock(of->kn);
  484. return ret ?: nbytes;
  485. }
  486. static ssize_t cgroup1_procs_write(struct kernfs_open_file *of,
  487. char *buf, size_t nbytes, loff_t off)
  488. {
  489. return __cgroup1_procs_write(of, buf, nbytes, off, true);
  490. }
  491. static ssize_t cgroup1_tasks_write(struct kernfs_open_file *of,
  492. char *buf, size_t nbytes, loff_t off)
  493. {
  494. return __cgroup1_procs_write(of, buf, nbytes, off, false);
  495. }
  496. static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
  497. char *buf, size_t nbytes, loff_t off)
  498. {
  499. struct cgroup *cgrp;
  500. BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
  501. cgrp = cgroup_kn_lock_live(of->kn, false);
  502. if (!cgrp)
  503. return -ENODEV;
  504. spin_lock(&release_agent_path_lock);
  505. strlcpy(cgrp->root->release_agent_path, strstrip(buf),
  506. sizeof(cgrp->root->release_agent_path));
  507. spin_unlock(&release_agent_path_lock);
  508. cgroup_kn_unlock(of->kn);
  509. return nbytes;
  510. }
  511. static int cgroup_release_agent_show(struct seq_file *seq, void *v)
  512. {
  513. struct cgroup *cgrp = seq_css(seq)->cgroup;
  514. spin_lock(&release_agent_path_lock);
  515. seq_puts(seq, cgrp->root->release_agent_path);
  516. spin_unlock(&release_agent_path_lock);
  517. seq_putc(seq, '\n');
  518. return 0;
  519. }
  520. static int cgroup_sane_behavior_show(struct seq_file *seq, void *v)
  521. {
  522. seq_puts(seq, "0\n");
  523. return 0;
  524. }
  525. static u64 cgroup_read_notify_on_release(struct cgroup_subsys_state *css,
  526. struct cftype *cft)
  527. {
  528. return notify_on_release(css->cgroup);
  529. }
  530. static int cgroup_write_notify_on_release(struct cgroup_subsys_state *css,
  531. struct cftype *cft, u64 val)
  532. {
  533. if (val)
  534. set_bit(CGRP_NOTIFY_ON_RELEASE, &css->cgroup->flags);
  535. else
  536. clear_bit(CGRP_NOTIFY_ON_RELEASE, &css->cgroup->flags);
  537. return 0;
  538. }
  539. static u64 cgroup_clone_children_read(struct cgroup_subsys_state *css,
  540. struct cftype *cft)
  541. {
  542. return test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
  543. }
  544. static int cgroup_clone_children_write(struct cgroup_subsys_state *css,
  545. struct cftype *cft, u64 val)
  546. {
  547. if (val)
  548. set_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
  549. else
  550. clear_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
  551. return 0;
  552. }
  553. /* cgroup core interface files for the legacy hierarchies */
  554. struct cftype cgroup1_base_files[] = {
  555. {
  556. .name = "cgroup.procs",
  557. .seq_start = cgroup_pidlist_start,
  558. .seq_next = cgroup_pidlist_next,
  559. .seq_stop = cgroup_pidlist_stop,
  560. .seq_show = cgroup_pidlist_show,
  561. .private = CGROUP_FILE_PROCS,
  562. .write = cgroup1_procs_write,
  563. },
  564. {
  565. .name = "cgroup.clone_children",
  566. .read_u64 = cgroup_clone_children_read,
  567. .write_u64 = cgroup_clone_children_write,
  568. },
  569. {
  570. .name = "cgroup.sane_behavior",
  571. .flags = CFTYPE_ONLY_ON_ROOT,
  572. .seq_show = cgroup_sane_behavior_show,
  573. },
  574. {
  575. .name = "tasks",
  576. .seq_start = cgroup_pidlist_start,
  577. .seq_next = cgroup_pidlist_next,
  578. .seq_stop = cgroup_pidlist_stop,
  579. .seq_show = cgroup_pidlist_show,
  580. .private = CGROUP_FILE_TASKS,
  581. .write = cgroup1_tasks_write,
  582. },
  583. {
  584. .name = "notify_on_release",
  585. .read_u64 = cgroup_read_notify_on_release,
  586. .write_u64 = cgroup_write_notify_on_release,
  587. },
  588. {
  589. .name = "release_agent",
  590. .flags = CFTYPE_ONLY_ON_ROOT,
  591. .seq_show = cgroup_release_agent_show,
  592. .write = cgroup_release_agent_write,
  593. .max_write_len = PATH_MAX - 1,
  594. },
  595. { } /* terminate */
  596. };
  597. /* Display information about each subsystem and each hierarchy */
  598. int proc_cgroupstats_show(struct seq_file *m, void *v)
  599. {
  600. struct cgroup_subsys *ss;
  601. int i;
  602. seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n");
  603. /*
  604. * ideally we don't want subsystems moving around while we do this.
  605. * cgroup_mutex is also necessary to guarantee an atomic snapshot of
  606. * subsys/hierarchy state.
  607. */
  608. mutex_lock(&cgroup_mutex);
  609. for_each_subsys(ss, i)
  610. seq_printf(m, "%s\t%d\t%d\t%d\n",
  611. ss->legacy_name, ss->root->hierarchy_id,
  612. atomic_read(&ss->root->nr_cgrps),
  613. cgroup_ssid_enabled(i));
  614. mutex_unlock(&cgroup_mutex);
  615. return 0;
  616. }
  617. /**
  618. * cgroupstats_build - build and fill cgroupstats
  619. * @stats: cgroupstats to fill information into
  620. * @dentry: A dentry entry belonging to the cgroup for which stats have
  621. * been requested.
  622. *
  623. * Build and fill cgroupstats so that taskstats can export it to user
  624. * space.
  625. */
  626. int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
  627. {
  628. struct kernfs_node *kn = kernfs_node_from_dentry(dentry);
  629. struct cgroup *cgrp;
  630. struct css_task_iter it;
  631. struct task_struct *tsk;
  632. /* it should be kernfs_node belonging to cgroupfs and is a directory */
  633. if (dentry->d_sb->s_type != &cgroup_fs_type || !kn ||
  634. kernfs_type(kn) != KERNFS_DIR)
  635. return -EINVAL;
  636. mutex_lock(&cgroup_mutex);
  637. /*
  638. * We aren't being called from kernfs and there's no guarantee on
  639. * @kn->priv's validity. For this and css_tryget_online_from_dir(),
  640. * @kn->priv is RCU safe. Let's do the RCU dancing.
  641. */
  642. rcu_read_lock();
  643. cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv);
  644. if (!cgrp || cgroup_is_dead(cgrp)) {
  645. rcu_read_unlock();
  646. mutex_unlock(&cgroup_mutex);
  647. return -ENOENT;
  648. }
  649. rcu_read_unlock();
  650. css_task_iter_start(&cgrp->self, 0, &it);
  651. while ((tsk = css_task_iter_next(&it))) {
  652. switch (tsk->state) {
  653. case TASK_RUNNING:
  654. stats->nr_running++;
  655. break;
  656. case TASK_INTERRUPTIBLE:
  657. stats->nr_sleeping++;
  658. break;
  659. case TASK_UNINTERRUPTIBLE:
  660. stats->nr_uninterruptible++;
  661. break;
  662. case TASK_STOPPED:
  663. stats->nr_stopped++;
  664. break;
  665. default:
  666. if (delayacct_is_task_waiting_on_io(tsk))
  667. stats->nr_io_wait++;
  668. break;
  669. }
  670. }
  671. css_task_iter_end(&it);
  672. mutex_unlock(&cgroup_mutex);
  673. return 0;
  674. }
  675. void cgroup1_check_for_release(struct cgroup *cgrp)
  676. {
  677. if (notify_on_release(cgrp) && !cgroup_is_populated(cgrp) &&
  678. !css_has_online_children(&cgrp->self) && !cgroup_is_dead(cgrp))
  679. schedule_work(&cgrp->release_agent_work);
  680. }
  681. /*
  682. * Notify userspace when a cgroup is released, by running the
  683. * configured release agent with the name of the cgroup (path
  684. * relative to the root of cgroup file system) as the argument.
  685. *
  686. * Most likely, this user command will try to rmdir this cgroup.
  687. *
  688. * This races with the possibility that some other task will be
  689. * attached to this cgroup before it is removed, or that some other
  690. * user task will 'mkdir' a child cgroup of this cgroup. That's ok.
  691. * The presumed 'rmdir' will fail quietly if this cgroup is no longer
  692. * unused, and this cgroup will be reprieved from its death sentence,
  693. * to continue to serve a useful existence. Next time it's released,
  694. * we will get notified again, if it still has 'notify_on_release' set.
  695. *
  696. * The final arg to call_usermodehelper() is UMH_WAIT_EXEC, which
  697. * means only wait until the task is successfully execve()'d. The
  698. * separate release agent task is forked by call_usermodehelper(),
  699. * then control in this thread returns here, without waiting for the
  700. * release agent task. We don't bother to wait because the caller of
  701. * this routine has no use for the exit status of the release agent
  702. * task, so no sense holding our caller up for that.
  703. */
  704. void cgroup1_release_agent(struct work_struct *work)
  705. {
  706. struct cgroup *cgrp =
  707. container_of(work, struct cgroup, release_agent_work);
  708. char *pathbuf = NULL, *agentbuf = NULL;
  709. char *argv[3], *envp[3];
  710. int ret;
  711. mutex_lock(&cgroup_mutex);
  712. pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  713. agentbuf = kstrdup(cgrp->root->release_agent_path, GFP_KERNEL);
  714. if (!pathbuf || !agentbuf)
  715. goto out;
  716. spin_lock_irq(&css_set_lock);
  717. ret = cgroup_path_ns_locked(cgrp, pathbuf, PATH_MAX, &init_cgroup_ns);
  718. spin_unlock_irq(&css_set_lock);
  719. if (ret < 0 || ret >= PATH_MAX)
  720. goto out;
  721. argv[0] = agentbuf;
  722. argv[1] = pathbuf;
  723. argv[2] = NULL;
  724. /* minimal command environment */
  725. envp[0] = "HOME=/";
  726. envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  727. envp[2] = NULL;
  728. mutex_unlock(&cgroup_mutex);
  729. call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
  730. goto out_free;
  731. out:
  732. mutex_unlock(&cgroup_mutex);
  733. out_free:
  734. kfree(agentbuf);
  735. kfree(pathbuf);
  736. }
  737. /*
  738. * cgroup_rename - Only allow simple rename of directories in place.
  739. */
  740. static int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent,
  741. const char *new_name_str)
  742. {
  743. struct cgroup *cgrp = kn->priv;
  744. int ret;
  745. if (kernfs_type(kn) != KERNFS_DIR)
  746. return -ENOTDIR;
  747. if (kn->parent != new_parent)
  748. return -EIO;
  749. /*
  750. * We're gonna grab cgroup_mutex which nests outside kernfs
  751. * active_ref. kernfs_rename() doesn't require active_ref
  752. * protection. Break them before grabbing cgroup_mutex.
  753. */
  754. kernfs_break_active_protection(new_parent);
  755. kernfs_break_active_protection(kn);
  756. mutex_lock(&cgroup_mutex);
  757. ret = kernfs_rename(kn, new_parent, new_name_str);
  758. if (!ret)
  759. TRACE_CGROUP_PATH(rename, cgrp);
  760. mutex_unlock(&cgroup_mutex);
  761. kernfs_unbreak_active_protection(kn);
  762. kernfs_unbreak_active_protection(new_parent);
  763. return ret;
  764. }
  765. static int cgroup1_show_options(struct seq_file *seq, struct kernfs_root *kf_root)
  766. {
  767. struct cgroup_root *root = cgroup_root_from_kf(kf_root);
  768. struct cgroup_subsys *ss;
  769. int ssid;
  770. for_each_subsys(ss, ssid)
  771. if (root->subsys_mask & (1 << ssid))
  772. seq_show_option(seq, ss->legacy_name, NULL);
  773. if (root->flags & CGRP_ROOT_NOPREFIX)
  774. seq_puts(seq, ",noprefix");
  775. if (root->flags & CGRP_ROOT_XATTR)
  776. seq_puts(seq, ",xattr");
  777. if (root->flags & CGRP_ROOT_CPUSET_V2_MODE)
  778. seq_puts(seq, ",cpuset_v2_mode");
  779. spin_lock(&release_agent_path_lock);
  780. if (strlen(root->release_agent_path))
  781. seq_show_option(seq, "release_agent",
  782. root->release_agent_path);
  783. spin_unlock(&release_agent_path_lock);
  784. if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags))
  785. seq_puts(seq, ",clone_children");
  786. if (strlen(root->name))
  787. seq_show_option(seq, "name", root->name);
  788. return 0;
  789. }
  790. static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
  791. {
  792. char *token, *o = data;
  793. bool all_ss = false, one_ss = false;
  794. u16 mask = U16_MAX;
  795. struct cgroup_subsys *ss;
  796. int nr_opts = 0;
  797. int i;
  798. #ifdef CONFIG_CPUSETS
  799. mask = ~((u16)1 << cpuset_cgrp_id);
  800. #endif
  801. memset(opts, 0, sizeof(*opts));
  802. while ((token = strsep(&o, ",")) != NULL) {
  803. nr_opts++;
  804. if (!*token)
  805. return -EINVAL;
  806. if (!strcmp(token, "none")) {
  807. /* Explicitly have no subsystems */
  808. opts->none = true;
  809. continue;
  810. }
  811. if (!strcmp(token, "all")) {
  812. /* Mutually exclusive option 'all' + subsystem name */
  813. if (one_ss)
  814. return -EINVAL;
  815. all_ss = true;
  816. continue;
  817. }
  818. if (!strcmp(token, "noprefix")) {
  819. opts->flags |= CGRP_ROOT_NOPREFIX;
  820. continue;
  821. }
  822. if (!strcmp(token, "clone_children")) {
  823. opts->cpuset_clone_children = true;
  824. continue;
  825. }
  826. if (!strcmp(token, "cpuset_v2_mode")) {
  827. opts->flags |= CGRP_ROOT_CPUSET_V2_MODE;
  828. continue;
  829. }
  830. if (!strcmp(token, "xattr")) {
  831. opts->flags |= CGRP_ROOT_XATTR;
  832. continue;
  833. }
  834. if (!strncmp(token, "release_agent=", 14)) {
  835. /* Specifying two release agents is forbidden */
  836. if (opts->release_agent)
  837. return -EINVAL;
  838. opts->release_agent =
  839. kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL);
  840. if (!opts->release_agent)
  841. return -ENOMEM;
  842. continue;
  843. }
  844. if (!strncmp(token, "name=", 5)) {
  845. const char *name = token + 5;
  846. /* Can't specify an empty name */
  847. if (!strlen(name))
  848. return -EINVAL;
  849. /* Must match [\w.-]+ */
  850. for (i = 0; i < strlen(name); i++) {
  851. char c = name[i];
  852. if (isalnum(c))
  853. continue;
  854. if ((c == '.') || (c == '-') || (c == '_'))
  855. continue;
  856. return -EINVAL;
  857. }
  858. /* Specifying two names is forbidden */
  859. if (opts->name)
  860. return -EINVAL;
  861. opts->name = kstrndup(name,
  862. MAX_CGROUP_ROOT_NAMELEN - 1,
  863. GFP_KERNEL);
  864. if (!opts->name)
  865. return -ENOMEM;
  866. continue;
  867. }
  868. for_each_subsys(ss, i) {
  869. if (strcmp(token, ss->legacy_name))
  870. continue;
  871. if (!cgroup_ssid_enabled(i))
  872. continue;
  873. if (cgroup1_ssid_disabled(i))
  874. continue;
  875. /* Mutually exclusive option 'all' + subsystem name */
  876. if (all_ss)
  877. return -EINVAL;
  878. opts->subsys_mask |= (1 << i);
  879. one_ss = true;
  880. break;
  881. }
  882. if (i == CGROUP_SUBSYS_COUNT)
  883. return -ENOENT;
  884. }
  885. /*
  886. * If the 'all' option was specified select all the subsystems,
  887. * otherwise if 'none', 'name=' and a subsystem name options were
  888. * not specified, let's default to 'all'
  889. */
  890. if (all_ss || (!one_ss && !opts->none && !opts->name))
  891. for_each_subsys(ss, i)
  892. if (cgroup_ssid_enabled(i) && !cgroup1_ssid_disabled(i))
  893. opts->subsys_mask |= (1 << i);
  894. /*
  895. * We either have to specify by name or by subsystems. (So all
  896. * empty hierarchies must have a name).
  897. */
  898. if (!opts->subsys_mask && !opts->name)
  899. return -EINVAL;
  900. /*
  901. * Option noprefix was introduced just for backward compatibility
  902. * with the old cpuset, so we allow noprefix only if mounting just
  903. * the cpuset subsystem.
  904. */
  905. if ((opts->flags & CGRP_ROOT_NOPREFIX) && (opts->subsys_mask & mask))
  906. return -EINVAL;
  907. /* Can't specify "none" and some subsystems */
  908. if (opts->subsys_mask && opts->none)
  909. return -EINVAL;
  910. return 0;
  911. }
  912. static int cgroup1_remount(struct kernfs_root *kf_root, int *flags, char *data)
  913. {
  914. int ret = 0;
  915. struct cgroup_root *root = cgroup_root_from_kf(kf_root);
  916. struct cgroup_sb_opts opts;
  917. u16 added_mask, removed_mask;
  918. cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
  919. /* See what subsystems are wanted */
  920. ret = parse_cgroupfs_options(data, &opts);
  921. if (ret)
  922. goto out_unlock;
  923. if (opts.subsys_mask != root->subsys_mask || opts.release_agent)
  924. pr_warn("option changes via remount are deprecated (pid=%d comm=%s)\n",
  925. task_tgid_nr(current), current->comm);
  926. added_mask = opts.subsys_mask & ~root->subsys_mask;
  927. removed_mask = root->subsys_mask & ~opts.subsys_mask;
  928. /* Don't allow flags or name to change at remount */
  929. if ((opts.flags ^ root->flags) ||
  930. (opts.name && strcmp(opts.name, root->name))) {
  931. pr_err("option or name mismatch, new: 0x%x \"%s\", old: 0x%x \"%s\"\n",
  932. opts.flags, opts.name ?: "", root->flags, root->name);
  933. ret = -EINVAL;
  934. goto out_unlock;
  935. }
  936. /* remounting is not allowed for populated hierarchies */
  937. if (!list_empty(&root->cgrp.self.children)) {
  938. ret = -EBUSY;
  939. goto out_unlock;
  940. }
  941. ret = rebind_subsystems(root, added_mask);
  942. if (ret)
  943. goto out_unlock;
  944. WARN_ON(rebind_subsystems(&cgrp_dfl_root, removed_mask));
  945. if (opts.release_agent) {
  946. spin_lock(&release_agent_path_lock);
  947. strcpy(root->release_agent_path, opts.release_agent);
  948. spin_unlock(&release_agent_path_lock);
  949. }
  950. trace_cgroup_remount(root);
  951. out_unlock:
  952. kfree(opts.release_agent);
  953. kfree(opts.name);
  954. mutex_unlock(&cgroup_mutex);
  955. return ret;
  956. }
  957. struct kernfs_syscall_ops cgroup1_kf_syscall_ops = {
  958. .rename = cgroup1_rename,
  959. .show_options = cgroup1_show_options,
  960. .remount_fs = cgroup1_remount,
  961. .mkdir = cgroup_mkdir,
  962. .rmdir = cgroup_rmdir,
  963. .show_path = cgroup_show_path,
  964. };
  965. struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags,
  966. void *data, unsigned long magic,
  967. struct cgroup_namespace *ns)
  968. {
  969. struct super_block *pinned_sb = NULL;
  970. struct cgroup_sb_opts opts;
  971. struct cgroup_root *root;
  972. struct cgroup_subsys *ss;
  973. struct dentry *dentry;
  974. int i, ret;
  975. bool new_root = false;
  976. cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
  977. /* First find the desired set of subsystems */
  978. ret = parse_cgroupfs_options(data, &opts);
  979. if (ret)
  980. goto out_unlock;
  981. /*
  982. * Destruction of cgroup root is asynchronous, so subsystems may
  983. * still be dying after the previous unmount. Let's drain the
  984. * dying subsystems. We just need to ensure that the ones
  985. * unmounted previously finish dying and don't care about new ones
  986. * starting. Testing ref liveliness is good enough.
  987. */
  988. for_each_subsys(ss, i) {
  989. if (!(opts.subsys_mask & (1 << i)) ||
  990. ss->root == &cgrp_dfl_root)
  991. continue;
  992. if (!percpu_ref_tryget_live(&ss->root->cgrp.self.refcnt)) {
  993. mutex_unlock(&cgroup_mutex);
  994. msleep(10);
  995. ret = restart_syscall();
  996. goto out_free;
  997. }
  998. cgroup_put(&ss->root->cgrp);
  999. }
  1000. for_each_root(root) {
  1001. bool name_match = false;
  1002. if (root == &cgrp_dfl_root)
  1003. continue;
  1004. /*
  1005. * If we asked for a name then it must match. Also, if
  1006. * name matches but sybsys_mask doesn't, we should fail.
  1007. * Remember whether name matched.
  1008. */
  1009. if (opts.name) {
  1010. if (strcmp(opts.name, root->name))
  1011. continue;
  1012. name_match = true;
  1013. }
  1014. /*
  1015. * If we asked for subsystems (or explicitly for no
  1016. * subsystems) then they must match.
  1017. */
  1018. if ((opts.subsys_mask || opts.none) &&
  1019. (opts.subsys_mask != root->subsys_mask)) {
  1020. if (!name_match)
  1021. continue;
  1022. ret = -EBUSY;
  1023. goto out_unlock;
  1024. }
  1025. if (root->flags ^ opts.flags)
  1026. pr_warn("new mount options do not match the existing superblock, will be ignored\n");
  1027. /*
  1028. * We want to reuse @root whose lifetime is governed by its
  1029. * ->cgrp. Let's check whether @root is alive and keep it
  1030. * that way. As cgroup_kill_sb() can happen anytime, we
  1031. * want to block it by pinning the sb so that @root doesn't
  1032. * get killed before mount is complete.
  1033. *
  1034. * With the sb pinned, tryget_live can reliably indicate
  1035. * whether @root can be reused. If it's being killed,
  1036. * drain it. We can use wait_queue for the wait but this
  1037. * path is super cold. Let's just sleep a bit and retry.
  1038. */
  1039. pinned_sb = kernfs_pin_sb(root->kf_root, NULL);
  1040. if (IS_ERR(pinned_sb) ||
  1041. !percpu_ref_tryget_live(&root->cgrp.self.refcnt)) {
  1042. mutex_unlock(&cgroup_mutex);
  1043. if (!IS_ERR_OR_NULL(pinned_sb))
  1044. deactivate_super(pinned_sb);
  1045. msleep(10);
  1046. ret = restart_syscall();
  1047. goto out_free;
  1048. }
  1049. ret = 0;
  1050. goto out_unlock;
  1051. }
  1052. /*
  1053. * No such thing, create a new one. name= matching without subsys
  1054. * specification is allowed for already existing hierarchies but we
  1055. * can't create new one without subsys specification.
  1056. */
  1057. if (!opts.subsys_mask && !opts.none) {
  1058. ret = -EINVAL;
  1059. goto out_unlock;
  1060. }
  1061. /* Hierarchies may only be created in the initial cgroup namespace. */
  1062. if (ns != &init_cgroup_ns) {
  1063. ret = -EPERM;
  1064. goto out_unlock;
  1065. }
  1066. root = kzalloc(sizeof(*root), GFP_KERNEL);
  1067. if (!root) {
  1068. ret = -ENOMEM;
  1069. goto out_unlock;
  1070. }
  1071. new_root = true;
  1072. init_cgroup_root(root, &opts);
  1073. ret = cgroup_setup_root(root, opts.subsys_mask, PERCPU_REF_INIT_DEAD);
  1074. if (ret)
  1075. cgroup_free_root(root);
  1076. out_unlock:
  1077. mutex_unlock(&cgroup_mutex);
  1078. out_free:
  1079. kfree(opts.release_agent);
  1080. kfree(opts.name);
  1081. if (ret)
  1082. return ERR_PTR(ret);
  1083. dentry = cgroup_do_mount(&cgroup_fs_type, flags, root,
  1084. CGROUP_SUPER_MAGIC, ns);
  1085. /*
  1086. * There's a race window after we release cgroup_mutex and before
  1087. * allocating a superblock. Make sure a concurrent process won't
  1088. * be able to re-use the root during this window by delaying the
  1089. * initialization of root refcnt.
  1090. */
  1091. if (new_root) {
  1092. mutex_lock(&cgroup_mutex);
  1093. percpu_ref_reinit(&root->cgrp.self.refcnt);
  1094. mutex_unlock(&cgroup_mutex);
  1095. }
  1096. /*
  1097. * If @pinned_sb, we're reusing an existing root and holding an
  1098. * extra ref on its sb. Mount is complete. Put the extra ref.
  1099. */
  1100. if (pinned_sb)
  1101. deactivate_super(pinned_sb);
  1102. return dentry;
  1103. }
  1104. static int __init cgroup1_wq_init(void)
  1105. {
  1106. /*
  1107. * Used to destroy pidlists and separate to serve as flush domain.
  1108. * Cap @max_active to 1 too.
  1109. */
  1110. cgroup_pidlist_destroy_wq = alloc_workqueue("cgroup_pidlist_destroy",
  1111. 0, 1);
  1112. BUG_ON(!cgroup_pidlist_destroy_wq);
  1113. return 0;
  1114. }
  1115. core_initcall(cgroup1_wq_init);
  1116. static int __init cgroup_no_v1(char *str)
  1117. {
  1118. struct cgroup_subsys *ss;
  1119. char *token;
  1120. int i;
  1121. while ((token = strsep(&str, ",")) != NULL) {
  1122. if (!*token)
  1123. continue;
  1124. if (!strcmp(token, "all")) {
  1125. cgroup_no_v1_mask = U16_MAX;
  1126. break;
  1127. }
  1128. for_each_subsys(ss, i) {
  1129. if (strcmp(token, ss->name) &&
  1130. strcmp(token, ss->legacy_name))
  1131. continue;
  1132. cgroup_no_v1_mask |= 1 << i;
  1133. }
  1134. }
  1135. return 1;
  1136. }
  1137. __setup("cgroup_no_v1=", cgroup_no_v1);