1
2#ifndef __CGROUP_INTERNAL_H
3#define __CGROUP_INTERNAL_H
4
5#include <linux/cgroup.h>
6#include <linux/kernfs.h>
7#include <linux/workqueue.h>
8#include <linux/list.h>
9#include <linux/refcount.h>
10
11#define TRACE_CGROUP_PATH_LEN 1024
12extern spinlock_t trace_cgroup_path_lock;
13extern char trace_cgroup_path[TRACE_CGROUP_PATH_LEN];
14
15
16
17
18
19
20
21
22
23
24
25#define TRACE_CGROUP_PATH(type, cgrp, ...) \
26 do { \
27 if (trace_cgroup_##type##_enabled()) { \
28 spin_lock(&trace_cgroup_path_lock); \
29 cgroup_path(cgrp, trace_cgroup_path, \
30 TRACE_CGROUP_PATH_LEN); \
31 trace_cgroup_##type(cgrp, trace_cgroup_path, \
32 ##__VA_ARGS__); \
33 spin_unlock(&trace_cgroup_path_lock); \
34 } \
35 } while (0)
36
37
38
39
40
41
42
43
44
45struct cgrp_cset_link {
46
47 struct cgroup *cgrp;
48 struct css_set *cset;
49
50
51 struct list_head cset_link;
52
53
54 struct list_head cgrp_link;
55};
56
57
58struct cgroup_taskset {
59
60 struct list_head src_csets;
61 struct list_head dst_csets;
62
63
64 int nr_tasks;
65
66
67 int ssid;
68
69
70
71
72
73
74
75
76
77
78
79
80 struct list_head *csets;
81 struct css_set *cur_cset;
82 struct task_struct *cur_task;
83};
84
85
86struct cgroup_mgctx {
87
88
89
90
91 struct list_head preloaded_src_csets;
92 struct list_head preloaded_dst_csets;
93
94
95 struct cgroup_taskset tset;
96
97
98 u16 ss_mask;
99};
100
101#define CGROUP_TASKSET_INIT(tset) \
102{ \
103 .src_csets = LIST_HEAD_INIT(tset.src_csets), \
104 .dst_csets = LIST_HEAD_INIT(tset.dst_csets), \
105 .csets = &tset.src_csets, \
106}
107
108#define CGROUP_MGCTX_INIT(name) \
109{ \
110 LIST_HEAD_INIT(name.preloaded_src_csets), \
111 LIST_HEAD_INIT(name.preloaded_dst_csets), \
112 CGROUP_TASKSET_INIT(name.tset), \
113}
114
115#define DEFINE_CGROUP_MGCTX(name) \
116 struct cgroup_mgctx name = CGROUP_MGCTX_INIT(name)
117
118struct cgroup_sb_opts {
119 u16 subsys_mask;
120 unsigned int flags;
121 char *release_agent;
122 bool cpuset_clone_children;
123 char *name;
124
125 bool none;
126};
127
128extern struct mutex cgroup_mutex;
129extern spinlock_t css_set_lock;
130extern struct cgroup_subsys *cgroup_subsys[];
131extern struct list_head cgroup_roots;
132extern struct file_system_type cgroup_fs_type;
133
134
135#define for_each_root(root) \
136 list_for_each_entry((root), &cgroup_roots, root_list)
137
138
139
140
141
142
143#define for_each_subsys(ss, ssid) \
144 for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
145 (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
146
147static inline bool cgroup_is_dead(const struct cgroup *cgrp)
148{
149 return !(cgrp->self.flags & CSS_ONLINE);
150}
151
152static inline bool notify_on_release(const struct cgroup *cgrp)
153{
154 return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
155}
156
157void put_css_set_locked(struct css_set *cset);
158
159static inline void put_css_set(struct css_set *cset)
160{
161 unsigned long flags;
162
163
164
165
166
167
168 if (refcount_dec_not_one(&cset->refcount))
169 return;
170
171 spin_lock_irqsave(&css_set_lock, flags);
172 put_css_set_locked(cset);
173 spin_unlock_irqrestore(&css_set_lock, flags);
174}
175
176
177
178
179static inline void get_css_set(struct css_set *cset)
180{
181 refcount_inc(&cset->refcount);
182}
183
184bool cgroup_ssid_enabled(int ssid);
185bool cgroup_on_dfl(const struct cgroup *cgrp);
186bool cgroup_is_thread_root(struct cgroup *cgrp);
187bool cgroup_is_threaded(struct cgroup *cgrp);
188
189struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root);
190struct cgroup *task_cgroup_from_root(struct task_struct *task,
191 struct cgroup_root *root);
192struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline);
193void cgroup_kn_unlock(struct kernfs_node *kn);
194int cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen,
195 struct cgroup_namespace *ns);
196
197void cgroup_free_root(struct cgroup_root *root);
198void init_cgroup_root(struct cgroup_root *root, struct cgroup_sb_opts *opts);
199int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask, int ref_flags);
200int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
201struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
202 struct cgroup_root *root, unsigned long magic,
203 struct cgroup_namespace *ns);
204
205int cgroup_migrate_vet_dst(struct cgroup *dst_cgrp);
206void cgroup_migrate_finish(struct cgroup_mgctx *mgctx);
207void cgroup_migrate_add_src(struct css_set *src_cset, struct cgroup *dst_cgrp,
208 struct cgroup_mgctx *mgctx);
209int cgroup_migrate_prepare_dst(struct cgroup_mgctx *mgctx);
210int cgroup_migrate(struct task_struct *leader, bool threadgroup,
211 struct cgroup_mgctx *mgctx);
212
213int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
214 bool threadgroup);
215struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup)
216 __acquires(&cgroup_threadgroup_rwsem);
217void cgroup_procs_write_finish(struct task_struct *task)
218 __releases(&cgroup_threadgroup_rwsem);
219
220void cgroup_lock_and_drain_offline(struct cgroup *cgrp);
221
222int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode);
223int cgroup_rmdir(struct kernfs_node *kn);
224int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
225 struct kernfs_root *kf_root);
226
227int cgroup_task_count(const struct cgroup *cgrp);
228
229
230
231
232int cgroup_rstat_init(struct cgroup *cgrp);
233void cgroup_rstat_exit(struct cgroup *cgrp);
234void cgroup_rstat_boot(void);
235void cgroup_base_stat_cputime_show(struct seq_file *seq);
236
237
238
239
240extern const struct proc_ns_operations cgroupns_operations;
241
242
243
244
245extern struct cftype cgroup1_base_files[];
246extern struct kernfs_syscall_ops cgroup1_kf_syscall_ops;
247
248int proc_cgroupstats_show(struct seq_file *m, void *v);
249bool cgroup1_ssid_disabled(int ssid);
250void cgroup1_pidlist_destroy_all(struct cgroup *cgrp);
251void cgroup1_release_agent(struct work_struct *work);
252void cgroup1_check_for_release(struct cgroup *cgrp);
253struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags,
254 void *data, unsigned long magic,
255 struct cgroup_namespace *ns);
256
257#endif
258