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> |
| 14 | #include <linux/rcupdate.h> |
Balbir Singh | 846c7bb | 2007-10-18 23:39:44 -0700 | [diff] [blame] | 15 | #include <linux/cgroupstats.h> |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 16 | #include <linux/prio_heap.h> |
Paul Menage | cc31edc | 2008-10-18 20:28:04 -0700 | [diff] [blame] | 17 | #include <linux/rwsem.h> |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 18 | #include <linux/idr.h> |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef CONFIG_CGROUPS |
| 21 | |
| 22 | struct cgroupfs_root; |
| 23 | struct cgroup_subsys; |
| 24 | struct inode; |
Paul Menage | 84eea84 | 2008-07-25 01:47:00 -0700 | [diff] [blame] | 25 | struct cgroup; |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 26 | struct css_id; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 27 | |
| 28 | extern int cgroup_init_early(void); |
| 29 | extern int cgroup_init(void); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 30 | extern void cgroup_lock(void); |
Paul E. McKenney | d11c563 | 2010-02-22 17:04:50 -0800 | [diff] [blame] | 31 | extern int cgroup_lock_is_held(void); |
Paul Menage | 84eea84 | 2008-07-25 01:47:00 -0700 | [diff] [blame] | 32 | extern bool cgroup_lock_live_group(struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 33 | extern void cgroup_unlock(void); |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 34 | extern void cgroup_fork(struct task_struct *p); |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 35 | extern void cgroup_post_fork(struct task_struct *p); |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 36 | extern void cgroup_exit(struct task_struct *p, int run_callbacks); |
Balbir Singh | 846c7bb | 2007-10-18 23:39:44 -0700 | [diff] [blame] | 37 | extern int cgroupstats_build(struct cgroupstats *stats, |
| 38 | struct dentry *dentry); |
Ben Blum | e6a1105 | 2010-03-10 15:22:09 -0800 | [diff] [blame] | 39 | extern int cgroup_load_subsys(struct cgroup_subsys *ss); |
Ben Blum | cf5d594 | 2010-03-10 15:22:09 -0800 | [diff] [blame] | 40 | extern void cgroup_unload_subsys(struct cgroup_subsys *ss); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 41 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 42 | extern const struct file_operations proc_cgroup_operations; |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 43 | |
Ben Blum | aae8aab | 2010-03-10 15:22:07 -0800 | [diff] [blame] | 44 | /* Define the enumeration of all builtin cgroup subsystems */ |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 45 | #define SUBSYS(_x) _x ## _subsys_id, |
| 46 | enum cgroup_subsys_id { |
| 47 | #include <linux/cgroup_subsys.h> |
Ben Blum | aae8aab | 2010-03-10 15:22:07 -0800 | [diff] [blame] | 48 | CGROUP_BUILTIN_SUBSYS_COUNT |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 49 | }; |
| 50 | #undef SUBSYS |
Ben Blum | aae8aab | 2010-03-10 15:22:07 -0800 | [diff] [blame] | 51 | /* |
| 52 | * This define indicates the maximum number of subsystems that can be loaded |
| 53 | * at once. We limit to this many since cgroupfs_root has subsys_bits to keep |
| 54 | * track of all of them. |
| 55 | */ |
| 56 | #define CGROUP_SUBSYS_COUNT (BITS_PER_BYTE*sizeof(unsigned long)) |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 57 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 58 | /* Per-subsystem/per-cgroup state maintained by the system. */ |
| 59 | struct cgroup_subsys_state { |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 60 | /* |
| 61 | * The cgroup that this subsystem is attached to. Useful |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 62 | * for subsystems that want to know about the cgroup |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 63 | * hierarchy structure |
| 64 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 65 | struct cgroup *cgroup; |
| 66 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 67 | /* |
| 68 | * State maintained by the cgroup system to allow subsystems |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 69 | * to be "busy". Should be accessed via css_get(), |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 70 | * css_tryget() and and css_put(). |
| 71 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 72 | |
| 73 | atomic_t refcnt; |
| 74 | |
| 75 | unsigned long flags; |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 76 | /* ID for this css, if possible */ |
Arnd Bergmann | 2c392b8 | 2010-02-24 19:41:39 +0100 | [diff] [blame] | 77 | struct css_id __rcu *id; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /* bits in struct cgroup_subsys_state flags field */ |
| 81 | enum { |
| 82 | CSS_ROOT, /* This CSS is the root of the subsystem */ |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 83 | CSS_REMOVED, /* This CSS is dead */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /* |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 87 | * Call css_get() to hold a reference on the css; it can be used |
| 88 | * for a reference obtained via: |
| 89 | * - an existing ref-counted reference to the css |
| 90 | * - task->cgroups for a locked task |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 91 | */ |
| 92 | |
Colin Cross | c0f6fa8 | 2010-11-23 21:37:03 -0800 | [diff] [blame] | 93 | extern void __css_get(struct cgroup_subsys_state *css, int count); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 94 | static inline void css_get(struct cgroup_subsys_state *css) |
| 95 | { |
| 96 | /* We don't need to reference count the root state */ |
| 97 | if (!test_bit(CSS_ROOT, &css->flags)) |
Daisuke Nishimura | d7b9fff | 2010-03-10 15:22:05 -0800 | [diff] [blame] | 98 | __css_get(css, 1); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 99 | } |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 100 | |
| 101 | static inline bool css_is_removed(struct cgroup_subsys_state *css) |
| 102 | { |
| 103 | return test_bit(CSS_REMOVED, &css->flags); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Call css_tryget() to take a reference on a css if your existing |
| 108 | * (known-valid) reference isn't already ref-counted. Returns false if |
| 109 | * the css has been destroyed. |
| 110 | */ |
| 111 | |
| 112 | static inline bool css_tryget(struct cgroup_subsys_state *css) |
| 113 | { |
| 114 | if (test_bit(CSS_ROOT, &css->flags)) |
| 115 | return true; |
| 116 | while (!atomic_inc_not_zero(&css->refcnt)) { |
| 117 | if (test_bit(CSS_REMOVED, &css->flags)) |
| 118 | return false; |
Paul Menage | 804b3c2 | 2009-01-29 14:25:21 -0800 | [diff] [blame] | 119 | cpu_relax(); |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 120 | } |
| 121 | return true; |
| 122 | } |
| 123 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 124 | /* |
| 125 | * css_put() should be called to release a reference taken by |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 126 | * css_get() or css_tryget() |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 127 | */ |
| 128 | |
Daisuke Nishimura | d7b9fff | 2010-03-10 15:22:05 -0800 | [diff] [blame] | 129 | extern void __css_put(struct cgroup_subsys_state *css, int count); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 130 | static inline void css_put(struct cgroup_subsys_state *css) |
| 131 | { |
| 132 | if (!test_bit(CSS_ROOT, &css->flags)) |
Daisuke Nishimura | d7b9fff | 2010-03-10 15:22:05 -0800 | [diff] [blame] | 133 | __css_put(css, 1); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 136 | /* bits in struct cgroup flags field */ |
| 137 | enum { |
| 138 | /* Control Group is dead */ |
| 139 | CGRP_REMOVED, |
Colin Cross | c0f6fa8 | 2010-11-23 21:37:03 -0800 | [diff] [blame] | 140 | /* Control Group has ever had a child cgroup or a task */ |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 141 | CGRP_RELEASABLE, |
| 142 | /* Control Group requires release notifications to userspace */ |
| 143 | CGRP_NOTIFY_ON_RELEASE, |
KAMEZAWA Hiroyuki | ec64f51 | 2009-04-02 16:57:26 -0700 | [diff] [blame] | 144 | /* |
| 145 | * A thread in rmdir() is wating for this cgroup. |
| 146 | */ |
| 147 | CGRP_WAIT_ON_RMDIR, |
Daniel Lezcano | 97978e6 | 2010-10-27 15:33:35 -0700 | [diff] [blame] | 148 | /* |
| 149 | * Clone cgroup values when creating a new child cgroup |
| 150 | */ |
| 151 | CGRP_CLONE_CHILDREN, |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 154 | struct cgroup { |
| 155 | unsigned long flags; /* "unsigned long" so bitops work */ |
| 156 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 157 | /* |
| 158 | * count users of this cgroup. >0 means busy, but doesn't |
| 159 | * necessarily indicate the number of tasks in the cgroup |
| 160 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 161 | atomic_t count; |
| 162 | |
| 163 | /* |
| 164 | * We link our 'sibling' struct into our parent's 'children'. |
| 165 | * Our children link their 'sibling' into our 'children'. |
| 166 | */ |
| 167 | struct list_head sibling; /* my parent's children */ |
| 168 | struct list_head children; /* my children */ |
| 169 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 170 | struct cgroup *parent; /* my parent */ |
Arnd Bergmann | 2c392b8 | 2010-02-24 19:41:39 +0100 | [diff] [blame] | 171 | struct dentry __rcu *dentry; /* cgroup fs entry, RCU protected */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 172 | |
| 173 | /* Private pointers for each registered subsystem */ |
| 174 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; |
| 175 | |
| 176 | struct cgroupfs_root *root; |
| 177 | struct cgroup *top_cgroup; |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * List of cg_cgroup_links pointing at css_sets with |
| 181 | * tasks in this cgroup. Protected by css_set_lock |
| 182 | */ |
| 183 | struct list_head css_sets; |
Paul Menage | 81a6a5c | 2007-10-18 23:39:38 -0700 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Linked list running through all cgroups that can |
| 187 | * potentially be reaped by the release agent. Protected by |
| 188 | * release_list_lock |
| 189 | */ |
| 190 | struct list_head release_list; |
Paul Menage | cc31edc | 2008-10-18 20:28:04 -0700 | [diff] [blame] | 191 | |
Ben Blum | 72a8cb3 | 2009-09-23 15:56:27 -0700 | [diff] [blame] | 192 | /* |
| 193 | * list of pidlists, up to two for each namespace (one for procs, one |
| 194 | * for tasks); created on demand. |
| 195 | */ |
| 196 | struct list_head pidlists; |
| 197 | struct mutex pidlist_mutex; |
Paul Menage | a47295e | 2009-01-07 18:07:44 -0800 | [diff] [blame] | 198 | |
| 199 | /* For RCU-protected deletion */ |
| 200 | struct rcu_head rcu_head; |
Kirill A. Shutemov | 0dea116 | 2010-03-10 15:22:20 -0800 | [diff] [blame] | 201 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 202 | /* List of events which userspace want to receive */ |
Kirill A. Shutemov | 0dea116 | 2010-03-10 15:22:20 -0800 | [diff] [blame] | 203 | struct list_head event_list; |
| 204 | spinlock_t event_list_lock; |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 207 | /* |
| 208 | * A css_set is a structure holding pointers to a set of |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 209 | * cgroup_subsys_state objects. This saves space in the task struct |
| 210 | * object and speeds up fork()/exit(), since a single inc/dec and a |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 211 | * list_add()/del() can bump the reference count on the entire cgroup |
| 212 | * set for a task. |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 213 | */ |
| 214 | |
| 215 | struct css_set { |
| 216 | |
| 217 | /* Reference count */ |
Lai Jiangshan | 146aa1b | 2008-10-18 20:28:03 -0700 | [diff] [blame] | 218 | atomic_t refcount; |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
Li Zefan | 472b105 | 2008-04-29 01:00:11 -0700 | [diff] [blame] | 221 | * List running through all cgroup groups in the same hash |
| 222 | * slot. Protected by css_set_lock |
| 223 | */ |
| 224 | struct hlist_node hlist; |
| 225 | |
| 226 | /* |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 227 | * List running through all tasks using this cgroup |
| 228 | * group. Protected by css_set_lock |
| 229 | */ |
| 230 | struct list_head tasks; |
| 231 | |
| 232 | /* |
| 233 | * List of cg_cgroup_link objects on link chains from |
| 234 | * cgroups referenced from this css_set. Protected by |
| 235 | * css_set_lock |
| 236 | */ |
| 237 | struct list_head cg_links; |
| 238 | |
| 239 | /* |
| 240 | * Set of subsystem states, one for each subsystem. This array |
| 241 | * is immutable after creation apart from the init_css_set |
Ben Blum | cf5d594 | 2010-03-10 15:22:09 -0800 | [diff] [blame] | 242 | * during subsystem registration (at boot time) and modular subsystem |
| 243 | * loading/unloading. |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 244 | */ |
| 245 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; |
Ben Blum | c378369 | 2009-09-23 15:56:29 -0700 | [diff] [blame] | 246 | |
| 247 | /* For RCU-protected deletion */ |
| 248 | struct rcu_head rcu_head; |
Colin Cross | befae2f | 2010-11-23 21:37:04 -0800 | [diff] [blame] | 249 | struct work_struct work; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 252 | /* |
| 253 | * cgroup_map_cb is an abstract callback API for reporting map-valued |
| 254 | * control files |
| 255 | */ |
| 256 | |
| 257 | struct cgroup_map_cb { |
| 258 | int (*fill)(struct cgroup_map_cb *cb, const char *key, u64 value); |
| 259 | void *state; |
| 260 | }; |
| 261 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 262 | /* |
| 263 | * struct cftype: handler definitions for cgroup control files |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 264 | * |
| 265 | * When reading/writing to a file: |
Li Zefan | a043e3b | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 266 | * - the cgroup to use is file->f_dentry->d_parent->d_fsdata |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 267 | * - the 'cftype' of the file is file->f_dentry->d_fsdata |
| 268 | */ |
| 269 | |
| 270 | #define MAX_CFTYPE_NAME 64 |
| 271 | struct cftype { |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 272 | /* |
| 273 | * By convention, the name should begin with the name of the |
| 274 | * subsystem, followed by a period |
| 275 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 276 | char name[MAX_CFTYPE_NAME]; |
| 277 | int private; |
Li Zefan | 099fca3 | 2009-04-02 16:57:29 -0700 | [diff] [blame] | 278 | /* |
| 279 | * If not 0, file mode is set to this value, otherwise it will |
| 280 | * be figured out automatically |
| 281 | */ |
Al Viro | a5e7ed3 | 2011-07-26 01:55:55 -0400 | [diff] [blame] | 282 | umode_t mode; |
Paul Menage | db3b149 | 2008-07-25 01:46:58 -0700 | [diff] [blame] | 283 | |
| 284 | /* |
| 285 | * If non-zero, defines the maximum length of string that can |
| 286 | * be passed to write_string; defaults to 64 |
| 287 | */ |
| 288 | size_t max_write_len; |
| 289 | |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 290 | int (*open)(struct inode *inode, struct file *file); |
| 291 | ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft, |
| 292 | struct file *file, |
| 293 | char __user *buf, size_t nbytes, loff_t *ppos); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 294 | /* |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 295 | * read_u64() is a shortcut for the common case of returning a |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 296 | * single integer. Use it in place of read() |
| 297 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 298 | u64 (*read_u64)(struct cgroup *cgrp, struct cftype *cft); |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 299 | /* |
Paul Menage | e73d2c6 | 2008-04-29 01:00:06 -0700 | [diff] [blame] | 300 | * read_s64() is a signed version of read_u64() |
| 301 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 302 | s64 (*read_s64)(struct cgroup *cgrp, struct cftype *cft); |
Paul Menage | e73d2c6 | 2008-04-29 01:00:06 -0700 | [diff] [blame] | 303 | /* |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 304 | * read_map() is used for defining a map of key/value |
| 305 | * pairs. It should call cb->fill(cb, key, value) for each |
| 306 | * entry. The key/value pairs (and their ordering) should not |
| 307 | * change between reboots. |
| 308 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 309 | int (*read_map)(struct cgroup *cont, struct cftype *cft, |
| 310 | struct cgroup_map_cb *cb); |
Serge E. Hallyn | 29486df | 2008-04-29 01:00:14 -0700 | [diff] [blame] | 311 | /* |
| 312 | * read_seq_string() is used for outputting a simple sequence |
| 313 | * using seqfile. |
| 314 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 315 | int (*read_seq_string)(struct cgroup *cont, struct cftype *cft, |
| 316 | struct seq_file *m); |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 317 | |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 318 | ssize_t (*write)(struct cgroup *cgrp, struct cftype *cft, |
| 319 | struct file *file, |
| 320 | const char __user *buf, size_t nbytes, loff_t *ppos); |
Paul Menage | 355e0c4 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 321 | |
| 322 | /* |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 323 | * write_u64() is a shortcut for the common case of accepting |
Paul Menage | 355e0c4 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 324 | * a single integer (as parsed by simple_strtoull) from |
| 325 | * userspace. Use in place of write(); return 0 or error. |
| 326 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 327 | int (*write_u64)(struct cgroup *cgrp, struct cftype *cft, u64 val); |
Paul Menage | e73d2c6 | 2008-04-29 01:00:06 -0700 | [diff] [blame] | 328 | /* |
| 329 | * write_s64() is a signed version of write_u64() |
| 330 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 331 | int (*write_s64)(struct cgroup *cgrp, struct cftype *cft, s64 val); |
Paul Menage | 355e0c4 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 332 | |
Pavel Emelyanov | d447ea2 | 2008-04-29 01:00:08 -0700 | [diff] [blame] | 333 | /* |
Paul Menage | db3b149 | 2008-07-25 01:46:58 -0700 | [diff] [blame] | 334 | * write_string() is passed a nul-terminated kernelspace |
| 335 | * buffer of maximum length determined by max_write_len. |
| 336 | * Returns 0 or -ve error code. |
| 337 | */ |
| 338 | int (*write_string)(struct cgroup *cgrp, struct cftype *cft, |
| 339 | const char *buffer); |
| 340 | /* |
Pavel Emelyanov | d447ea2 | 2008-04-29 01:00:08 -0700 | [diff] [blame] | 341 | * trigger() callback can be used to get some kick from the |
| 342 | * userspace, when the actual string written is not important |
| 343 | * at all. The private field can be used to determine the |
| 344 | * kick type for multiplexing. |
| 345 | */ |
| 346 | int (*trigger)(struct cgroup *cgrp, unsigned int event); |
| 347 | |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 348 | int (*release)(struct inode *inode, struct file *file); |
Kirill A. Shutemov | 0dea116 | 2010-03-10 15:22:20 -0800 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * register_event() callback will be used to add new userspace |
| 352 | * waiter for changes related to the cftype. Implement it if |
| 353 | * you want to provide this functionality. Use eventfd_signal() |
| 354 | * on eventfd to send notification to userspace. |
| 355 | */ |
| 356 | int (*register_event)(struct cgroup *cgrp, struct cftype *cft, |
| 357 | struct eventfd_ctx *eventfd, const char *args); |
| 358 | /* |
| 359 | * unregister_event() callback will be called when userspace |
| 360 | * closes the eventfd or on cgroup removing. |
| 361 | * This callback must be implemented, if you want provide |
| 362 | * notification functionality. |
Kirill A. Shutemov | 0dea116 | 2010-03-10 15:22:20 -0800 | [diff] [blame] | 363 | */ |
Kirill A. Shutemov | 907860e | 2010-05-26 14:42:46 -0700 | [diff] [blame] | 364 | void (*unregister_event)(struct cgroup *cgrp, struct cftype *cft, |
Kirill A. Shutemov | 0dea116 | 2010-03-10 15:22:20 -0800 | [diff] [blame] | 365 | struct eventfd_ctx *eventfd); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 366 | }; |
| 367 | |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 368 | struct cgroup_scanner { |
| 369 | struct cgroup *cg; |
| 370 | int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan); |
| 371 | void (*process_task)(struct task_struct *p, |
| 372 | struct cgroup_scanner *scan); |
| 373 | struct ptr_heap *heap; |
Li Zefan | bd1a8ab | 2009-04-02 16:57:50 -0700 | [diff] [blame] | 374 | void *data; |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 375 | }; |
| 376 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 377 | /* |
| 378 | * Add a new file to the given cgroup directory. Should only be |
| 379 | * called by subsystems from within a populate() method |
| 380 | */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 381 | int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys, |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 382 | const struct cftype *cft); |
| 383 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 384 | /* |
| 385 | * Add a set of new files to the given cgroup directory. Should |
| 386 | * only be called by subsystems from within a populate() method |
| 387 | */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 388 | int cgroup_add_files(struct cgroup *cgrp, |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 389 | struct cgroup_subsys *subsys, |
| 390 | const struct cftype cft[], |
| 391 | int count); |
| 392 | |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 393 | int cgroup_is_removed(const struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 394 | |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 395 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 396 | |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 397 | int cgroup_task_count(const struct cgroup *cgrp); |
Paul Menage | bbcb81d | 2007-10-18 23:39:32 -0700 | [diff] [blame] | 398 | |
Grzegorz Nosek | 313e924 | 2009-04-02 16:57:23 -0700 | [diff] [blame] | 399 | /* Return true if cgrp is a descendant of the task's cgroup */ |
| 400 | int cgroup_is_descendant(const struct cgroup *cgrp, struct task_struct *task); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 401 | |
Thadeu Lima de Souza Cascardo | 21acb9c | 2009-02-04 10:12:08 +0100 | [diff] [blame] | 402 | /* |
KAMEZAWA Hiroyuki | 8870326 | 2009-07-29 15:04:06 -0700 | [diff] [blame] | 403 | * When the subsys has to access css and may add permanent refcnt to css, |
| 404 | * it should take care of racy conditions with rmdir(). Following set of |
| 405 | * functions, is for stop/restart rmdir if necessary. |
| 406 | * Because these will call css_get/put, "css" should be alive css. |
| 407 | * |
| 408 | * cgroup_exclude_rmdir(); |
| 409 | * ...do some jobs which may access arbitrary empty cgroup |
| 410 | * cgroup_release_and_wakeup_rmdir(); |
| 411 | * |
| 412 | * When someone removes a cgroup while cgroup_exclude_rmdir() holds it, |
| 413 | * it sleeps and cgroup_release_and_wakeup_rmdir() will wake him up. |
| 414 | */ |
| 415 | |
| 416 | void cgroup_exclude_rmdir(struct cgroup_subsys_state *css); |
| 417 | void cgroup_release_and_wakeup_rmdir(struct cgroup_subsys_state *css); |
| 418 | |
| 419 | /* |
Tejun Heo | 2f7ee56 | 2011-12-12 18:12:21 -0800 | [diff] [blame] | 420 | * Control Group taskset, used to pass around set of tasks to cgroup_subsys |
| 421 | * methods. |
| 422 | */ |
| 423 | struct cgroup_taskset; |
| 424 | struct task_struct *cgroup_taskset_first(struct cgroup_taskset *tset); |
| 425 | struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset); |
| 426 | struct cgroup *cgroup_taskset_cur_cgroup(struct cgroup_taskset *tset); |
| 427 | int cgroup_taskset_size(struct cgroup_taskset *tset); |
| 428 | |
| 429 | /** |
| 430 | * cgroup_taskset_for_each - iterate cgroup_taskset |
| 431 | * @task: the loop cursor |
| 432 | * @skip_cgrp: skip if task's cgroup matches this, %NULL to iterate through all |
| 433 | * @tset: taskset to iterate |
| 434 | */ |
| 435 | #define cgroup_taskset_for_each(task, skip_cgrp, tset) \ |
| 436 | for ((task) = cgroup_taskset_first((tset)); (task); \ |
| 437 | (task) = cgroup_taskset_next((tset))) \ |
| 438 | if (!(skip_cgrp) || \ |
| 439 | cgroup_taskset_cur_cgroup((tset)) != (skip_cgrp)) |
| 440 | |
| 441 | /* |
Thadeu Lima de Souza Cascardo | 21acb9c | 2009-02-04 10:12:08 +0100 | [diff] [blame] | 442 | * Control Group subsystem type. |
| 443 | * See Documentation/cgroups/cgroups.txt for details |
| 444 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 445 | |
| 446 | struct cgroup_subsys { |
Li Zefan | 761b3ef | 2012-01-31 13:47:36 +0800 | [diff] [blame] | 447 | struct cgroup_subsys_state *(*create)(struct cgroup *cgrp); |
| 448 | int (*pre_destroy)(struct cgroup *cgrp); |
| 449 | void (*destroy)(struct cgroup *cgrp); |
Colin Cross | 4a12178 | 2011-07-12 19:53:24 -0700 | [diff] [blame] | 450 | int (*allow_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset); |
Li Zefan | 761b3ef | 2012-01-31 13:47:36 +0800 | [diff] [blame] | 451 | int (*can_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset); |
| 452 | void (*cancel_attach)(struct cgroup *cgrp, struct cgroup_taskset *tset); |
| 453 | void (*attach)(struct cgroup *cgrp, struct cgroup_taskset *tset); |
| 454 | void (*fork)(struct task_struct *task); |
| 455 | void (*exit)(struct cgroup *cgrp, struct cgroup *old_cgrp, |
| 456 | struct task_struct *task); |
| 457 | int (*populate)(struct cgroup_subsys *ss, struct cgroup *cgrp); |
| 458 | void (*post_clone)(struct cgroup *cgrp); |
| 459 | void (*bind)(struct cgroup *root); |
Hugh Dickins | e599137 | 2009-01-06 14:39:22 -0800 | [diff] [blame] | 460 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 461 | int subsys_id; |
| 462 | int active; |
Paul Menage | 8bab8dd | 2008-04-04 14:29:57 -0700 | [diff] [blame] | 463 | int disabled; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 464 | int early_init; |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 465 | /* |
| 466 | * True if this subsys uses ID. ID is not available before cgroup_init() |
| 467 | * (not available in early_init time.) |
| 468 | */ |
| 469 | bool use_id; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 470 | #define MAX_CGROUP_TYPE_NAMELEN 32 |
| 471 | const char *name; |
| 472 | |
Paul Menage | 999cd8a | 2009-01-07 18:08:36 -0800 | [diff] [blame] | 473 | /* |
| 474 | * Protects sibling/children links of cgroups in this |
| 475 | * hierarchy, plus protects which hierarchy (or none) the |
| 476 | * subsystem is a part of (i.e. root/sibling). To avoid |
| 477 | * potential deadlocks, the following operations should not be |
| 478 | * undertaken while holding any hierarchy_mutex: |
| 479 | * |
| 480 | * - allocating memory |
| 481 | * - initiating hotplug events |
| 482 | */ |
| 483 | struct mutex hierarchy_mutex; |
Li Zefan | cfebe56 | 2009-02-11 13:04:36 -0800 | [diff] [blame] | 484 | struct lock_class_key subsys_key; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 485 | |
Paul Menage | 999cd8a | 2009-01-07 18:08:36 -0800 | [diff] [blame] | 486 | /* |
| 487 | * Link to parent, and list entry in parent's children. |
| 488 | * Protected by this->hierarchy_mutex and cgroup_lock() |
| 489 | */ |
| 490 | struct cgroupfs_root *root; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 491 | struct list_head sibling; |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 492 | /* used when use_id == true */ |
| 493 | struct idr idr; |
Hugh Dickins | 42aee6c | 2012-03-21 16:34:21 -0700 | [diff] [blame] | 494 | spinlock_t id_lock; |
Ben Blum | e6a1105 | 2010-03-10 15:22:09 -0800 | [diff] [blame] | 495 | |
| 496 | /* should be defined only by modular subsystems */ |
| 497 | struct module *module; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 498 | }; |
| 499 | |
| 500 | #define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys; |
| 501 | #include <linux/cgroup_subsys.h> |
| 502 | #undef SUBSYS |
| 503 | |
| 504 | static inline struct cgroup_subsys_state *cgroup_subsys_state( |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 505 | struct cgroup *cgrp, int subsys_id) |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 506 | { |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 507 | return cgrp->subsys[subsys_id]; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Tejun Heo | 71a2068 | 2013-06-25 11:48:32 -0700 | [diff] [blame] | 510 | /** |
| 511 | * task_css_set_check - obtain a task's css_set with extra access conditions |
| 512 | * @task: the task to obtain css_set for |
| 513 | * @__c: extra condition expression to be passed to rcu_dereference_check() |
| 514 | * |
| 515 | * A task's css_set is RCU protected, initialized and exited while holding |
| 516 | * task_lock(), and can only be modified while holding both cgroup_mutex |
| 517 | * and task_lock() while the task is alive. This macro verifies that the |
| 518 | * caller is inside proper critical section and returns @task's css_set. |
| 519 | * |
| 520 | * The caller can also specify additional allowed conditions via @__c, such |
| 521 | * as locks used during the cgroup_subsys::attach() methods. |
| 522 | */ |
| 523 | #define task_css_set_check(task, __c) \ |
| 524 | rcu_dereference_check((task)->cgroups, \ |
| 525 | lockdep_is_held(&(task)->alloc_lock) || \ |
| 526 | cgroup_lock_is_held() || (__c)) |
| 527 | |
| 528 | /** |
| 529 | * task_subsys_state_check - obtain css for (task, subsys) w/ extra access conds |
| 530 | * @task: the target task |
| 531 | * @subsys_id: the target subsystem ID |
| 532 | * @__c: extra condition expression to be passed to rcu_dereference_check() |
| 533 | * |
| 534 | * Return the cgroup_subsys_state for the (@task, @subsys_id) pair. The |
| 535 | * synchronization rules are the same as task_css_set_check(). |
Peter Zijlstra | dc61b1d | 2010-06-08 11:40:42 +0200 | [diff] [blame] | 536 | */ |
| 537 | #define task_subsys_state_check(task, subsys_id, __c) \ |
Tejun Heo | 71a2068 | 2013-06-25 11:48:32 -0700 | [diff] [blame] | 538 | task_css_set_check((task), (__c))->subsys[(subsys_id)] |
Peter Zijlstra | dc61b1d | 2010-06-08 11:40:42 +0200 | [diff] [blame] | 539 | |
Tejun Heo | 71a2068 | 2013-06-25 11:48:32 -0700 | [diff] [blame] | 540 | /** |
| 541 | * task_css_set - obtain a task's css_set |
| 542 | * @task: the task to obtain css_set for |
| 543 | * |
| 544 | * See task_css_set_check(). |
| 545 | */ |
| 546 | static inline struct css_set *task_css_set(struct task_struct *task) |
| 547 | { |
| 548 | return task_css_set_check(task, false); |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * task_subsys_state - obtain css for (task, subsys) |
| 553 | * @task: the target task |
| 554 | * @subsys_id: the target subsystem ID |
| 555 | * |
| 556 | * See task_subsys_state_check(). |
| 557 | */ |
Peter Zijlstra | dc61b1d | 2010-06-08 11:40:42 +0200 | [diff] [blame] | 558 | static inline struct cgroup_subsys_state * |
| 559 | task_subsys_state(struct task_struct *task, int subsys_id) |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 560 | { |
Peter Zijlstra | dc61b1d | 2010-06-08 11:40:42 +0200 | [diff] [blame] | 561 | return task_subsys_state_check(task, subsys_id, false); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static inline struct cgroup* task_cgroup(struct task_struct *task, |
| 565 | int subsys_id) |
| 566 | { |
| 567 | return task_subsys_state(task, subsys_id)->cgroup; |
| 568 | } |
| 569 | |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 570 | /* A cgroup_iter should be treated as an opaque object */ |
| 571 | struct cgroup_iter { |
| 572 | struct list_head *cg_link; |
| 573 | struct list_head *task; |
| 574 | }; |
| 575 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 576 | /* |
| 577 | * To iterate across the tasks in a cgroup: |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 578 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 579 | * 1) call cgroup_iter_start to initialize an iterator |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 580 | * |
| 581 | * 2) call cgroup_iter_next() to retrieve member tasks until it |
| 582 | * returns NULL or until you want to end the iteration |
| 583 | * |
| 584 | * 3) call cgroup_iter_end() to destroy the iterator. |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 585 | * |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame] | 586 | * Or, call cgroup_scan_tasks() to iterate through every task in a |
| 587 | * cgroup - cgroup_scan_tasks() holds the css_set_lock when calling |
| 588 | * the test_task() callback, but not while calling the process_task() |
| 589 | * callback. |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 590 | */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 591 | void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it); |
| 592 | struct task_struct *cgroup_iter_next(struct cgroup *cgrp, |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 593 | struct cgroup_iter *it); |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 594 | void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it); |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 595 | int cgroup_scan_tasks(struct cgroup_scanner *scan); |
Cliff Wickman | 956db3c | 2008-02-07 00:14:43 -0800 | [diff] [blame] | 596 | int cgroup_attach_task(struct cgroup *, struct task_struct *); |
Michael S. Tsirkin | 31583bb | 2010-09-09 16:37:37 -0700 | [diff] [blame] | 597 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); |
| 598 | |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 599 | /* |
| 600 | * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works |
| 601 | * if cgroup_subsys.use_id == true. It can be used for looking up and scanning. |
| 602 | * CSS ID is assigned at cgroup allocation (create) automatically |
| 603 | * and removed when subsys calls free_css_id() function. This is because |
| 604 | * the lifetime of cgroup_subsys_state is subsys's matter. |
| 605 | * |
| 606 | * Looking up and scanning function should be called under rcu_read_lock(). |
| 607 | * Taking cgroup_mutex()/hierarchy_mutex() is not necessary for following calls. |
| 608 | * But the css returned by this routine can be "not populated yet" or "being |
| 609 | * destroyed". The caller should check css and cgroup's status. |
| 610 | */ |
| 611 | |
| 612 | /* |
| 613 | * Typically Called at ->destroy(), or somewhere the subsys frees |
| 614 | * cgroup_subsys_state. |
| 615 | */ |
| 616 | void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css); |
| 617 | |
| 618 | /* Find a cgroup_subsys_state which has given ID */ |
| 619 | |
| 620 | struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id); |
| 621 | |
| 622 | /* |
| 623 | * Get a cgroup whose id is greater than or equal to id under tree of root. |
| 624 | * Returning a cgroup_subsys_state or NULL. |
| 625 | */ |
| 626 | struct cgroup_subsys_state *css_get_next(struct cgroup_subsys *ss, int id, |
| 627 | struct cgroup_subsys_state *root, int *foundid); |
| 628 | |
| 629 | /* Returns true if root is ancestor of cg */ |
| 630 | bool css_is_ancestor(struct cgroup_subsys_state *cg, |
KAMEZAWA Hiroyuki | 0b7f569 | 2009-04-02 16:57:38 -0700 | [diff] [blame] | 631 | const struct cgroup_subsys_state *root); |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 632 | |
| 633 | /* Get id and depth of css */ |
| 634 | unsigned short css_id(struct cgroup_subsys_state *css); |
| 635 | unsigned short css_depth(struct cgroup_subsys_state *css); |
Stephane Eranian | e5d1367 | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 636 | struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id); |
KAMEZAWA Hiroyuki | 38460b4 | 2009-04-02 16:57:25 -0700 | [diff] [blame] | 637 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 638 | #else /* !CONFIG_CGROUPS */ |
| 639 | |
| 640 | static inline int cgroup_init_early(void) { return 0; } |
| 641 | static inline int cgroup_init(void) { return 0; } |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 642 | static inline void cgroup_fork(struct task_struct *p) {} |
| 643 | static inline void cgroup_fork_callbacks(struct task_struct *p) {} |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 644 | static inline void cgroup_post_fork(struct task_struct *p) {} |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 645 | static inline void cgroup_exit(struct task_struct *p, int callbacks) {} |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 646 | |
| 647 | static inline void cgroup_lock(void) {} |
| 648 | static inline void cgroup_unlock(void) {} |
Balbir Singh | 846c7bb | 2007-10-18 23:39:44 -0700 | [diff] [blame] | 649 | static inline int cgroupstats_build(struct cgroupstats *stats, |
| 650 | struct dentry *dentry) |
| 651 | { |
| 652 | return -EINVAL; |
| 653 | } |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 654 | |
Sridhar Samudrala | d7926ee | 2010-05-30 22:24:39 +0200 | [diff] [blame] | 655 | /* No cgroups - nothing to do */ |
Michael S. Tsirkin | 31583bb | 2010-09-09 16:37:37 -0700 | [diff] [blame] | 656 | static inline int cgroup_attach_task_all(struct task_struct *from, |
| 657 | struct task_struct *t) |
| 658 | { |
| 659 | return 0; |
| 660 | } |
Sridhar Samudrala | d7926ee | 2010-05-30 22:24:39 +0200 | [diff] [blame] | 661 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 662 | #endif /* !CONFIG_CGROUPS */ |
| 663 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 664 | #endif /* _LINUX_CGROUP_H */ |