]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - kernel/cgroup/cgroup-internal.h
Merge tag 'for-linus-20170825' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-artful-kernel.git] / kernel / cgroup / cgroup-internal.h
CommitLineData
0a268dbd
TH
1#ifndef __CGROUP_INTERNAL_H
2#define __CGROUP_INTERNAL_H
3
4#include <linux/cgroup.h>
5#include <linux/kernfs.h>
6#include <linux/workqueue.h>
7#include <linux/list.h>
4b9502e6 8#include <linux/refcount.h>
0a268dbd
TH
9
10/*
11 * A cgroup can be associated with multiple css_sets as different tasks may
12 * belong to different cgroups on different hierarchies. In the other
13 * direction, a css_set is naturally associated with multiple cgroups.
14 * This M:N relationship is represented by the following link structure
15 * which exists for each association and allows traversing the associations
16 * from both sides.
17 */
18struct cgrp_cset_link {
19 /* the cgroup and css_set this link associates */
20 struct cgroup *cgrp;
21 struct css_set *cset;
22
23 /* list of cgrp_cset_links anchored at cgrp->cset_links */
24 struct list_head cset_link;
25
26 /* list of cgrp_cset_links anchored at css_set->cgrp_links */
27 struct list_head cgrp_link;
28};
29
e595cd70
TH
30/* used to track tasks and csets during migration */
31struct cgroup_taskset {
32 /* the src and dst cset list running through cset->mg_node */
33 struct list_head src_csets;
34 struct list_head dst_csets;
35
61046727
TH
36 /* the number of tasks in the set */
37 int nr_tasks;
38
e595cd70
TH
39 /* the subsys currently being processed */
40 int ssid;
41
42 /*
43 * Fields for cgroup_taskset_*() iteration.
44 *
45 * Before migration is committed, the target migration tasks are on
46 * ->mg_tasks of the csets on ->src_csets. After, on ->mg_tasks of
47 * the csets on ->dst_csets. ->csets point to either ->src_csets
48 * or ->dst_csets depending on whether migration is committed.
49 *
50 * ->cur_csets and ->cur_task point to the current task position
51 * during iteration.
52 */
53 struct list_head *csets;
54 struct css_set *cur_cset;
55 struct task_struct *cur_task;
56};
57
58/* migration context also tracks preloading */
59struct cgroup_mgctx {
60 /*
61 * Preloaded source and destination csets. Used to guarantee
62 * atomic success or failure on actual migration.
63 */
64 struct list_head preloaded_src_csets;
65 struct list_head preloaded_dst_csets;
66
67 /* tasks and csets to migrate */
68 struct cgroup_taskset tset;
bfc2cf6f
TH
69
70 /* subsystems affected by migration */
71 u16 ss_mask;
e595cd70
TH
72};
73
74#define CGROUP_TASKSET_INIT(tset) \
75{ \
76 .src_csets = LIST_HEAD_INIT(tset.src_csets), \
77 .dst_csets = LIST_HEAD_INIT(tset.dst_csets), \
78 .csets = &tset.src_csets, \
79}
80
81#define CGROUP_MGCTX_INIT(name) \
82{ \
83 LIST_HEAD_INIT(name.preloaded_src_csets), \
84 LIST_HEAD_INIT(name.preloaded_dst_csets), \
85 CGROUP_TASKSET_INIT(name.tset), \
86}
87
88#define DEFINE_CGROUP_MGCTX(name) \
89 struct cgroup_mgctx name = CGROUP_MGCTX_INIT(name)
90
1592c9b2
TH
91struct cgroup_sb_opts {
92 u16 subsys_mask;
93 unsigned int flags;
94 char *release_agent;
95 bool cpuset_clone_children;
96 char *name;
97 /* User explicitly requested empty subsystem */
98 bool none;
99};
100
0a268dbd
TH
101extern struct mutex cgroup_mutex;
102extern spinlock_t css_set_lock;
103extern struct cgroup_subsys *cgroup_subsys[];
104extern struct list_head cgroup_roots;
105extern struct file_system_type cgroup_fs_type;
106
107/* iterate across the hierarchies */
108#define for_each_root(root) \
109 list_for_each_entry((root), &cgroup_roots, root_list)
110
111/**
112 * for_each_subsys - iterate all enabled cgroup subsystems
113 * @ss: the iteration cursor
114 * @ssid: the index of @ss, CGROUP_SUBSYS_COUNT after reaching the end
115 */
116#define for_each_subsys(ss, ssid) \
117 for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
118 (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
119
120static inline bool cgroup_is_dead(const struct cgroup *cgrp)
121{
122 return !(cgrp->self.flags & CSS_ONLINE);
123}
124
125static inline bool notify_on_release(const struct cgroup *cgrp)
126{
127 return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
128}
129
dcfe149b
TH
130void put_css_set_locked(struct css_set *cset);
131
132static inline void put_css_set(struct css_set *cset)
133{
134 unsigned long flags;
135
136 /*
137 * Ensure that the refcount doesn't hit zero while any readers
138 * can see it. Similar to atomic_dec_and_lock(), but for an
139 * rwlock
140 */
4b9502e6 141 if (refcount_dec_not_one(&cset->refcount))
dcfe149b
TH
142 return;
143
144 spin_lock_irqsave(&css_set_lock, flags);
145 put_css_set_locked(cset);
146 spin_unlock_irqrestore(&css_set_lock, flags);
147}
148
149/*
150 * refcounted get/put for css_set objects
151 */
152static inline void get_css_set(struct css_set *cset)
153{
4b9502e6 154 refcount_inc(&cset->refcount);
dcfe149b
TH
155}
156
0a268dbd
TH
157bool cgroup_ssid_enabled(int ssid);
158bool cgroup_on_dfl(const struct cgroup *cgrp);
159
160struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root);
161struct cgroup *task_cgroup_from_root(struct task_struct *task,
162 struct cgroup_root *root);
163struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline);
164void cgroup_kn_unlock(struct kernfs_node *kn);
165int cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen,
166 struct cgroup_namespace *ns);
167
1592c9b2
TH
168void cgroup_free_root(struct cgroup_root *root);
169void init_cgroup_root(struct cgroup_root *root, struct cgroup_sb_opts *opts);
9732adc5 170int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask, int ref_flags);
0a268dbd 171int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
1592c9b2
TH
172struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
173 struct cgroup_root *root, unsigned long magic,
174 struct cgroup_namespace *ns);
0a268dbd
TH
175
176bool cgroup_may_migrate_to(struct cgroup *dst_cgrp);
e595cd70
TH
177void cgroup_migrate_finish(struct cgroup_mgctx *mgctx);
178void cgroup_migrate_add_src(struct css_set *src_cset, struct cgroup *dst_cgrp,
179 struct cgroup_mgctx *mgctx);
180int cgroup_migrate_prepare_dst(struct cgroup_mgctx *mgctx);
0a268dbd 181int cgroup_migrate(struct task_struct *leader, bool threadgroup,
bfc2cf6f 182 struct cgroup_mgctx *mgctx);
0a268dbd
TH
183
184int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
185 bool threadgroup);
186ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
187 size_t nbytes, loff_t off, bool threadgroup);
188ssize_t cgroup_procs_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
189 loff_t off);
190
191void cgroup_lock_and_drain_offline(struct cgroup *cgrp);
192
1592c9b2
TH
193int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode);
194int cgroup_rmdir(struct kernfs_node *kn);
195int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
196 struct kernfs_root *kf_root);
197
a28f8f5e
WL
198int cgroup_task_count(const struct cgroup *cgrp);
199
dcfe149b
TH
200/*
201 * namespace.c
202 */
203extern const struct proc_ns_operations cgroupns_operations;
204
0a268dbd
TH
205/*
206 * cgroup-v1.c
207 */
d62beb7f 208extern struct cftype cgroup1_base_files[];
0a268dbd 209extern const struct file_operations proc_cgroupstats_operations;
1592c9b2 210extern struct kernfs_syscall_ops cgroup1_kf_syscall_ops;
0a268dbd 211
d62beb7f
TH
212bool cgroup1_ssid_disabled(int ssid);
213void cgroup1_pidlist_destroy_all(struct cgroup *cgrp);
214void cgroup1_release_agent(struct work_struct *work);
215void cgroup1_check_for_release(struct cgroup *cgrp);
1592c9b2
TH
216struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags,
217 void *data, unsigned long magic,
218 struct cgroup_namespace *ns);
0a268dbd
TH
219
220#endif /* __CGROUP_INTERNAL_H */