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> |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 18 | |
| 19 | #ifdef CONFIG_CGROUPS |
| 20 | |
| 21 | struct cgroupfs_root; |
| 22 | struct cgroup_subsys; |
| 23 | struct inode; |
Paul Menage | 84eea84 | 2008-07-25 01:47:00 -0700 | [diff] [blame] | 24 | struct cgroup; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 25 | |
| 26 | extern int cgroup_init_early(void); |
| 27 | extern int cgroup_init(void); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 28 | extern void cgroup_lock(void); |
Paul Menage | 84eea84 | 2008-07-25 01:47:00 -0700 | [diff] [blame] | 29 | extern bool cgroup_lock_live_group(struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 30 | extern void cgroup_unlock(void); |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 31 | extern void cgroup_fork(struct task_struct *p); |
| 32 | extern void cgroup_fork_callbacks(struct task_struct *p); |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 33 | extern void cgroup_post_fork(struct task_struct *p); |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 34 | extern void cgroup_exit(struct task_struct *p, int run_callbacks); |
Balbir Singh | 846c7bb | 2007-10-18 23:39:44 -0700 | [diff] [blame] | 35 | extern int cgroupstats_build(struct cgroupstats *stats, |
| 36 | struct dentry *dentry); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 37 | |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 38 | extern struct file_operations proc_cgroup_operations; |
| 39 | |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 40 | /* Define the enumeration of all cgroup subsystems */ |
| 41 | #define SUBSYS(_x) _x ## _subsys_id, |
| 42 | enum cgroup_subsys_id { |
| 43 | #include <linux/cgroup_subsys.h> |
| 44 | CGROUP_SUBSYS_COUNT |
| 45 | }; |
| 46 | #undef SUBSYS |
| 47 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 48 | /* Per-subsystem/per-cgroup state maintained by the system. */ |
| 49 | struct cgroup_subsys_state { |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 50 | /* |
| 51 | * The cgroup that this subsystem is attached to. Useful |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 52 | * for subsystems that want to know about the cgroup |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 53 | * hierarchy structure |
| 54 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 55 | struct cgroup *cgroup; |
| 56 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 57 | /* |
| 58 | * State maintained by the cgroup system to allow subsystems |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 59 | * to be "busy". Should be accessed via css_get(), |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 60 | * css_tryget() and and css_put(). |
| 61 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 62 | |
| 63 | atomic_t refcnt; |
| 64 | |
| 65 | unsigned long flags; |
| 66 | }; |
| 67 | |
| 68 | /* bits in struct cgroup_subsys_state flags field */ |
| 69 | enum { |
| 70 | CSS_ROOT, /* This CSS is the root of the subsystem */ |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 71 | CSS_REMOVED, /* This CSS is dead */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /* |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 75 | * Call css_get() to hold a reference on the css; it can be used |
| 76 | * for a reference obtained via: |
| 77 | * - an existing ref-counted reference to the css |
| 78 | * - task->cgroups for a locked task |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 79 | */ |
| 80 | |
| 81 | static inline void css_get(struct cgroup_subsys_state *css) |
| 82 | { |
| 83 | /* We don't need to reference count the root state */ |
| 84 | if (!test_bit(CSS_ROOT, &css->flags)) |
| 85 | atomic_inc(&css->refcnt); |
| 86 | } |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 87 | |
| 88 | static inline bool css_is_removed(struct cgroup_subsys_state *css) |
| 89 | { |
| 90 | return test_bit(CSS_REMOVED, &css->flags); |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Call css_tryget() to take a reference on a css if your existing |
| 95 | * (known-valid) reference isn't already ref-counted. Returns false if |
| 96 | * the css has been destroyed. |
| 97 | */ |
| 98 | |
| 99 | static inline bool css_tryget(struct cgroup_subsys_state *css) |
| 100 | { |
| 101 | if (test_bit(CSS_ROOT, &css->flags)) |
| 102 | return true; |
| 103 | while (!atomic_inc_not_zero(&css->refcnt)) { |
| 104 | if (test_bit(CSS_REMOVED, &css->flags)) |
| 105 | return false; |
Paul Menage | 804b3c2 | 2009-01-29 14:25:21 -0800 | [diff] [blame] | 106 | cpu_relax(); |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 107 | } |
| 108 | return true; |
| 109 | } |
| 110 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 111 | /* |
| 112 | * css_put() should be called to release a reference taken by |
Paul Menage | e7c5ec9 | 2009-01-07 18:08:38 -0800 | [diff] [blame] | 113 | * css_get() or css_tryget() |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 114 | */ |
| 115 | |
Paul Menage | 81a6a5c | 2007-10-18 23:39:38 -0700 | [diff] [blame] | 116 | extern void __css_put(struct cgroup_subsys_state *css); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 117 | static inline void css_put(struct cgroup_subsys_state *css) |
| 118 | { |
| 119 | if (!test_bit(CSS_ROOT, &css->flags)) |
Paul Menage | 81a6a5c | 2007-10-18 23:39:38 -0700 | [diff] [blame] | 120 | __css_put(css); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 123 | /* bits in struct cgroup flags field */ |
| 124 | enum { |
| 125 | /* Control Group is dead */ |
| 126 | CGRP_REMOVED, |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 127 | /* |
| 128 | * Control Group has previously had a child cgroup or a task, |
| 129 | * but no longer (only if CGRP_NOTIFY_ON_RELEASE is set) |
| 130 | */ |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 131 | CGRP_RELEASABLE, |
| 132 | /* Control Group requires release notifications to userspace */ |
| 133 | CGRP_NOTIFY_ON_RELEASE, |
| 134 | }; |
| 135 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 136 | struct cgroup { |
| 137 | unsigned long flags; /* "unsigned long" so bitops work */ |
| 138 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 139 | /* |
| 140 | * count users of this cgroup. >0 means busy, but doesn't |
| 141 | * necessarily indicate the number of tasks in the cgroup |
| 142 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 143 | atomic_t count; |
| 144 | |
| 145 | /* |
| 146 | * We link our 'sibling' struct into our parent's 'children'. |
| 147 | * Our children link their 'sibling' into our 'children'. |
| 148 | */ |
| 149 | struct list_head sibling; /* my parent's children */ |
| 150 | struct list_head children; /* my children */ |
| 151 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 152 | struct cgroup *parent; /* my parent */ |
Paul Menage | a47295e | 2009-01-07 18:07:44 -0800 | [diff] [blame] | 153 | struct dentry *dentry; /* cgroup fs entry, RCU protected */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 154 | |
| 155 | /* Private pointers for each registered subsystem */ |
| 156 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; |
| 157 | |
| 158 | struct cgroupfs_root *root; |
| 159 | struct cgroup *top_cgroup; |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * List of cg_cgroup_links pointing at css_sets with |
| 163 | * tasks in this cgroup. Protected by css_set_lock |
| 164 | */ |
| 165 | struct list_head css_sets; |
Paul Menage | 81a6a5c | 2007-10-18 23:39:38 -0700 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * Linked list running through all cgroups that can |
| 169 | * potentially be reaped by the release agent. Protected by |
| 170 | * release_list_lock |
| 171 | */ |
| 172 | struct list_head release_list; |
Paul Menage | cc31edc | 2008-10-18 20:28:04 -0700 | [diff] [blame] | 173 | |
| 174 | /* pids_mutex protects the fields below */ |
| 175 | struct rw_semaphore pids_mutex; |
| 176 | /* Array of process ids in the cgroup */ |
| 177 | pid_t *tasks_pids; |
| 178 | /* How many files are using the current tasks_pids array */ |
| 179 | int pids_use_count; |
| 180 | /* Length of the current tasks_pids array */ |
| 181 | int pids_length; |
Paul Menage | a47295e | 2009-01-07 18:07:44 -0800 | [diff] [blame] | 182 | |
| 183 | /* For RCU-protected deletion */ |
| 184 | struct rcu_head rcu_head; |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 187 | /* |
| 188 | * A css_set is a structure holding pointers to a set of |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 189 | * cgroup_subsys_state objects. This saves space in the task struct |
| 190 | * 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^] | 191 | * list_add()/del() can bump the reference count on the entire cgroup |
| 192 | * set for a task. |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 193 | */ |
| 194 | |
| 195 | struct css_set { |
| 196 | |
| 197 | /* Reference count */ |
Lai Jiangshan | 146aa1b | 2008-10-18 20:28:03 -0700 | [diff] [blame] | 198 | atomic_t refcount; |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 199 | |
| 200 | /* |
Li Zefan | 472b105 | 2008-04-29 01:00:11 -0700 | [diff] [blame] | 201 | * List running through all cgroup groups in the same hash |
| 202 | * slot. Protected by css_set_lock |
| 203 | */ |
| 204 | struct hlist_node hlist; |
| 205 | |
| 206 | /* |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 207 | * List running through all tasks using this cgroup |
| 208 | * group. Protected by css_set_lock |
| 209 | */ |
| 210 | struct list_head tasks; |
| 211 | |
| 212 | /* |
| 213 | * List of cg_cgroup_link objects on link chains from |
| 214 | * cgroups referenced from this css_set. Protected by |
| 215 | * css_set_lock |
| 216 | */ |
| 217 | struct list_head cg_links; |
| 218 | |
| 219 | /* |
| 220 | * Set of subsystem states, one for each subsystem. This array |
| 221 | * is immutable after creation apart from the init_css_set |
| 222 | * during subsystem registration (at boot time). |
| 223 | */ |
| 224 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 227 | /* |
| 228 | * cgroup_map_cb is an abstract callback API for reporting map-valued |
| 229 | * control files |
| 230 | */ |
| 231 | |
| 232 | struct cgroup_map_cb { |
| 233 | int (*fill)(struct cgroup_map_cb *cb, const char *key, u64 value); |
| 234 | void *state; |
| 235 | }; |
| 236 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 237 | /* |
| 238 | * struct cftype: handler definitions for cgroup control files |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 239 | * |
| 240 | * When reading/writing to a file: |
Li Zefan | a043e3b | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 241 | * - the cgroup to use is file->f_dentry->d_parent->d_fsdata |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 242 | * - the 'cftype' of the file is file->f_dentry->d_fsdata |
| 243 | */ |
| 244 | |
| 245 | #define MAX_CFTYPE_NAME 64 |
| 246 | struct cftype { |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 247 | /* |
| 248 | * By convention, the name should begin with the name of the |
| 249 | * subsystem, followed by a period |
| 250 | */ |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 251 | char name[MAX_CFTYPE_NAME]; |
| 252 | int private; |
Paul Menage | db3b149 | 2008-07-25 01:46:58 -0700 | [diff] [blame] | 253 | |
| 254 | /* |
| 255 | * If non-zero, defines the maximum length of string that can |
| 256 | * be passed to write_string; defaults to 64 |
| 257 | */ |
| 258 | size_t max_write_len; |
| 259 | |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 260 | int (*open)(struct inode *inode, struct file *file); |
| 261 | ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft, |
| 262 | struct file *file, |
| 263 | char __user *buf, size_t nbytes, loff_t *ppos); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 264 | /* |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 265 | * read_u64() is a shortcut for the common case of returning a |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 266 | * single integer. Use it in place of read() |
| 267 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 268 | u64 (*read_u64)(struct cgroup *cgrp, struct cftype *cft); |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 269 | /* |
Paul Menage | e73d2c6 | 2008-04-29 01:00:06 -0700 | [diff] [blame] | 270 | * read_s64() is a signed version of read_u64() |
| 271 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 272 | s64 (*read_s64)(struct cgroup *cgrp, struct cftype *cft); |
Paul Menage | e73d2c6 | 2008-04-29 01:00:06 -0700 | [diff] [blame] | 273 | /* |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 274 | * read_map() is used for defining a map of key/value |
| 275 | * pairs. It should call cb->fill(cb, key, value) for each |
| 276 | * entry. The key/value pairs (and their ordering) should not |
| 277 | * change between reboots. |
| 278 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 279 | int (*read_map)(struct cgroup *cont, struct cftype *cft, |
| 280 | struct cgroup_map_cb *cb); |
Serge E. Hallyn | 29486df | 2008-04-29 01:00:14 -0700 | [diff] [blame] | 281 | /* |
| 282 | * read_seq_string() is used for outputting a simple sequence |
| 283 | * using seqfile. |
| 284 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 285 | int (*read_seq_string)(struct cgroup *cont, struct cftype *cft, |
| 286 | struct seq_file *m); |
Paul Menage | 9179656 | 2008-04-29 01:00:01 -0700 | [diff] [blame] | 287 | |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 288 | ssize_t (*write)(struct cgroup *cgrp, struct cftype *cft, |
| 289 | struct file *file, |
| 290 | const char __user *buf, size_t nbytes, loff_t *ppos); |
Paul Menage | 355e0c4 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 291 | |
| 292 | /* |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 293 | * write_u64() is a shortcut for the common case of accepting |
Paul Menage | 355e0c4 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 294 | * a single integer (as parsed by simple_strtoull) from |
| 295 | * userspace. Use in place of write(); return 0 or error. |
| 296 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 297 | int (*write_u64)(struct cgroup *cgrp, struct cftype *cft, u64 val); |
Paul Menage | e73d2c6 | 2008-04-29 01:00:06 -0700 | [diff] [blame] | 298 | /* |
| 299 | * write_s64() is a signed version of write_u64() |
| 300 | */ |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 301 | int (*write_s64)(struct cgroup *cgrp, struct cftype *cft, s64 val); |
Paul Menage | 355e0c4 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 302 | |
Pavel Emelyanov | d447ea2 | 2008-04-29 01:00:08 -0700 | [diff] [blame] | 303 | /* |
Paul Menage | db3b149 | 2008-07-25 01:46:58 -0700 | [diff] [blame] | 304 | * write_string() is passed a nul-terminated kernelspace |
| 305 | * buffer of maximum length determined by max_write_len. |
| 306 | * Returns 0 or -ve error code. |
| 307 | */ |
| 308 | int (*write_string)(struct cgroup *cgrp, struct cftype *cft, |
| 309 | const char *buffer); |
| 310 | /* |
Pavel Emelyanov | d447ea2 | 2008-04-29 01:00:08 -0700 | [diff] [blame] | 311 | * trigger() callback can be used to get some kick from the |
| 312 | * userspace, when the actual string written is not important |
| 313 | * at all. The private field can be used to determine the |
| 314 | * kick type for multiplexing. |
| 315 | */ |
| 316 | int (*trigger)(struct cgroup *cgrp, unsigned int event); |
| 317 | |
Paul Menage | ce16b49 | 2008-07-25 01:46:57 -0700 | [diff] [blame] | 318 | int (*release)(struct inode *inode, struct file *file); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 321 | struct cgroup_scanner { |
| 322 | struct cgroup *cg; |
| 323 | int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan); |
| 324 | void (*process_task)(struct task_struct *p, |
| 325 | struct cgroup_scanner *scan); |
| 326 | struct ptr_heap *heap; |
| 327 | }; |
| 328 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 329 | /* |
| 330 | * Add a new file to the given cgroup directory. Should only be |
| 331 | * called by subsystems from within a populate() method |
| 332 | */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 333 | int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys, |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 334 | const struct cftype *cft); |
| 335 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 336 | /* |
| 337 | * Add a set of new files to the given cgroup directory. Should |
| 338 | * only be called by subsystems from within a populate() method |
| 339 | */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 340 | int cgroup_add_files(struct cgroup *cgrp, |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 341 | struct cgroup_subsys *subsys, |
| 342 | const struct cftype cft[], |
| 343 | int count); |
| 344 | |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 345 | int cgroup_is_removed(const struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 346 | |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 347 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 348 | |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 349 | int cgroup_task_count(const struct cgroup *cgrp); |
Paul Menage | bbcb81d | 2007-10-18 23:39:32 -0700 | [diff] [blame] | 350 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 351 | /* Return true if the cgroup is a descendant of the current cgroup */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 352 | int cgroup_is_descendant(const struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 353 | |
| 354 | /* Control Group subsystem type. See Documentation/cgroups.txt for details */ |
| 355 | |
| 356 | struct cgroup_subsys { |
| 357 | struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss, |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 358 | struct cgroup *cgrp); |
| 359 | void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp); |
| 360 | void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 361 | int (*can_attach)(struct cgroup_subsys *ss, |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 362 | struct cgroup *cgrp, struct task_struct *tsk); |
| 363 | void (*attach)(struct cgroup_subsys *ss, struct cgroup *cgrp, |
| 364 | struct cgroup *old_cgrp, struct task_struct *tsk); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 365 | void (*fork)(struct cgroup_subsys *ss, struct task_struct *task); |
| 366 | void (*exit)(struct cgroup_subsys *ss, struct task_struct *task); |
| 367 | int (*populate)(struct cgroup_subsys *ss, |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 368 | struct cgroup *cgrp); |
| 369 | void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cgrp); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 370 | void (*bind)(struct cgroup_subsys *ss, struct cgroup *root); |
Hugh Dickins | e599137 | 2009-01-06 14:39:22 -0800 | [diff] [blame] | 371 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 372 | int subsys_id; |
| 373 | int active; |
Paul Menage | 8bab8dd | 2008-04-04 14:29:57 -0700 | [diff] [blame] | 374 | int disabled; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 375 | int early_init; |
| 376 | #define MAX_CGROUP_TYPE_NAMELEN 32 |
| 377 | const char *name; |
| 378 | |
Paul Menage | 999cd8a | 2009-01-07 18:08:36 -0800 | [diff] [blame] | 379 | /* |
| 380 | * Protects sibling/children links of cgroups in this |
| 381 | * hierarchy, plus protects which hierarchy (or none) the |
| 382 | * subsystem is a part of (i.e. root/sibling). To avoid |
| 383 | * potential deadlocks, the following operations should not be |
| 384 | * undertaken while holding any hierarchy_mutex: |
| 385 | * |
| 386 | * - allocating memory |
| 387 | * - initiating hotplug events |
| 388 | */ |
| 389 | struct mutex hierarchy_mutex; |
Li Zefan | cfebe56 | 2009-02-11 13:04:36 -0800 | [diff] [blame] | 390 | struct lock_class_key subsys_key; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 391 | |
Paul Menage | 999cd8a | 2009-01-07 18:08:36 -0800 | [diff] [blame] | 392 | /* |
| 393 | * Link to parent, and list entry in parent's children. |
| 394 | * Protected by this->hierarchy_mutex and cgroup_lock() |
| 395 | */ |
| 396 | struct cgroupfs_root *root; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 397 | struct list_head sibling; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | #define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys; |
| 401 | #include <linux/cgroup_subsys.h> |
| 402 | #undef SUBSYS |
| 403 | |
| 404 | static inline struct cgroup_subsys_state *cgroup_subsys_state( |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 405 | struct cgroup *cgrp, int subsys_id) |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 406 | { |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 407 | return cgrp->subsys[subsys_id]; |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static inline struct cgroup_subsys_state *task_subsys_state( |
| 411 | struct task_struct *task, int subsys_id) |
| 412 | { |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 413 | return rcu_dereference(task->cgroups->subsys[subsys_id]); |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static inline struct cgroup* task_cgroup(struct task_struct *task, |
| 417 | int subsys_id) |
| 418 | { |
| 419 | return task_subsys_state(task, subsys_id)->cgroup; |
| 420 | } |
| 421 | |
Serge E. Hallyn | e885dcd | 2008-07-25 01:47:06 -0700 | [diff] [blame] | 422 | int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *ss, |
| 423 | char *nodename); |
Paul Menage | 697f416 | 2007-10-18 23:39:34 -0700 | [diff] [blame] | 424 | |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 425 | /* A cgroup_iter should be treated as an opaque object */ |
| 426 | struct cgroup_iter { |
| 427 | struct list_head *cg_link; |
| 428 | struct list_head *task; |
| 429 | }; |
| 430 | |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 431 | /* |
| 432 | * To iterate across the tasks in a cgroup: |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 433 | * |
| 434 | * 1) call cgroup_iter_start to intialize an iterator |
| 435 | * |
| 436 | * 2) call cgroup_iter_next() to retrieve member tasks until it |
| 437 | * returns NULL or until you want to end the iteration |
| 438 | * |
| 439 | * 3) call cgroup_iter_end() to destroy the iterator. |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 440 | * |
Paul Menage | d20a390 | 2009-04-02 16:57:22 -0700 | [diff] [blame^] | 441 | * Or, call cgroup_scan_tasks() to iterate through every task in a |
| 442 | * cgroup - cgroup_scan_tasks() holds the css_set_lock when calling |
| 443 | * the test_task() callback, but not while calling the process_task() |
| 444 | * callback. |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 445 | */ |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 446 | void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it); |
| 447 | struct task_struct *cgroup_iter_next(struct cgroup *cgrp, |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 448 | struct cgroup_iter *it); |
Li Zefan | ffd2d88 | 2008-02-23 15:24:09 -0800 | [diff] [blame] | 449 | void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it); |
Cliff Wickman | 31a7df0 | 2008-02-07 00:14:42 -0800 | [diff] [blame] | 450 | int cgroup_scan_tasks(struct cgroup_scanner *scan); |
Cliff Wickman | 956db3c | 2008-02-07 00:14:43 -0800 | [diff] [blame] | 451 | int cgroup_attach_task(struct cgroup *, struct task_struct *); |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 452 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 453 | #else /* !CONFIG_CGROUPS */ |
| 454 | |
| 455 | static inline int cgroup_init_early(void) { return 0; } |
| 456 | static inline int cgroup_init(void) { return 0; } |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 457 | static inline void cgroup_fork(struct task_struct *p) {} |
| 458 | static inline void cgroup_fork_callbacks(struct task_struct *p) {} |
Paul Menage | 817929e | 2007-10-18 23:39:36 -0700 | [diff] [blame] | 459 | static inline void cgroup_post_fork(struct task_struct *p) {} |
Paul Menage | b4f48b6 | 2007-10-18 23:39:33 -0700 | [diff] [blame] | 460 | static inline void cgroup_exit(struct task_struct *p, int callbacks) {} |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 461 | |
| 462 | static inline void cgroup_lock(void) {} |
| 463 | static inline void cgroup_unlock(void) {} |
Balbir Singh | 846c7bb | 2007-10-18 23:39:44 -0700 | [diff] [blame] | 464 | static inline int cgroupstats_build(struct cgroupstats *stats, |
| 465 | struct dentry *dentry) |
| 466 | { |
| 467 | return -EINVAL; |
| 468 | } |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 469 | |
| 470 | #endif /* !CONFIG_CGROUPS */ |
| 471 | |
Paul Menage | ddbcc7e | 2007-10-18 23:39:30 -0700 | [diff] [blame] | 472 | #endif /* _LINUX_CGROUP_H */ |