Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 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> |
| 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 | */ |
| 17 | struct 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 Heo | 1592c9b | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 29 | struct 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 Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 39 | extern struct mutex cgroup_mutex; |
| 40 | extern spinlock_t css_set_lock; |
| 41 | extern struct cgroup_subsys *cgroup_subsys[]; |
| 42 | extern struct list_head cgroup_roots; |
| 43 | extern 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 | |
| 58 | static inline bool cgroup_is_dead(const struct cgroup *cgrp) |
| 59 | { |
| 60 | return !(cgrp->self.flags & CSS_ONLINE); |
| 61 | } |
| 62 | |
| 63 | static inline bool notify_on_release(const struct cgroup *cgrp) |
| 64 | { |
| 65 | return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); |
| 66 | } |
| 67 | |
Tejun Heo | dcfe149 | 2016-12-27 14:49:09 -0500 | [diff] [blame^] | 68 | void put_css_set_locked(struct css_set *cset); |
| 69 | |
| 70 | static 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 | */ |
| 90 | static inline void get_css_set(struct css_set *cset) |
| 91 | { |
| 92 | atomic_inc(&cset->refcount); |
| 93 | } |
| 94 | |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 95 | bool cgroup_ssid_enabled(int ssid); |
| 96 | bool cgroup_on_dfl(const struct cgroup *cgrp); |
| 97 | |
| 98 | struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root); |
| 99 | struct cgroup *task_cgroup_from_root(struct task_struct *task, |
| 100 | struct cgroup_root *root); |
| 101 | struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline); |
| 102 | void cgroup_kn_unlock(struct kernfs_node *kn); |
| 103 | int cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen, |
| 104 | struct cgroup_namespace *ns); |
| 105 | |
Tejun Heo | 1592c9b | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 106 | void cgroup_free_root(struct cgroup_root *root); |
| 107 | void init_cgroup_root(struct cgroup_root *root, struct cgroup_sb_opts *opts); |
| 108 | int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask); |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 109 | int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask); |
Tejun Heo | 1592c9b | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 110 | struct 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 Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 113 | |
| 114 | bool cgroup_may_migrate_to(struct cgroup *dst_cgrp); |
| 115 | void cgroup_migrate_finish(struct list_head *preloaded_csets); |
| 116 | void cgroup_migrate_add_src(struct css_set *src_cset, |
| 117 | struct cgroup *dst_cgrp, |
| 118 | struct list_head *preloaded_csets); |
| 119 | int cgroup_migrate_prepare_dst(struct list_head *preloaded_csets); |
| 120 | int cgroup_migrate(struct task_struct *leader, bool threadgroup, |
| 121 | struct cgroup_root *root); |
| 122 | |
| 123 | int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader, |
| 124 | bool threadgroup); |
| 125 | ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf, |
| 126 | size_t nbytes, loff_t off, bool threadgroup); |
| 127 | ssize_t cgroup_procs_write(struct kernfs_open_file *of, char *buf, size_t nbytes, |
| 128 | loff_t off); |
| 129 | |
| 130 | void cgroup_lock_and_drain_offline(struct cgroup *cgrp); |
| 131 | |
Tejun Heo | 1592c9b | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 132 | int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode); |
| 133 | int cgroup_rmdir(struct kernfs_node *kn); |
| 134 | int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node, |
| 135 | struct kernfs_root *kf_root); |
| 136 | |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 137 | /* |
Tejun Heo | dcfe149 | 2016-12-27 14:49:09 -0500 | [diff] [blame^] | 138 | * namespace.c |
| 139 | */ |
| 140 | extern const struct proc_ns_operations cgroupns_operations; |
| 141 | |
| 142 | /* |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 143 | * cgroup-v1.c |
| 144 | */ |
Tejun Heo | d62beb7 | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 145 | extern struct cftype cgroup1_base_files[]; |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 146 | extern const struct file_operations proc_cgroupstats_operations; |
Tejun Heo | 1592c9b | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 147 | extern struct kernfs_syscall_ops cgroup1_kf_syscall_ops; |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 148 | |
Tejun Heo | d62beb7 | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 149 | bool cgroup1_ssid_disabled(int ssid); |
| 150 | void cgroup1_pidlist_destroy_all(struct cgroup *cgrp); |
| 151 | void cgroup1_release_agent(struct work_struct *work); |
| 152 | void cgroup1_check_for_release(struct cgroup *cgrp); |
Tejun Heo | 1592c9b | 2016-12-27 14:49:08 -0500 | [diff] [blame] | 153 | struct dentry *cgroup1_mount(struct file_system_type *fs_type, int flags, |
| 154 | void *data, unsigned long magic, |
| 155 | struct cgroup_namespace *ns); |
Tejun Heo | 0a268db | 2016-12-27 14:49:06 -0500 | [diff] [blame] | 156 | |
| 157 | #endif /* __CGROUP_INTERNAL_H */ |