Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 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 | |
| 11 | #include <linux/sched.h> |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 12 | #include <linux/cpumask.h> |
| 13 | #include <linux/nodemask.h> |
Tejun Heo | eb6fd50 | 2012-11-09 09:12:29 -0800 | [diff] [blame] | 14 | #include <linux/rculist.h> |
Balbir Singh | 846c7bb | 2007-10-18 23:39:44 -0700 | [diff] [blame] | 15 | #include <linux/cgroupstats.h> |
Paul Menage | cc31edc | 2008-10-18 20:28:04 -0700 | [diff] [blame] | 16 | #include <linux/rwsem.h> |
Tejun Heo | 25a7e68 | 2013-04-14 20:15:25 -0700 | [diff] [blame] | 17 | #include <linux/fs.h> |
Tejun Heo | 7da1127 | 2013-12-05 12:28:04 -0500 | [diff] [blame] | 18 | #include <linux/seq_file.h> |
Tejun Heo | 2bd59d4 | 2014-02-11 11:52:49 -0500 | [diff] [blame] | 19 | #include <linux/kernfs.h> |
Tejun Heo | b4a04ab | 2015-05-13 15:38:40 -0400 | [diff] [blame] | 20 | |
| 21 | #include <linux/cgroup-defs.h> |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 22 | |
| 23 | #ifdef CONFIG_CGROUPS |
| 24 | |
Tejun Heo | c326aa2 | 2015-05-13 16:24:16 -0400 | [diff] [blame^] | 25 | /* a css_task_iter should be treated as an opaque object */ |
| 26 | struct css_task_iter { |
| 27 | struct cgroup_subsys *ss; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 28 | |
Tejun Heo | c326aa2 | 2015-05-13 16:24:16 -0400 | [diff] [blame^] | 29 | struct list_head *cset_pos; |
| 30 | struct list_head *cset_head; |
| 31 | |
| 32 | struct list_head *task_pos; |
| 33 | struct list_head *tasks_head; |
| 34 | struct list_head *mg_tasks_head; |
| 35 | }; |
| 36 | |
| 37 | extern struct cgroup_root cgrp_dfl_root; |
| 38 | extern struct css_set init_css_set; |
| 39 | |
| 40 | #define SUBSYS(_x) extern struct cgroup_subsys _x ## _cgrp_subsys; |
| 41 | #include <linux/cgroup_subsys.h> |
| 42 | #undef SUBSYS |
| 43 | |
| 44 | bool css_has_online_children(struct cgroup_subsys_state *css); |
| 45 | struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss); |
| 46 | struct cgroup_subsys_state *cgroup_get_e_css(struct cgroup *cgroup, |
| 47 | struct cgroup_subsys *ss); |
| 48 | struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry, |
| 49 | struct cgroup_subsys *ss); |
| 50 | |
| 51 | bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor); |
| 52 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); |
| 53 | int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); |
| 54 | |
| 55 | int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts); |
| 56 | int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts); |
| 57 | int cgroup_rm_cftypes(struct cftype *cfts); |
| 58 | |
| 59 | char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen); |
| 60 | int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry); |
| 61 | int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns, |
| 62 | struct pid *pid, struct task_struct *tsk); |
| 63 | |
| 64 | void cgroup_fork(struct task_struct *p); |
| 65 | void cgroup_post_fork(struct task_struct *p); |
| 66 | void cgroup_exit(struct task_struct *p); |
| 67 | |
| 68 | int cgroup_init_early(void); |
| 69 | int cgroup_init(void); |
| 70 | |
| 71 | /* |
| 72 | * Iteration helpers and macros. |
| 73 | */ |
| 74 | |
| 75 | struct cgroup_subsys_state *css_next_child(struct cgroup_subsys_state *pos, |
| 76 | struct cgroup_subsys_state *parent); |
| 77 | struct cgroup_subsys_state *css_next_descendant_pre(struct cgroup_subsys_state *pos, |
| 78 | struct cgroup_subsys_state *css); |
| 79 | struct cgroup_subsys_state *css_rightmost_descendant(struct cgroup_subsys_state *pos); |
| 80 | struct cgroup_subsys_state *css_next_descendant_post(struct cgroup_subsys_state *pos, |
| 81 | struct cgroup_subsys_state *css); |
| 82 | |
| 83 | struct task_struct *cgroup_taskset_first(struct cgroup_taskset *tset); |
| 84 | struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset); |
| 85 | |
| 86 | void css_task_iter_start(struct cgroup_subsys_state *css, |
| 87 | struct css_task_iter *it); |
| 88 | struct task_struct *css_task_iter_next(struct css_task_iter *it); |
| 89 | void css_task_iter_end(struct css_task_iter *it); |
| 90 | |
| 91 | /** |
| 92 | * css_for_each_child - iterate through children of a css |
| 93 | * @pos: the css * to use as the loop cursor |
| 94 | * @parent: css whose children to walk |
| 95 | * |
| 96 | * Walk @parent's children. Must be called under rcu_read_lock(). |
| 97 | * |
| 98 | * If a subsystem synchronizes ->css_online() and the start of iteration, a |
| 99 | * css which finished ->css_online() is guaranteed to be visible in the |
| 100 | * future iterations and will stay visible until the last reference is put. |
| 101 | * A css which hasn't finished ->css_online() or already finished |
| 102 | * ->css_offline() may show up during traversal. It's each subsystem's |
| 103 | * responsibility to synchronize against on/offlining. |
| 104 | * |
| 105 | * It is allowed to temporarily drop RCU read lock during iteration. The |
| 106 | * caller is responsible for ensuring that @pos remains accessible until |
| 107 | * the start of the next iteration by, for example, bumping the css refcnt. |
| 108 | */ |
| 109 | #define css_for_each_child(pos, parent) \ |
| 110 | for ((pos) = css_next_child(NULL, (parent)); (pos); \ |
| 111 | (pos) = css_next_child((pos), (parent))) |
| 112 | |
| 113 | /** |
| 114 | * css_for_each_descendant_pre - pre-order walk of a css's descendants |
| 115 | * @pos: the css * to use as the loop cursor |
| 116 | * @root: css whose descendants to walk |
| 117 | * |
| 118 | * Walk @root's descendants. @root is included in the iteration and the |
| 119 | * first node to be visited. Must be called under rcu_read_lock(). |
| 120 | * |
| 121 | * If a subsystem synchronizes ->css_online() and the start of iteration, a |
| 122 | * css which finished ->css_online() is guaranteed to be visible in the |
| 123 | * future iterations and will stay visible until the last reference is put. |
| 124 | * A css which hasn't finished ->css_online() or already finished |
| 125 | * ->css_offline() may show up during traversal. It's each subsystem's |
| 126 | * responsibility to synchronize against on/offlining. |
| 127 | * |
| 128 | * For example, the following guarantees that a descendant can't escape |
| 129 | * state updates of its ancestors. |
| 130 | * |
| 131 | * my_online(@css) |
| 132 | * { |
| 133 | * Lock @css's parent and @css; |
| 134 | * Inherit state from the parent; |
| 135 | * Unlock both. |
| 136 | * } |
| 137 | * |
| 138 | * my_update_state(@css) |
| 139 | * { |
| 140 | * css_for_each_descendant_pre(@pos, @css) { |
| 141 | * Lock @pos; |
| 142 | * if (@pos == @css) |
| 143 | * Update @css's state; |
| 144 | * else |
| 145 | * Verify @pos is alive and inherit state from its parent; |
| 146 | * Unlock @pos; |
| 147 | * } |
| 148 | * } |
| 149 | * |
| 150 | * As long as the inheriting step, including checking the parent state, is |
| 151 | * enclosed inside @pos locking, double-locking the parent isn't necessary |
| 152 | * while inheriting. The state update to the parent is guaranteed to be |
| 153 | * visible by walking order and, as long as inheriting operations to the |
| 154 | * same @pos are atomic to each other, multiple updates racing each other |
| 155 | * still result in the correct state. It's guaranateed that at least one |
| 156 | * inheritance happens for any css after the latest update to its parent. |
| 157 | * |
| 158 | * If checking parent's state requires locking the parent, each inheriting |
| 159 | * iteration should lock and unlock both @pos->parent and @pos. |
| 160 | * |
| 161 | * Alternatively, a subsystem may choose to use a single global lock to |
| 162 | * synchronize ->css_online() and ->css_offline() against tree-walking |
| 163 | * operations. |
| 164 | * |
| 165 | * It is allowed to temporarily drop RCU read lock during iteration. The |
| 166 | * caller is responsible for ensuring that @pos remains accessible until |
| 167 | * the start of the next iteration by, for example, bumping the css refcnt. |
| 168 | */ |
| 169 | #define css_for_each_descendant_pre(pos, css) \ |
| 170 | for ((pos) = css_next_descendant_pre(NULL, (css)); (pos); \ |
| 171 | (pos) = css_next_descendant_pre((pos), (css))) |
| 172 | |
| 173 | /** |
| 174 | * css_for_each_descendant_post - post-order walk of a css's descendants |
| 175 | * @pos: the css * to use as the loop cursor |
| 176 | * @css: css whose descendants to walk |
| 177 | * |
| 178 | * Similar to css_for_each_descendant_pre() but performs post-order |
| 179 | * traversal instead. @root is included in the iteration and the last |
| 180 | * node to be visited. |
| 181 | * |
| 182 | * If a subsystem synchronizes ->css_online() and the start of iteration, a |
| 183 | * css which finished ->css_online() is guaranteed to be visible in the |
| 184 | * future iterations and will stay visible until the last reference is put. |
| 185 | * A css which hasn't finished ->css_online() or already finished |
| 186 | * ->css_offline() may show up during traversal. It's each subsystem's |
| 187 | * responsibility to synchronize against on/offlining. |
| 188 | * |
| 189 | * Note that the walk visibility guarantee example described in pre-order |
| 190 | * walk doesn't apply the same to post-order walks. |
| 191 | */ |
| 192 | #define css_for_each_descendant_post(pos, css) \ |
| 193 | for ((pos) = css_next_descendant_post(NULL, (css)); (pos); \ |
| 194 | (pos) = css_next_descendant_post((pos), (css))) |
| 195 | |
| 196 | /** |
| 197 | * cgroup_taskset_for_each - iterate cgroup_taskset |
| 198 | * @task: the loop cursor |
| 199 | * @tset: taskset to iterate |
| 200 | */ |
| 201 | #define cgroup_taskset_for_each(task, tset) \ |
| 202 | for ((task) = cgroup_taskset_first((tset)); (task); \ |
| 203 | (task) = cgroup_taskset_next((tset))) |
| 204 | |
| 205 | /* |
| 206 | * Inline functions. |
| 207 | */ |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 208 | |
Tejun Heo | 5de0107 | 2013-06-12 21:04:52 -0700 | [diff] [blame] | 209 | /** |
| 210 | * css_get - obtain a reference on the specified css |
| 211 | * @css: target css |
| 212 | * |
| 213 | * The caller must already have a reference. |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 214 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 215 | static inline void css_get(struct cgroup_subsys_state *css) |
| 216 | { |
Tejun Heo | 3b514d2 | 2014-05-16 13:22:47 -0400 | [diff] [blame] | 217 | if (!(css->flags & CSS_NO_REF)) |
| 218 | percpu_ref_get(&css->refcnt); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 219 | } |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 220 | |
Tejun Heo | 5de0107 | 2013-06-12 21:04:52 -0700 | [diff] [blame] | 221 | /** |
Johannes Weiner | e8ea14c | 2014-12-10 15:42:42 -0800 | [diff] [blame] | 222 | * css_get_many - obtain references on the specified css |
| 223 | * @css: target css |
| 224 | * @n: number of references to get |
| 225 | * |
| 226 | * The caller must already have a reference. |
| 227 | */ |
| 228 | static inline void css_get_many(struct cgroup_subsys_state *css, unsigned int n) |
| 229 | { |
| 230 | if (!(css->flags & CSS_NO_REF)) |
| 231 | percpu_ref_get_many(&css->refcnt, n); |
| 232 | } |
| 233 | |
| 234 | /** |
Tejun Heo | 6f4524d | 2014-05-16 13:22:52 -0400 | [diff] [blame] | 235 | * css_tryget - try to obtain a reference on the specified css |
| 236 | * @css: target css |
| 237 | * |
| 238 | * Obtain a reference on @css unless it already has reached zero and is |
| 239 | * being released. This function doesn't care whether @css is on or |
| 240 | * offline. The caller naturally needs to ensure that @css is accessible |
| 241 | * but doesn't have to be holding a reference on it - IOW, RCU protected |
| 242 | * access is good enough for this function. Returns %true if a reference |
| 243 | * count was successfully obtained; %false otherwise. |
| 244 | */ |
| 245 | static inline bool css_tryget(struct cgroup_subsys_state *css) |
| 246 | { |
| 247 | if (!(css->flags & CSS_NO_REF)) |
| 248 | return percpu_ref_tryget(&css->refcnt); |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | /** |
Tejun Heo | ec903c0 | 2014-05-13 12:11:01 -0400 | [diff] [blame] | 253 | * css_tryget_online - try to obtain a reference on the specified css if online |
Tejun Heo | 5de0107 | 2013-06-12 21:04:52 -0700 | [diff] [blame] | 254 | * @css: target css |
| 255 | * |
Tejun Heo | ec903c0 | 2014-05-13 12:11:01 -0400 | [diff] [blame] | 256 | * Obtain a reference on @css if it's online. The caller naturally needs |
| 257 | * to ensure that @css is accessible but doesn't have to be holding a |
Tejun Heo | 5de0107 | 2013-06-12 21:04:52 -0700 | [diff] [blame] | 258 | * reference on it - IOW, RCU protected access is good enough for this |
| 259 | * function. Returns %true if a reference count was successfully obtained; |
| 260 | * %false otherwise. |
| 261 | */ |
Tejun Heo | ec903c0 | 2014-05-13 12:11:01 -0400 | [diff] [blame] | 262 | static inline bool css_tryget_online(struct cgroup_subsys_state *css) |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 263 | { |
Tejun Heo | 3b514d2 | 2014-05-16 13:22:47 -0400 | [diff] [blame] | 264 | if (!(css->flags & CSS_NO_REF)) |
| 265 | return percpu_ref_tryget_live(&css->refcnt); |
| 266 | return true; |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Tejun Heo | 5de0107 | 2013-06-12 21:04:52 -0700 | [diff] [blame] | 269 | /** |
| 270 | * css_put - put a css reference |
| 271 | * @css: target css |
| 272 | * |
Tejun Heo | ec903c0 | 2014-05-13 12:11:01 -0400 | [diff] [blame] | 273 | * Put a reference obtained via css_get() and css_tryget_online(). |
Tejun Heo | 5de0107 | 2013-06-12 21:04:52 -0700 | [diff] [blame] | 274 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 275 | static inline void css_put(struct cgroup_subsys_state *css) |
| 276 | { |
Tejun Heo | 3b514d2 | 2014-05-16 13:22:47 -0400 | [diff] [blame] | 277 | if (!(css->flags & CSS_NO_REF)) |
| 278 | percpu_ref_put(&css->refcnt); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Johannes Weiner | e8ea14c | 2014-12-10 15:42:42 -0800 | [diff] [blame] | 281 | /** |
| 282 | * css_put_many - put css references |
| 283 | * @css: target css |
| 284 | * @n: number of references to put |
| 285 | * |
| 286 | * Put references obtained via css_get() and css_tryget_online(). |
| 287 | */ |
| 288 | static inline void css_put_many(struct cgroup_subsys_state *css, unsigned int n) |
| 289 | { |
| 290 | if (!(css->flags & CSS_NO_REF)) |
| 291 | percpu_ref_put_many(&css->refcnt, n); |
| 292 | } |
| 293 | |
Tejun Heo | c326aa2 | 2015-05-13 16:24:16 -0400 | [diff] [blame^] | 294 | /** |
| 295 | * task_css_set_check - obtain a task's css_set with extra access conditions |
| 296 | * @task: the task to obtain css_set for |
| 297 | * @__c: extra condition expression to be passed to rcu_dereference_check() |
| 298 | * |
| 299 | * A task's css_set is RCU protected, initialized and exited while holding |
| 300 | * task_lock(), and can only be modified while holding both cgroup_mutex |
| 301 | * and task_lock() while the task is alive. This macro verifies that the |
| 302 | * caller is inside proper critical section and returns @task's css_set. |
| 303 | * |
| 304 | * The caller can also specify additional allowed conditions via @__c, such |
| 305 | * as locks used during the cgroup_subsys::attach() methods. |
| 306 | */ |
| 307 | #ifdef CONFIG_PROVE_RCU |
| 308 | extern struct mutex cgroup_mutex; |
| 309 | extern struct rw_semaphore css_set_rwsem; |
| 310 | #define task_css_set_check(task, __c) \ |
| 311 | rcu_dereference_check((task)->cgroups, \ |
| 312 | lockdep_is_held(&cgroup_mutex) || \ |
| 313 | lockdep_is_held(&css_set_rwsem) || \ |
| 314 | ((task)->flags & PF_EXITING) || (__c)) |
| 315 | #else |
| 316 | #define task_css_set_check(task, __c) \ |
| 317 | rcu_dereference((task)->cgroups) |
| 318 | #endif |
| 319 | |
| 320 | /** |
| 321 | * task_css_check - obtain css for (task, subsys) w/ extra access conds |
| 322 | * @task: the target task |
| 323 | * @subsys_id: the target subsystem ID |
| 324 | * @__c: extra condition expression to be passed to rcu_dereference_check() |
| 325 | * |
| 326 | * Return the cgroup_subsys_state for the (@task, @subsys_id) pair. The |
| 327 | * synchronization rules are the same as task_css_set_check(). |
| 328 | */ |
| 329 | #define task_css_check(task, subsys_id, __c) \ |
| 330 | task_css_set_check((task), (__c))->subsys[(subsys_id)] |
| 331 | |
| 332 | /** |
| 333 | * task_css_set - obtain a task's css_set |
| 334 | * @task: the task to obtain css_set for |
| 335 | * |
| 336 | * See task_css_set_check(). |
| 337 | */ |
| 338 | static inline struct css_set *task_css_set(struct task_struct *task) |
| 339 | { |
| 340 | return task_css_set_check(task, false); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * task_css - obtain css for (task, subsys) |
| 345 | * @task: the target task |
| 346 | * @subsys_id: the target subsystem ID |
| 347 | * |
| 348 | * See task_css_check(). |
| 349 | */ |
| 350 | static inline struct cgroup_subsys_state *task_css(struct task_struct *task, |
| 351 | int subsys_id) |
| 352 | { |
| 353 | return task_css_check(task, subsys_id, false); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * task_css_is_root - test whether a task belongs to the root css |
| 358 | * @task: the target task |
| 359 | * @subsys_id: the target subsystem ID |
| 360 | * |
| 361 | * Test whether @task belongs to the root css on the specified subsystem. |
| 362 | * May be invoked in any context. |
| 363 | */ |
| 364 | static inline bool task_css_is_root(struct task_struct *task, int subsys_id) |
| 365 | { |
| 366 | return task_css_check(task, subsys_id, true) == |
| 367 | init_css_set.subsys[subsys_id]; |
| 368 | } |
| 369 | |
| 370 | static inline struct cgroup *task_cgroup(struct task_struct *task, |
| 371 | int subsys_id) |
| 372 | { |
| 373 | return task_css(task, subsys_id)->cgroup; |
| 374 | } |
Tejun Heo | a2dd424 | 2014-03-19 10:23:55 -0400 | [diff] [blame] | 375 | |
Tejun Heo | aa6ec29 | 2014-07-09 10:08:08 -0400 | [diff] [blame] | 376 | /** |
| 377 | * cgroup_on_dfl - test whether a cgroup is on the default hierarchy |
| 378 | * @cgrp: the cgroup of interest |
| 379 | * |
| 380 | * The default hierarchy is the v2 interface of cgroup and this function |
| 381 | * can be used to test whether a cgroup is on the default hierarchy for |
| 382 | * cases where a subsystem should behave differnetly depending on the |
| 383 | * interface version. |
| 384 | * |
| 385 | * The set of behaviors which change on the default hierarchy are still |
| 386 | * being determined and the mount option is prefixed with __DEVEL__. |
| 387 | * |
| 388 | * List of changed behaviors: |
| 389 | * |
| 390 | * - Mount options "noprefix", "xattr", "clone_children", "release_agent" |
| 391 | * and "name" are disallowed. |
| 392 | * |
| 393 | * - When mounting an existing superblock, mount options should match. |
| 394 | * |
| 395 | * - Remount is disallowed. |
| 396 | * |
| 397 | * - rename(2) is disallowed. |
| 398 | * |
| 399 | * - "tasks" is removed. Everything should be at process granularity. Use |
| 400 | * "cgroup.procs" instead. |
| 401 | * |
| 402 | * - "cgroup.procs" is not sorted. pids will be unique unless they got |
| 403 | * recycled inbetween reads. |
| 404 | * |
| 405 | * - "release_agent" and "notify_on_release" are removed. Replacement |
| 406 | * notification mechanism will be implemented. |
| 407 | * |
| 408 | * - "cgroup.clone_children" is removed. |
| 409 | * |
| 410 | * - "cgroup.subtree_populated" is available. Its value is 0 if the cgroup |
| 411 | * and its descendants contain no task; otherwise, 1. The file also |
| 412 | * generates kernfs notification which can be monitored through poll and |
| 413 | * [di]notify when the value of the file changes. |
| 414 | * |
| 415 | * - cpuset: tasks will be kept in empty cpusets when hotplug happens and |
| 416 | * take masks of ancestors with non-empty cpus/mems, instead of being |
| 417 | * moved to an ancestor. |
| 418 | * |
| 419 | * - cpuset: a task can be moved into an empty cpuset, and again it takes |
| 420 | * masks of ancestors. |
| 421 | * |
| 422 | * - memcg: use_hierarchy is on by default and the cgroup file for the flag |
| 423 | * is not created. |
| 424 | * |
| 425 | * - blkcg: blk-throttle becomes properly hierarchical. |
| 426 | * |
| 427 | * - debug: disallowed on the default hierarchy. |
| 428 | */ |
Tejun Heo | a2dd424 | 2014-03-19 10:23:55 -0400 | [diff] [blame] | 429 | static inline bool cgroup_on_dfl(const struct cgroup *cgrp) |
| 430 | { |
| 431 | return cgrp->root == &cgrp_dfl_root; |
| 432 | } |
| 433 | |
Tejun Heo | 07bc356 | 2014-02-13 06:58:39 -0500 | [diff] [blame] | 434 | /* no synchronization, the result can only be used as a hint */ |
| 435 | static inline bool cgroup_has_tasks(struct cgroup *cgrp) |
| 436 | { |
| 437 | return !list_empty(&cgrp->cset_links); |
| 438 | } |
| 439 | |
Zefan Li | f29374b | 2014-09-19 16:29:31 +0800 | [diff] [blame] | 440 | /* returns ino associated with a cgroup */ |
Tejun Heo | b166492 | 2014-02-11 11:52:49 -0500 | [diff] [blame] | 441 | static inline ino_t cgroup_ino(struct cgroup *cgrp) |
| 442 | { |
Zefan Li | f29374b | 2014-09-19 16:29:31 +0800 | [diff] [blame] | 443 | return cgrp->kn->ino; |
Tejun Heo | b166492 | 2014-02-11 11:52:49 -0500 | [diff] [blame] | 444 | } |
| 445 | |
Tejun Heo | b416864 | 2014-05-13 12:16:21 -0400 | [diff] [blame] | 446 | /* cft/css accessors for cftype->write() operation */ |
| 447 | static inline struct cftype *of_cft(struct kernfs_open_file *of) |
Tejun Heo | 7da1127 | 2013-12-05 12:28:04 -0500 | [diff] [blame] | 448 | { |
Tejun Heo | 2bd59d4 | 2014-02-11 11:52:49 -0500 | [diff] [blame] | 449 | return of->kn->priv; |
Tejun Heo | 7da1127 | 2013-12-05 12:28:04 -0500 | [diff] [blame] | 450 | } |
| 451 | |
Tejun Heo | b416864 | 2014-05-13 12:16:21 -0400 | [diff] [blame] | 452 | struct cgroup_subsys_state *of_css(struct kernfs_open_file *of); |
| 453 | |
| 454 | /* cft/css accessors for cftype->seq_*() operations */ |
| 455 | static inline struct cftype *seq_cft(struct seq_file *seq) |
| 456 | { |
| 457 | return of_cft(seq->private); |
| 458 | } |
| 459 | |
| 460 | static inline struct cgroup_subsys_state *seq_css(struct seq_file *seq) |
| 461 | { |
| 462 | return of_css(seq->private); |
| 463 | } |
Tejun Heo | 59f5296 | 2014-02-11 11:52:49 -0500 | [diff] [blame] | 464 | |
Tejun Heo | e61734c | 2014-02-12 09:29:50 -0500 | [diff] [blame] | 465 | /* |
| 466 | * Name / path handling functions. All are thin wrappers around the kernfs |
| 467 | * counterparts and can be called under any context. |
| 468 | */ |
| 469 | |
| 470 | static inline int cgroup_name(struct cgroup *cgrp, char *buf, size_t buflen) |
| 471 | { |
Tejun Heo | fdce6bf | 2014-03-19 10:23:54 -0400 | [diff] [blame] | 472 | return kernfs_name(cgrp->kn, buf, buflen); |
Tejun Heo | e61734c | 2014-02-12 09:29:50 -0500 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | static inline char * __must_check cgroup_path(struct cgroup *cgrp, char *buf, |
| 476 | size_t buflen) |
| 477 | { |
Tejun Heo | fdce6bf | 2014-03-19 10:23:54 -0400 | [diff] [blame] | 478 | return kernfs_path(cgrp->kn, buf, buflen); |
Tejun Heo | e61734c | 2014-02-12 09:29:50 -0500 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static inline void pr_cont_cgroup_name(struct cgroup *cgrp) |
| 482 | { |
Tejun Heo | fdce6bf | 2014-03-19 10:23:54 -0400 | [diff] [blame] | 483 | pr_cont_kernfs_name(cgrp->kn); |
Tejun Heo | e61734c | 2014-02-12 09:29:50 -0500 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static inline void pr_cont_cgroup_path(struct cgroup *cgrp) |
| 487 | { |
Tejun Heo | fdce6bf | 2014-03-19 10:23:54 -0400 | [diff] [blame] | 488 | pr_cont_kernfs_path(cgrp->kn); |
Tejun Heo | e61734c | 2014-02-12 09:29:50 -0500 | [diff] [blame] | 489 | } |
| 490 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 491 | #else /* !CONFIG_CGROUPS */ |
| 492 | |
Tejun Heo | f3ba538 | 2015-01-06 12:02:46 -0500 | [diff] [blame] | 493 | struct cgroup_subsys_state; |
| 494 | |
Tejun Heo | c326aa2 | 2015-05-13 16:24:16 -0400 | [diff] [blame^] | 495 | static inline void css_put(struct cgroup_subsys_state *css) {} |
| 496 | static inline int cgroup_attach_task_all(struct task_struct *from, |
| 497 | struct task_struct *t) { return 0; } |
| 498 | static inline int cgroupstats_build(struct cgroupstats *stats, |
| 499 | struct dentry *dentry) { return -EINVAL; } |
| 500 | |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 501 | static inline void cgroup_fork(struct task_struct *p) {} |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 502 | static inline void cgroup_post_fork(struct task_struct *p) {} |
Li Zefan | 1ec4183 | 2014-03-28 15:22:19 +0800 | [diff] [blame] | 503 | static inline void cgroup_exit(struct task_struct *p) {} |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 504 | |
Tejun Heo | c326aa2 | 2015-05-13 16:24:16 -0400 | [diff] [blame^] | 505 | static inline int cgroup_init_early(void) { return 0; } |
| 506 | static inline int cgroup_init(void) { return 0; } |
Sridhar Samudrala | d7926ee | 2010-05-30 22:24:39 +0200 | [diff] [blame] | 507 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 508 | #endif /* !CONFIG_CGROUPS */ |
| 509 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 510 | #endif /* _LINUX_CGROUP_H */ |