]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
8e274523 | 3 | |
c1ff5570 TA |
4 | #include <stdbool.h> |
5 | ||
6a48d82f | 6 | #include "cgroup-util.h" |
047f5d63 | 7 | #include "cpu-set-util.h" |
6a48d82f | 8 | #include "ip-address-access.h" |
4ad49000 | 9 | #include "list.h" |
c1ff5570 | 10 | #include "time-util.h" |
8e274523 | 11 | |
4ad49000 LP |
12 | typedef struct CGroupContext CGroupContext; |
13 | typedef struct CGroupDeviceAllow CGroupDeviceAllow; | |
13c31542 TH |
14 | typedef struct CGroupIODeviceWeight CGroupIODeviceWeight; |
15 | typedef struct CGroupIODeviceLimit CGroupIODeviceLimit; | |
6ae4283c | 16 | typedef struct CGroupIODeviceLatency CGroupIODeviceLatency; |
4ad49000 LP |
17 | typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight; |
18 | typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth; | |
8e274523 | 19 | |
4ad49000 | 20 | typedef enum CGroupDevicePolicy { |
8e274523 | 21 | |
4ad49000 LP |
22 | /* When devices listed, will allow those, plus built-in ones, |
23 | if none are listed will allow everything. */ | |
24 | CGROUP_AUTO, | |
8e274523 | 25 | |
4ad49000 LP |
26 | /* Everything forbidden, except built-in ones and listed ones. */ |
27 | CGROUP_CLOSED, | |
9d58f1db | 28 | |
5238e957 | 29 | /* Everything forbidden, except for the listed devices */ |
4ad49000 | 30 | CGROUP_STRICT, |
9d58f1db | 31 | |
4ad49000 LP |
32 | _CGROUP_DEVICE_POLICY_MAX, |
33 | _CGROUP_DEVICE_POLICY_INVALID = -1 | |
34 | } CGroupDevicePolicy; | |
8e274523 | 35 | |
4ad49000 LP |
36 | struct CGroupDeviceAllow { |
37 | LIST_FIELDS(CGroupDeviceAllow, device_allow); | |
38 | char *path; | |
39 | bool r:1; | |
40 | bool w:1; | |
41 | bool m:1; | |
42 | }; | |
8c6db833 | 43 | |
13c31542 TH |
44 | struct CGroupIODeviceWeight { |
45 | LIST_FIELDS(CGroupIODeviceWeight, device_weights); | |
46 | char *path; | |
47 | uint64_t weight; | |
48 | }; | |
49 | ||
50 | struct CGroupIODeviceLimit { | |
51 | LIST_FIELDS(CGroupIODeviceLimit, device_limits); | |
52 | char *path; | |
9be57249 | 53 | uint64_t limits[_CGROUP_IO_LIMIT_TYPE_MAX]; |
13c31542 TH |
54 | }; |
55 | ||
6ae4283c TH |
56 | struct CGroupIODeviceLatency { |
57 | LIST_FIELDS(CGroupIODeviceLatency, device_latencies); | |
58 | char *path; | |
59 | usec_t target_usec; | |
60 | }; | |
61 | ||
4ad49000 LP |
62 | struct CGroupBlockIODeviceWeight { |
63 | LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights); | |
64 | char *path; | |
d53d9474 | 65 | uint64_t weight; |
8e274523 LP |
66 | }; |
67 | ||
4ad49000 LP |
68 | struct CGroupBlockIODeviceBandwidth { |
69 | LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths); | |
70 | char *path; | |
979d0311 TH |
71 | uint64_t rbps; |
72 | uint64_t wbps; | |
4ad49000 | 73 | }; |
8e274523 | 74 | |
4ad49000 LP |
75 | struct CGroupContext { |
76 | bool cpu_accounting; | |
13c31542 | 77 | bool io_accounting; |
4ad49000 LP |
78 | bool blockio_accounting; |
79 | bool memory_accounting; | |
03a7b521 | 80 | bool tasks_accounting; |
6a48d82f | 81 | bool ip_accounting; |
8e274523 | 82 | |
afcfaa69 LP |
83 | /* Configures the memory.oom.group attribute (on unified) */ |
84 | bool memory_oom_group; | |
85 | ||
0a6991e0 LP |
86 | bool delegate; |
87 | CGroupMask delegate_controllers; | |
88 | CGroupMask disable_controllers; | |
89 | ||
13c31542 | 90 | /* For unified hierarchy */ |
66ebf6c0 TH |
91 | uint64_t cpu_weight; |
92 | uint64_t startup_cpu_weight; | |
93 | usec_t cpu_quota_per_sec_usec; | |
10f28641 | 94 | usec_t cpu_quota_period_usec; |
66ebf6c0 | 95 | |
047f5d63 PH |
96 | CPUSet cpuset_cpus; |
97 | CPUSet cpuset_mems; | |
98 | ||
13c31542 TH |
99 | uint64_t io_weight; |
100 | uint64_t startup_io_weight; | |
101 | LIST_HEAD(CGroupIODeviceWeight, io_device_weights); | |
102 | LIST_HEAD(CGroupIODeviceLimit, io_device_limits); | |
6ae4283c | 103 | LIST_HEAD(CGroupIODeviceLatency, io_device_latencies); |
13c31542 | 104 | |
7ad5439e | 105 | uint64_t default_memory_min; |
c52db42b | 106 | uint64_t default_memory_low; |
48422635 | 107 | uint64_t memory_min; |
da4d897e TH |
108 | uint64_t memory_low; |
109 | uint64_t memory_high; | |
110 | uint64_t memory_max; | |
96e131ea | 111 | uint64_t memory_swap_max; |
da4d897e | 112 | |
7ad5439e | 113 | bool default_memory_min_set; |
c52db42b | 114 | bool default_memory_low_set; |
7ad5439e | 115 | bool memory_min_set; |
c52db42b CD |
116 | bool memory_low_set; |
117 | ||
6a48d82f DM |
118 | LIST_HEAD(IPAddressAccessItem, ip_address_allow); |
119 | LIST_HEAD(IPAddressAccessItem, ip_address_deny); | |
120 | ||
fab34748 KL |
121 | char **ip_filters_ingress; |
122 | char **ip_filters_egress; | |
123 | ||
13c31542 | 124 | /* For legacy hierarchies */ |
d53d9474 LP |
125 | uint64_t cpu_shares; |
126 | uint64_t startup_cpu_shares; | |
8e274523 | 127 | |
d53d9474 LP |
128 | uint64_t blockio_weight; |
129 | uint64_t startup_blockio_weight; | |
4ad49000 LP |
130 | LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights); |
131 | LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths); | |
246aa6dd | 132 | |
4ad49000 | 133 | uint64_t memory_limit; |
64747e2d | 134 | |
4ad49000 LP |
135 | CGroupDevicePolicy device_policy; |
136 | LIST_HEAD(CGroupDeviceAllow, device_allow); | |
a931ad47 | 137 | |
13c31542 | 138 | /* Common */ |
03a7b521 | 139 | uint64_t tasks_max; |
4ad49000 | 140 | }; |
64747e2d | 141 | |
906c06f6 DM |
142 | /* Used when querying IP accounting data */ |
143 | typedef enum CGroupIPAccountingMetric { | |
144 | CGROUP_IP_INGRESS_BYTES, | |
145 | CGROUP_IP_INGRESS_PACKETS, | |
146 | CGROUP_IP_EGRESS_BYTES, | |
147 | CGROUP_IP_EGRESS_PACKETS, | |
148 | _CGROUP_IP_ACCOUNTING_METRIC_MAX, | |
149 | _CGROUP_IP_ACCOUNTING_METRIC_INVALID = -1, | |
150 | } CGroupIPAccountingMetric; | |
151 | ||
fbe14fc9 LP |
152 | /* Used when querying IO accounting data */ |
153 | typedef enum CGroupIOAccountingMetric { | |
154 | CGROUP_IO_READ_BYTES, | |
155 | CGROUP_IO_WRITE_BYTES, | |
156 | CGROUP_IO_READ_OPERATIONS, | |
157 | CGROUP_IO_WRITE_OPERATIONS, | |
158 | _CGROUP_IO_ACCOUNTING_METRIC_MAX, | |
159 | _CGROUP_IO_ACCOUNTING_METRIC_INVALID = -1, | |
160 | } CGroupIOAccountingMetric; | |
161 | ||
90a8f0b9 FS |
162 | typedef struct Unit Unit; |
163 | typedef struct Manager Manager; | |
8e274523 | 164 | |
10f28641 FB |
165 | usec_t cgroup_cpu_adjust_period(usec_t period, usec_t quota, usec_t resolution, usec_t max_period); |
166 | ||
4ad49000 LP |
167 | void cgroup_context_init(CGroupContext *c); |
168 | void cgroup_context_done(CGroupContext *c); | |
bc0623df | 169 | void cgroup_context_dump(Unit *u, FILE* f, const char *prefix); |
bc432dc7 | 170 | |
4ad49000 | 171 | void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a); |
13c31542 TH |
172 | void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w); |
173 | void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l); | |
6ae4283c | 174 | void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLatency *l); |
4ad49000 LP |
175 | void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w); |
176 | void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b); | |
8e274523 | 177 | |
fd870bac YW |
178 | int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode); |
179 | ||
efdb0237 | 180 | CGroupMask unit_get_own_mask(Unit *u); |
02638280 | 181 | CGroupMask unit_get_delegate_mask(Unit *u); |
efdb0237 | 182 | CGroupMask unit_get_members_mask(Unit *u); |
02638280 | 183 | CGroupMask unit_get_siblings_mask(Unit *u); |
efdb0237 | 184 | CGroupMask unit_get_subtree_mask(Unit *u); |
c72703e2 CD |
185 | CGroupMask unit_get_disable_mask(Unit *u); |
186 | CGroupMask unit_get_ancestor_disable_mask(Unit *u); | |
187 | ||
efdb0237 LP |
188 | CGroupMask unit_get_target_mask(Unit *u); |
189 | CGroupMask unit_get_enable_mask(Unit *u); | |
bc432dc7 | 190 | |
5af88058 | 191 | void unit_invalidate_cgroup_members_masks(Unit *u); |
efdb0237 | 192 | |
27adcc97 LP |
193 | void unit_add_to_cgroup_realize_queue(Unit *u); |
194 | ||
6592b975 | 195 | const char *unit_get_realized_cgroup_path(Unit *u, CGroupMask mask); |
303ee601 | 196 | char *unit_default_cgroup_path(const Unit *u); |
efdb0237 | 197 | int unit_set_cgroup_path(Unit *u, const char *path); |
a4634b21 | 198 | int unit_pick_cgroup_path(Unit *u); |
efdb0237 | 199 | |
0a1eb06d | 200 | int unit_realize_cgroup(Unit *u); |
efdb0237 LP |
201 | void unit_release_cgroup(Unit *u); |
202 | void unit_prune_cgroup(Unit *u); | |
203 | int unit_watch_cgroup(Unit *u); | |
afcfaa69 | 204 | int unit_watch_cgroup_memory(Unit *u); |
efdb0237 | 205 | |
09e24654 | 206 | void unit_add_to_cgroup_empty_queue(Unit *u); |
2ba6ae6b | 207 | int unit_check_oom(Unit *u); |
09e24654 | 208 | |
6592b975 | 209 | int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path); |
8e274523 | 210 | |
4ad49000 LP |
211 | int manager_setup_cgroup(Manager *m); |
212 | void manager_shutdown_cgroup(Manager *m, bool delete); | |
6dde1f33 | 213 | |
91a6073e | 214 | unsigned manager_dispatch_cgroup_realize_queue(Manager *m); |
4fbf50b3 | 215 | |
4ad49000 | 216 | Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup); |
b3ac818b | 217 | Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid); |
4ad49000 | 218 | Unit* manager_get_unit_by_pid(Manager *m, pid_t pid); |
8e274523 | 219 | |
7ad5439e | 220 | uint64_t unit_get_ancestor_memory_min(Unit *u); |
c52db42b CD |
221 | uint64_t unit_get_ancestor_memory_low(Unit *u); |
222 | ||
efdb0237 LP |
223 | int unit_search_main_pid(Unit *u, pid_t *ret); |
224 | int unit_watch_all_pids(Unit *u); | |
8e274523 | 225 | |
11aef522 LP |
226 | int unit_synthesize_cgroup_empty_event(Unit *u); |
227 | ||
5ad096b3 | 228 | int unit_get_memory_current(Unit *u, uint64_t *ret); |
03a7b521 | 229 | int unit_get_tasks_current(Unit *u, uint64_t *ret); |
5ad096b3 | 230 | int unit_get_cpu_usage(Unit *u, nsec_t *ret); |
fbe14fc9 | 231 | int unit_get_io_accounting(Unit *u, CGroupIOAccountingMetric metric, bool allow_cache, uint64_t *ret); |
906c06f6 DM |
232 | int unit_get_ip_accounting(Unit *u, CGroupIPAccountingMetric metric, uint64_t *ret); |
233 | ||
234 | int unit_reset_cpu_accounting(Unit *u); | |
235 | int unit_reset_ip_accounting(Unit *u); | |
fbe14fc9 | 236 | int unit_reset_io_accounting(Unit *u); |
9b2559a1 | 237 | int unit_reset_accounting(Unit *u); |
5ad096b3 | 238 | |
2e4025c0 ZJS |
239 | #define UNIT_CGROUP_BOOL(u, name) \ |
240 | ({ \ | |
241 | CGroupContext *cc = unit_get_cgroup_context(u); \ | |
242 | cc ? cc->name : false; \ | |
243 | }) | |
e9db43d5 | 244 | |
611c4f8a LP |
245 | bool manager_owns_host_root_cgroup(Manager *m); |
246 | bool unit_has_host_root_cgroup(Unit *u); | |
f3725e64 | 247 | |
efdb0237 LP |
248 | int manager_notify_cgroup_empty(Manager *m, const char *group); |
249 | ||
e7ab4d1a | 250 | void unit_invalidate_cgroup(Unit *u, CGroupMask m); |
906c06f6 | 251 | void unit_invalidate_cgroup_bpf(Unit *u); |
e7ab4d1a LP |
252 | |
253 | void manager_invalidate_startup_units(Manager *m); | |
254 | ||
4ad49000 LP |
255 | const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_; |
256 | CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_; | |
1d9cc876 LP |
257 | |
258 | bool unit_cgroup_delegate(Unit *u); | |
da8e1782 MO |
259 | |
260 | int compare_job_priority(const void *a, const void *b); | |
047f5d63 PH |
261 | |
262 | int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name); |