debug: turn ignore_loglevel into an early param
[wrt350n-kernel.git] / include / linux / cgroup.h
blob87479328d46ddf88de95b3038f98134f74fc054e
1 #ifndef _LINUX_CGROUP_H
2 #define _LINUX_CGROUP_H
3 /*
4 * cgroup interface
6 * Copyright (C) 2003 BULL SA
7 * Copyright (C) 2004-2006 Silicon Graphics, Inc.
9 */
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>
18 #ifdef CONFIG_CGROUPS
20 struct cgroupfs_root;
21 struct cgroup_subsys;
22 struct inode;
24 extern int cgroup_init_early(void);
25 extern int cgroup_init(void);
26 extern void cgroup_init_smp(void);
27 extern void cgroup_lock(void);
28 extern void cgroup_unlock(void);
29 extern void cgroup_fork(struct task_struct *p);
30 extern void cgroup_fork_callbacks(struct task_struct *p);
31 extern void cgroup_post_fork(struct task_struct *p);
32 extern void cgroup_exit(struct task_struct *p, int run_callbacks);
33 extern int cgroupstats_build(struct cgroupstats *stats,
34 struct dentry *dentry);
36 extern struct file_operations proc_cgroup_operations;
38 /* Define the enumeration of all cgroup subsystems */
39 #define SUBSYS(_x) _x ## _subsys_id,
40 enum cgroup_subsys_id {
41 #include <linux/cgroup_subsys.h>
42 CGROUP_SUBSYS_COUNT
44 #undef SUBSYS
46 /* Per-subsystem/per-cgroup state maintained by the system. */
47 struct cgroup_subsys_state {
48 /* The cgroup that this subsystem is attached to. Useful
49 * for subsystems that want to know about the cgroup
50 * hierarchy structure */
51 struct cgroup *cgroup;
53 /* State maintained by the cgroup system to allow
54 * subsystems to be "busy". Should be accessed via css_get()
55 * and css_put() */
57 atomic_t refcnt;
59 unsigned long flags;
62 /* bits in struct cgroup_subsys_state flags field */
63 enum {
64 CSS_ROOT, /* This CSS is the root of the subsystem */
68 * Call css_get() to hold a reference on the cgroup;
72 static inline void css_get(struct cgroup_subsys_state *css)
74 /* We don't need to reference count the root state */
75 if (!test_bit(CSS_ROOT, &css->flags))
76 atomic_inc(&css->refcnt);
79 * css_put() should be called to release a reference taken by
80 * css_get()
83 extern void __css_put(struct cgroup_subsys_state *css);
84 static inline void css_put(struct cgroup_subsys_state *css)
86 if (!test_bit(CSS_ROOT, &css->flags))
87 __css_put(css);
90 struct cgroup {
91 unsigned long flags; /* "unsigned long" so bitops work */
93 /* count users of this cgroup. >0 means busy, but doesn't
94 * necessarily indicate the number of tasks in the
95 * cgroup */
96 atomic_t count;
99 * We link our 'sibling' struct into our parent's 'children'.
100 * Our children link their 'sibling' into our 'children'.
102 struct list_head sibling; /* my parent's children */
103 struct list_head children; /* my children */
105 struct cgroup *parent; /* my parent */
106 struct dentry *dentry; /* cgroup fs entry */
108 /* Private pointers for each registered subsystem */
109 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
111 struct cgroupfs_root *root;
112 struct cgroup *top_cgroup;
115 * List of cg_cgroup_links pointing at css_sets with
116 * tasks in this cgroup. Protected by css_set_lock
118 struct list_head css_sets;
121 * Linked list running through all cgroups that can
122 * potentially be reaped by the release agent. Protected by
123 * release_list_lock
125 struct list_head release_list;
128 /* A css_set is a structure holding pointers to a set of
129 * cgroup_subsys_state objects. This saves space in the task struct
130 * object and speeds up fork()/exit(), since a single inc/dec and a
131 * list_add()/del() can bump the reference count on the entire
132 * cgroup set for a task.
135 struct css_set {
137 /* Reference count */
138 struct kref ref;
141 * List running through all cgroup groups. Protected by
142 * css_set_lock
144 struct list_head list;
147 * List running through all tasks using this cgroup
148 * group. Protected by css_set_lock
150 struct list_head tasks;
153 * List of cg_cgroup_link objects on link chains from
154 * cgroups referenced from this css_set. Protected by
155 * css_set_lock
157 struct list_head cg_links;
160 * Set of subsystem states, one for each subsystem. This array
161 * is immutable after creation apart from the init_css_set
162 * during subsystem registration (at boot time).
164 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
168 /* struct cftype:
170 * The files in the cgroup filesystem mostly have a very simple read/write
171 * handling, some common function will take care of it. Nevertheless some cases
172 * (read tasks) are special and therefore I define this structure for every
173 * kind of file.
176 * When reading/writing to a file:
177 * - the cgroup to use in file->f_dentry->d_parent->d_fsdata
178 * - the 'cftype' of the file is file->f_dentry->d_fsdata
181 #define MAX_CFTYPE_NAME 64
182 struct cftype {
183 /* By convention, the name should begin with the name of the
184 * subsystem, followed by a period */
185 char name[MAX_CFTYPE_NAME];
186 int private;
187 int (*open) (struct inode *inode, struct file *file);
188 ssize_t (*read) (struct cgroup *cont, struct cftype *cft,
189 struct file *file,
190 char __user *buf, size_t nbytes, loff_t *ppos);
192 * read_uint() is a shortcut for the common case of returning a
193 * single integer. Use it in place of read()
195 u64 (*read_uint) (struct cgroup *cont, struct cftype *cft);
196 ssize_t (*write) (struct cgroup *cont, struct cftype *cft,
197 struct file *file,
198 const char __user *buf, size_t nbytes, loff_t *ppos);
201 * write_uint() is a shortcut for the common case of accepting
202 * a single integer (as parsed by simple_strtoull) from
203 * userspace. Use in place of write(); return 0 or error.
205 int (*write_uint) (struct cgroup *cont, struct cftype *cft, u64 val);
207 int (*release) (struct inode *inode, struct file *file);
210 /* Add a new file to the given cgroup directory. Should only be
211 * called by subsystems from within a populate() method */
212 int cgroup_add_file(struct cgroup *cont, struct cgroup_subsys *subsys,
213 const struct cftype *cft);
215 /* Add a set of new files to the given cgroup directory. Should
216 * only be called by subsystems from within a populate() method */
217 int cgroup_add_files(struct cgroup *cont,
218 struct cgroup_subsys *subsys,
219 const struct cftype cft[],
220 int count);
222 int cgroup_is_removed(const struct cgroup *cont);
224 int cgroup_path(const struct cgroup *cont, char *buf, int buflen);
226 int cgroup_task_count(const struct cgroup *cont);
228 /* Return true if the cgroup is a descendant of the current cgroup */
229 int cgroup_is_descendant(const struct cgroup *cont);
231 /* Control Group subsystem type. See Documentation/cgroups.txt for details */
233 struct cgroup_subsys {
234 struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
235 struct cgroup *cont);
236 void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cont);
237 int (*can_attach)(struct cgroup_subsys *ss,
238 struct cgroup *cont, struct task_struct *tsk);
239 void (*attach)(struct cgroup_subsys *ss, struct cgroup *cont,
240 struct cgroup *old_cont, struct task_struct *tsk);
241 void (*fork)(struct cgroup_subsys *ss, struct task_struct *task);
242 void (*exit)(struct cgroup_subsys *ss, struct task_struct *task);
243 int (*populate)(struct cgroup_subsys *ss,
244 struct cgroup *cont);
245 void (*post_clone)(struct cgroup_subsys *ss, struct cgroup *cont);
246 void (*bind)(struct cgroup_subsys *ss, struct cgroup *root);
247 int subsys_id;
248 int active;
249 int early_init;
250 #define MAX_CGROUP_TYPE_NAMELEN 32
251 const char *name;
253 /* Protected by RCU */
254 struct cgroupfs_root *root;
256 struct list_head sibling;
258 void *private;
261 #define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys;
262 #include <linux/cgroup_subsys.h>
263 #undef SUBSYS
265 static inline struct cgroup_subsys_state *cgroup_subsys_state(
266 struct cgroup *cont, int subsys_id)
268 return cont->subsys[subsys_id];
271 static inline struct cgroup_subsys_state *task_subsys_state(
272 struct task_struct *task, int subsys_id)
274 return rcu_dereference(task->cgroups->subsys[subsys_id]);
277 static inline struct cgroup* task_cgroup(struct task_struct *task,
278 int subsys_id)
280 return task_subsys_state(task, subsys_id)->cgroup;
283 int cgroup_path(const struct cgroup *cont, char *buf, int buflen);
285 int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *ss);
287 /* A cgroup_iter should be treated as an opaque object */
288 struct cgroup_iter {
289 struct list_head *cg_link;
290 struct list_head *task;
293 /* To iterate across the tasks in a cgroup:
295 * 1) call cgroup_iter_start to intialize an iterator
297 * 2) call cgroup_iter_next() to retrieve member tasks until it
298 * returns NULL or until you want to end the iteration
300 * 3) call cgroup_iter_end() to destroy the iterator.
302 void cgroup_iter_start(struct cgroup *cont, struct cgroup_iter *it);
303 struct task_struct *cgroup_iter_next(struct cgroup *cont,
304 struct cgroup_iter *it);
305 void cgroup_iter_end(struct cgroup *cont, struct cgroup_iter *it);
307 #else /* !CONFIG_CGROUPS */
309 static inline int cgroup_init_early(void) { return 0; }
310 static inline int cgroup_init(void) { return 0; }
311 static inline void cgroup_init_smp(void) {}
312 static inline void cgroup_fork(struct task_struct *p) {}
313 static inline void cgroup_fork_callbacks(struct task_struct *p) {}
314 static inline void cgroup_post_fork(struct task_struct *p) {}
315 static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
317 static inline void cgroup_lock(void) {}
318 static inline void cgroup_unlock(void) {}
319 static inline int cgroupstats_build(struct cgroupstats *stats,
320 struct dentry *dentry)
322 return -EINVAL;
325 #endif /* !CONFIG_CGROUPS */
327 #endif /* _LINUX_CGROUP_H */