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/kref.h>
13#include <linux/cpumask.h>
14#include <linux/nodemask.h>
15#include <linux/rcupdate.h>
16#include <linux/cgroupstats.h>
17#include <linux/prio_heap.h>
18
19#ifdef CONFIG_CGROUPS
20
21struct cgroupfs_root;
22struct cgroup_subsys;
23struct inode;
24
25extern int cgroup_init_early(void);
26extern int cgroup_init(void);
27extern void cgroup_init_smp(void);
28extern void cgroup_lock(void);
29extern void cgroup_unlock(void);
30extern void cgroup_fork(struct task_struct *p);
31extern void cgroup_fork_callbacks(struct task_struct *p);
32extern void cgroup_post_fork(struct task_struct *p);
33extern void cgroup_exit(struct task_struct *p, int run_callbacks);
34extern int cgroupstats_build(struct cgroupstats *stats,
35 struct dentry *dentry);
36
37extern struct file_operations proc_cgroup_operations;
38
39
40#define SUBSYS(_x) _x ## _subsys_id,
41enum cgroup_subsys_id {
42#include <linux/cgroup_subsys.h>
43 CGROUP_SUBSYS_COUNT
44};
45#undef SUBSYS
46
47
48struct cgroup_subsys_state {
49
50
51
52 struct cgroup *cgroup;
53
54
55
56
57
58 atomic_t refcnt;
59
60 unsigned long flags;
61};
62
63
64enum {
65 CSS_ROOT,
66};
67
68
69
70
71
72
73static inline void css_get(struct cgroup_subsys_state *css)
74{
75
76 if (!test_bit(CSS_ROOT, &css->flags))
77 atomic_inc(&css->refcnt);
78}
79
80
81
82
83
84extern void __css_put(struct cgroup_subsys_state *css);
85static inline void css_put(struct cgroup_subsys_state *css)
86{
87 if (!test_bit(CSS_ROOT, &css->flags))
88 __css_put(css);
89}
90
91struct cgroup {
92 unsigned long flags;
93
94
95
96
97 atomic_t count;
98
99
100
101
102
103 struct list_head sibling;
104 struct list_head children;
105
106 struct cgroup *parent;
107 struct dentry *dentry;
108
109
110 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
111
112 struct cgroupfs_root *root;
113 struct cgroup *top_cgroup;
114
115
116
117
118
119 struct list_head css_sets;
120
121
122
123
124
125
126 struct list_head release_list;
127};
128
129
130
131
132
133
134
135
136struct css_set {
137
138
139 struct kref ref;
140
141
142
143
144
145 struct list_head list;
146
147
148
149
150
151 struct list_head tasks;
152
153
154
155
156
157
158 struct list_head cg_links;
159
160
161
162
163
164
165 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
166
167};
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182#define MAX_CFTYPE_NAME 64
183struct cftype {
184
185
186 char name[MAX_CFTYPE_NAME];
187 int private;
188 int (*open) (struct inode *inode, struct file *file);
189 ssize_t (*read) (struct cgroup *cgrp, struct cftype *cft,
190 struct file *file,
191 char __user *buf, size_t nbytes, loff_t *ppos);
192
193
194
195
196 u64 (*read_uint) (struct cgroup *cgrp, struct cftype *cft);
197 ssize_t (*write) (struct cgroup *cgrp, struct cftype *cft,
198 struct file *file,
199 const char __user *buf, size_t nbytes, loff_t *ppos);
200
201
202
203
204
205
206 int (*write_uint) (struct cgroup *cgrp, struct cftype *cft, u64 val);
207
208 int (*release) (struct inode *inode, struct file *file);
209};
210
211struct cgroup_scanner {
212 struct cgroup *cg;
213 int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan);
214 void (*process_task)(struct task_struct *p,
215 struct cgroup_scanner *scan);
216 struct ptr_heap *heap;
217};
218
219
220
221int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
222 const struct cftype *cft);
223
224
225
226int cgroup_add_files(struct cgroup *cgrp,
227 struct cgroup_subsys *subsys,
228 const struct cftype cft[],
229 int count);
230
231int cgroup_is_removed(const struct cgroup *cgrp);
232
233int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
234
235int cgroup_task_count(const struct cgroup *cgrp);
236
237
238int cgroup_is_descendant(const struct cgroup *cgrp);
239
240
241
242struct cgroup_subsys {
243 struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
244 struct cgroup *cgrp);
245 void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
246 void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
247 int (*can_attach)(struct cgroup_subsys *ss,
248 struct cgroup *cgrp, struct task_struct *tsk);
249 void (*attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
250 struct cgroup *old_cgrp, struct task_struct *tsk);
251 void (*fork)(struct cgroup_subsys *ss, struct task_struct *task);
252 void (*exit)(struct cgroup_subsys *ss, struct task_struct *task);
253 int (*populate)(struct cgroup_subsys *ss,
254 struct cgroup *cgrp);
255 void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cgrp);
256 void (*bind)(struct cgroup_subsys *ss, struct cgroup *root);
257 int subsys_id;
258 int active;
259 int disabled;
260 int early_init;
261#define MAX_CGROUP_TYPE_NAMELEN 32
262 const char *name;
263
264
265 struct cgroupfs_root *root;
266
267 struct list_head sibling;
268
269 void *private;
270};
271
272#define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys;
273#include <linux/cgroup_subsys.h>
274#undef SUBSYS
275
276static inline struct cgroup_subsys_state *cgroup_subsys_state(
277 struct cgroup *cgrp, int subsys_id)
278{
279 return cgrp->subsys[subsys_id];
280}
281
282static inline struct cgroup_subsys_state *task_subsys_state(
283 struct task_struct *task, int subsys_id)
284{
285 return rcu_dereference(task->cgroups->subsys[subsys_id]);
286}
287
288static inline struct cgroup* task_cgroup(struct task_struct *task,
289 int subsys_id)
290{
291 return task_subsys_state(task, subsys_id)->cgroup;
292}
293
294int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *ss);
295
296
297struct cgroup_iter {
298 struct list_head *cg_link;
299 struct list_head *task;
300};
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315void cgroup_iter_start(struct cgroup *cgrp, struct cgroup_iter *it);
316struct task_struct *cgroup_iter_next(struct cgroup *cgrp,
317 struct cgroup_iter *it);
318void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it);
319int cgroup_scan_tasks(struct cgroup_scanner *scan);
320int cgroup_attach_task(struct cgroup *, struct task_struct *);
321
322#else
323
324static inline int cgroup_init_early(void) { return 0; }
325static inline int cgroup_init(void) { return 0; }
326static inline void cgroup_init_smp(void) {}
327static inline void cgroup_fork(struct task_struct *p) {}
328static inline void cgroup_fork_callbacks(struct task_struct *p) {}
329static inline void cgroup_post_fork(struct task_struct *p) {}
330static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
331
332static inline void cgroup_lock(void) {}
333static inline void cgroup_unlock(void) {}
334static inline int cgroupstats_build(struct cgroupstats *stats,
335 struct dentry *dentry)
336{
337 return -EINVAL;
338}
339
340#endif
341
342#endif
343