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