1#ifndef _LINUX_CGROUP_H
2#define _LINUX_CGROUP_H
3
4
5
6
7
8
9
10
11#include <linux/sched.h>
12#include <linux/cpumask.h>
13#include <linux/nodemask.h>
14#include <linux/rcupdate.h>
15#include <linux/cgroupstats.h>
16#include <linux/prio_heap.h>
17#include <linux/rwsem.h>
18
19#ifdef CONFIG_CGROUPS
20
21struct cgroupfs_root;
22struct cgroup_subsys;
23struct inode;
24struct cgroup;
25
26extern int cgroup_init_early(void);
27extern int cgroup_init(void);
28extern void cgroup_lock(void);
29extern bool cgroup_lock_live_group(struct cgroup *cgrp);
30extern void cgroup_unlock(void);
31extern void cgroup_fork(struct task_struct *p);
32extern void cgroup_fork_callbacks(struct task_struct *p);
33extern void cgroup_post_fork(struct task_struct *p);
34extern void cgroup_exit(struct task_struct *p, int run_callbacks);
35extern int cgroupstats_build(struct cgroupstats *stats,
36 struct dentry *dentry);
37
38extern struct file_operations proc_cgroup_operations;
39
40
41#define SUBSYS(_x) _x ## _subsys_id,
42enum cgroup_subsys_id {
43#include <linux/cgroup_subsys.h>
44 CGROUP_SUBSYS_COUNT
45};
46#undef SUBSYS
47
48
49struct cgroup_subsys_state {
50
51
52
53 struct cgroup *cgroup;
54
55
56
57
58
59 atomic_t refcnt;
60
61 unsigned long flags;
62};
63
64
65enum {
66 CSS_ROOT,
67};
68
69
70
71
72
73
74static inline void css_get(struct cgroup_subsys_state *css)
75{
76
77 if (!test_bit(CSS_ROOT, &css->flags))
78 atomic_inc(&css->refcnt);
79}
80
81
82
83
84
85extern void __css_put(struct cgroup_subsys_state *css);
86static inline void css_put(struct cgroup_subsys_state *css)
87{
88 if (!test_bit(CSS_ROOT, &css->flags))
89 __css_put(css);
90}
91
92
93enum {
94
95 CGRP_REMOVED,
96
97
98 CGRP_RELEASABLE,
99
100 CGRP_NOTIFY_ON_RELEASE,
101};
102
103struct cgroup {
104 unsigned long flags;
105
106
107
108
109 atomic_t count;
110
111
112
113
114
115 struct list_head sibling;
116 struct list_head children;
117
118 struct cgroup *parent;
119 struct dentry *dentry;
120
121
122 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
123
124 struct cgroupfs_root *root;
125 struct cgroup *top_cgroup;
126
127
128
129
130
131 struct list_head css_sets;
132
133
134
135
136
137
138 struct list_head release_list;
139
140
141 struct rw_semaphore pids_mutex;
142
143 pid_t *tasks_pids;
144
145 int pids_use_count;
146
147 int pids_length;
148};
149
150
151
152
153
154
155
156
157struct css_set {
158
159
160 atomic_t refcount;
161
162
163
164
165
166 struct hlist_node hlist;
167
168
169
170
171
172 struct list_head tasks;
173
174
175
176
177
178
179 struct list_head cg_links;
180
181
182
183
184
185
186 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
187};
188
189
190
191
192
193
194struct cgroup_map_cb {
195 int (*fill)(struct cgroup_map_cb *cb, const char *key, u64 value);
196 void *state;
197};
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212#define MAX_CFTYPE_NAME 64
213struct cftype {
214
215
216 char name[MAX_CFTYPE_NAME];
217 int private;
218
219
220
221
222
223 size_t max_write_len;
224
225 int (*open)(struct inode *inode, struct file *file);
226 ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
227 struct file *file,
228 char __user *buf, size_t nbytes, loff_t *ppos);
229
230
231
232
233 u64 (*read_u64)(struct cgroup *cgrp, struct cftype *cft);
234
235
236
237 s64 (*read_s64)(struct cgroup *cgrp, struct cftype *cft);
238
239
240
241
242
243
244 int (*read_map)(struct cgroup *cont, struct cftype *cft,
245 struct cgroup_map_cb *cb);
246
247
248
249
250 int (*read_seq_string)(struct cgroup *cont, struct cftype *cft,
251 struct seq_file *m);
252
253 ssize_t (*write)(struct cgroup *cgrp, struct cftype *cft,
254 struct file *file,
255 const char __user *buf, size_t nbytes, loff_t *ppos);
256
257
258
259
260
261
262 int (*write_u64)(struct cgroup *cgrp, struct cftype *cft, u64 val);
263
264
265
266 int (*write_s64)(struct cgroup *cgrp, struct cftype *cft, s64 val);
267
268
269
270
271
272
273 int (*write_string)(struct cgroup *cgrp, struct cftype *cft,
274 const char *buffer);
275
276
277
278
279
280
281 int (*trigger)(struct cgroup *cgrp, unsigned int event);
282
283 int (*release)(struct inode *inode, struct file *file);
284};
285
286struct cgroup_scanner {
287 struct cgroup *cg;
288 int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan);
289 void (*process_task)(struct task_struct *p,
290 struct cgroup_scanner *scan);
291 struct ptr_heap *heap;
292};
293
294
295
296int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
297 const struct cftype *cft);
298
299
300
301int cgroup_add_files(struct cgroup *cgrp,
302 struct cgroup_subsys *subsys,
303 const struct cftype cft[],
304 int count);
305
306int cgroup_is_removed(const struct cgroup *cgrp);
307
308int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
309
310int cgroup_task_count(const struct cgroup *cgrp);
311
312
313int cgroup_is_descendant(const struct cgroup *cgrp);
314
315
316
317struct cgroup_subsys {
318 struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
319 struct cgroup *cgrp);
320 void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
321 void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
322 int (*can_attach)(struct cgroup_subsys *ss,
323 struct cgroup *cgrp, struct task_struct *tsk);
324 void (*attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
325 struct cgroup *old_cgrp, struct task_struct *tsk);
326 void (*fork)(struct cgroup_subsys *ss, struct task_struct *task);
327 void (*exit)(struct cgroup_subsys *ss, struct task_struct *task);
328 int (*populate)(struct cgroup_subsys *ss,
329 struct cgroup *cgrp);
330 void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cgrp);
331 void (*bind)(struct cgroup_subsys *ss, struct cgroup *root);
332
333
334
335 void (*mm_owner_changed)(struct cgroup_subsys *ss,
336 struct cgroup *old,
337 struct cgroup *new,
338 struct task_struct *p);
339 int subsys_id;
340 int active;
341 int disabled;
342 int early_init;
343#define MAX_CGROUP_TYPE_NAMELEN 32
344 const char *name;
345
346
347 struct cgroupfs_root *root;
348
349 struct list_head sibling;
350};
351
352#define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys;
353#include <linux/cgroup_subsys.h>
354#undef SUBSYS
355
356static inline struct cgroup_subsys_state *cgroup_subsys_state(
357 struct cgroup *cgrp, int subsys_id)
358{
359 return cgrp->subsys[subsys_id];
360}
361
362static inline struct cgroup_subsys_state *task_subsys_state(
363 struct task_struct *task, int subsys_id)
364{
365 return rcu_dereference(task->cgroups->subsys[subsys_id]);
366}
367
368static inline struct cgroup* task_cgroup(struct task_struct *task,
369 int subsys_id)
370{
371 return task_subsys_state(task, subsys_id)->cgroup;
372}
373
374int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *ss,
375 char *nodename);
376
377
378struct cgroup_iter {
379 struct list_head *cg_link;
380 struct list_head *task;
381};
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it);
397struct task_struct *cgroup_iter_next(struct cgroup *cgrp,
398 struct cgroup_iter *it);
399void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it);
400int cgroup_scan_tasks(struct cgroup_scanner *scan);
401int cgroup_attach_task(struct cgroup *, struct task_struct *);
402
403void cgroup_mm_owner_callbacks(struct task_struct *old,
404 struct task_struct *new);
405
406#else
407
408static inline int cgroup_init_early(void) { return 0; }
409static inline int cgroup_init(void) { return 0; }
410static inline void cgroup_fork(struct task_struct *p) {}
411static inline void cgroup_fork_callbacks(struct task_struct *p) {}
412static inline void cgroup_post_fork(struct task_struct *p) {}
413static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
414
415static inline void cgroup_lock(void) {}
416static inline void cgroup_unlock(void) {}
417static inline int cgroupstats_build(struct cgroupstats *stats,
418 struct dentry *dentry)
419{
420 return -EINVAL;
421}
422
423static inline void cgroup_mm_owner_callbacks(struct task_struct *old,
424 struct task_struct *new) {}
425
426#endif
427
428#endif
429