blob: 589b0e7013ec829056353f92b481be9830955b58 [file] [log] [blame]
Tejun Heo0a268db2016-12-27 14:49:06 -05001#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>
8
9/*
10 * A cgroup can be associated with multiple css_sets as different tasks may
11 * belong to different cgroups on different hierarchies. In the other
12 * direction, a css_set is naturally associated with multiple cgroups.
13 * This M:N relationship is represented by the following link structure
14 * which exists for each association and allows traversing the associations
15 * from both sides.
16 */
17struct cgrp_cset_link {
18 /* the cgroup and css_set this link associates */
19 struct cgroup *cgrp;
20 struct css_set *cset;
21
22 /* list of cgrp_cset_links anchored at cgrp->cset_links */
23 struct list_head cset_link;
24
25 /* list of cgrp_cset_links anchored at css_set->cgrp_links */
26 struct list_head cgrp_link;
27};
28
Tejun Heo1592c9b2016-12-27 14:49:08 -050029struct cgroup_sb_opts {
30 u16 subsys_mask;
31 unsigned int flags;
32 char *release_agent;
33 bool cpuset_clone_children;
34 char *name;
35 /* User explicitly requested empty subsystem */
36 bool none;
37};
38
Tejun Heo0a268db2016-12-27 14:49:06 -050039extern struct mutex cgroup_mutex;
40extern spinlock_t css_set_lock;
41extern struct cgroup_subsys *cgroup_subsys[];
42extern struct list_head cgroup_roots;
43extern struct file_system_type cgroup_fs_type;
44
45/* iterate across the hierarchies */
46#define for_each_root(root) \
47 list_for_each_entry((root), &cgroup_roots, root_list)
48
49/**
50 * for_each_subsys - iterate all enabled cgroup subsystems
51 * @ss: the iteration cursor
52 * @ssid: the index of @ss, CGROUP_SUBSYS_COUNT after reaching the end
53 */
54#define for_each_subsys(ss, ssid) \
55 for ((ssid) = 0; (ssid) < CGROUP_SUBSYS_COUNT && \
56 (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
57
58static inline bool cgroup_is_dead(const struct cgroup *cgrp)
59{
60 return !(cgrp->self.flags & CSS_ONLINE);
61}
62
63static inline bool notify_on_release(const struct cgroup *cgrp)
64{
65 return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
66}
67
Tejun Heodcfe1492016-12-27 14:49:09 -050068void put_css_set_locked(struct css_set *cset);
69
70static inline void put_css_set(struct css_set *cset)
71{
72 unsigned long flags;
73
74 /*
75 * Ensure that the refcount doesn't hit zero while any readers
76 * can see it. Similar to atomic_dec_and_lock(), but for an
77 * rwlock
78 */
79 if (atomic_add_unless(&cset->refcount, -1, 1))
80 return;
81
82 spin_lock_irqsave(&css_set_lock, flags);
83 put_css_set_locked(cset);
84 spin_unlock_irqrestore(&css_set_lock, flags);
85}
86
87/*
88 * refcounted get/put for css_set objects
89 */
90static inline void get_css_set(struct css_set *cset)
91{
92 atomic_inc(&cset->refcount);
93}
94
Tejun Heo0a268db2016-12-27 14:49:06 -050095bool cgroup_ssid_enabled(int ssid);
96bool cgroup_on_dfl(const struct cgroup *cgrp);
97
98struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root);
99struct cgroup *task_cgroup_from_root(struct task_struct *task,
100 struct cgroup_root *root);
101struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline);
102void cgroup_kn_unlock(struct kernfs_node *kn);
103int cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen,
104 struct cgroup_namespace *ns);
105
Tejun Heo1592c9b2016-12-27 14:49:08 -0500106void cgroup_free_root(struct cgroup_root *root);
107void init_cgroup_root(struct cgroup_root *root, struct cgroup_sb_opts *opts);
108int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask);
Tejun Heo0a268db2016-12-27 14:49:06 -0500109int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
Tejun Heo1592c9b2016-12-27 14:49:08 -0500110struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
111 struct cgroup_root *root, unsigned long magic,
112 struct cgroup_namespace *ns);
Tejun Heo0a268db2016-12-27 14:49:06 -0500113
114bool cgroup_may_migrate_to(struct cgroup *dst_cgrp);
115void cgroup_migrate_finish(struct list_head *preloaded_csets);
116void cgroup_migrate_add_src(struct css_set *src_cset,
117 struct cgroup *dst_cgrp,
118 struct list_head *preloaded_csets);
119int cgroup_migrate_prepare_dst(struct list_head *preloaded_csets);
120int cgroup_migrate(struct task_struct *leader, bool threadgroup,
121 struct cgroup_root *root);
122
123int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
124 bool threadgroup);
125ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
126 size_t nbytes, loff_t off, bool threadgroup);
127ssize_t cgroup_procs_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
128 loff_t off);
129
130void cgroup_lock_and_drain_offline(struct cgroup *cgrp);
131
Tejun Heo1592c9b2016-12-27 14:49:08 -0500132int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode);
133int cgroup_rmdir(struct kernfs_node *kn);
134int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
135 struct kernfs_root *kf_root);
136
Tejun Heo0a268db2016-12-27 14:49:06 -0500137/*
Tejun Heodcfe1492016-12-27 14:49:09 -0500138 * namespace.c
139 */
140extern const struct proc_ns_operations cgroupns_operations;
141
142/*
Tejun Heo0a268db2016-12-27 14:49:06 -0500143 * cgroup-v1.c
144 */
Tejun Heod62beb72016-12-27 14:49:08 -0500145extern struct cftype cgroup1_base_files[];
Tejun Heo0a268db2016-12-27 14:49:06 -0500146extern const struct file_operations proc_cgroupstats_operations;
Tejun Heo1592c9b2016-12-27 14:49:08 -0500147extern struct kernfs_syscall_ops cgroup1_kf_syscall_ops;
Tejun Heo0a268db2016-12-27 14:49:06 -0500148
Tejun Heod62beb72016-12-27 14:49:08 -0500149bool cgroup1_ssid_disabled(int ssid);
150void cgroup1_pidlist_destroy_all(struct cgroup *cgrp);
151void cgroup1_release_agent(struct work_struct *work);
152void cgroup1_check_for_release(struct cgroup *cgrp);
Tejun Heo1592c9b2016-12-27 14:49:08 -0500153struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags,
154 void *data, unsigned long magic,
155 struct cgroup_namespace *ns);
Tejun Heo0a268db2016-12-27 14:49:06 -0500156
157#endif /* __CGROUP_INTERNAL_H */