]>
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; | |
86 | ||
13c31542 TH |
87 | uint64_t io_weight; |
88 | uint64_t startup_io_weight; | |
89 | LIST_HEAD(CGroupIODeviceWeight, io_device_weights); | |
90 | LIST_HEAD(CGroupIODeviceLimit, io_device_limits); | |
6ae4283c | 91 | LIST_HEAD(CGroupIODeviceLatency, io_device_latencies); |
13c31542 | 92 | |
48422635 | 93 | uint64_t memory_min; |
da4d897e TH |
94 | uint64_t memory_low; |
95 | uint64_t memory_high; | |
96 | uint64_t memory_max; | |
96e131ea | 97 | uint64_t memory_swap_max; |
da4d897e | 98 | |
6a48d82f DM |
99 | LIST_HEAD(IPAddressAccessItem, ip_address_allow); |
100 | LIST_HEAD(IPAddressAccessItem, ip_address_deny); | |
101 | ||
13c31542 | 102 | /* For legacy hierarchies */ |
d53d9474 LP |
103 | uint64_t cpu_shares; |
104 | uint64_t startup_cpu_shares; | |
8e274523 | 105 | |
d53d9474 LP |
106 | uint64_t blockio_weight; |
107 | uint64_t startup_blockio_weight; | |
4ad49000 LP |
108 | LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights); |
109 | LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths); | |
246aa6dd | 110 | |
4ad49000 | 111 | uint64_t memory_limit; |
64747e2d | 112 | |
4ad49000 LP |
113 | CGroupDevicePolicy device_policy; |
114 | LIST_HEAD(CGroupDeviceAllow, device_allow); | |
a931ad47 | 115 | |
13c31542 | 116 | /* Common */ |
03a7b521 | 117 | uint64_t tasks_max; |
d53d9474 LP |
118 | |
119 | bool delegate; | |
02638280 | 120 | CGroupMask delegate_controllers; |
4ad49000 | 121 | }; |
64747e2d | 122 | |
906c06f6 DM |
123 | /* Used when querying IP accounting data */ |
124 | typedef enum CGroupIPAccountingMetric { | |
125 | CGROUP_IP_INGRESS_BYTES, | |
126 | CGROUP_IP_INGRESS_PACKETS, | |
127 | CGROUP_IP_EGRESS_BYTES, | |
128 | CGROUP_IP_EGRESS_PACKETS, | |
129 | _CGROUP_IP_ACCOUNTING_METRIC_MAX, | |
130 | _CGROUP_IP_ACCOUNTING_METRIC_INVALID = -1, | |
131 | } CGroupIPAccountingMetric; | |
132 | ||
90a8f0b9 FS |
133 | typedef struct Unit Unit; |
134 | typedef struct Manager Manager; | |
8e274523 | 135 | |
4ad49000 LP |
136 | void cgroup_context_init(CGroupContext *c); |
137 | void cgroup_context_done(CGroupContext *c); | |
138 | void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix); | |
bc432dc7 | 139 | |
4ad49000 | 140 | void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a); |
13c31542 TH |
141 | void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w); |
142 | void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l); | |
6ae4283c | 143 | void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLatency *l); |
4ad49000 LP |
144 | void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w); |
145 | void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b); | |
8e274523 | 146 | |
fd870bac YW |
147 | int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode); |
148 | ||
efdb0237 | 149 | CGroupMask unit_get_own_mask(Unit *u); |
02638280 | 150 | CGroupMask unit_get_delegate_mask(Unit *u); |
efdb0237 | 151 | CGroupMask unit_get_members_mask(Unit *u); |
02638280 | 152 | CGroupMask unit_get_siblings_mask(Unit *u); |
efdb0237 LP |
153 | CGroupMask unit_get_subtree_mask(Unit *u); |
154 | ||
155 | CGroupMask unit_get_target_mask(Unit *u); | |
156 | CGroupMask unit_get_enable_mask(Unit *u); | |
bc432dc7 LP |
157 | |
158 | void unit_update_cgroup_members_masks(Unit *u); | |
efdb0237 | 159 | |
6592b975 | 160 | const char *unit_get_realized_cgroup_path(Unit *u, CGroupMask mask); |
efdb0237 LP |
161 | char *unit_default_cgroup_path(Unit *u); |
162 | int unit_set_cgroup_path(Unit *u, const char *path); | |
a4634b21 | 163 | int unit_pick_cgroup_path(Unit *u); |
efdb0237 | 164 | |
0a1eb06d | 165 | int unit_realize_cgroup(Unit *u); |
efdb0237 LP |
166 | void unit_release_cgroup(Unit *u); |
167 | void unit_prune_cgroup(Unit *u); | |
168 | int unit_watch_cgroup(Unit *u); | |
169 | ||
09e24654 LP |
170 | void unit_add_to_cgroup_empty_queue(Unit *u); |
171 | ||
6592b975 | 172 | int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path); |
8e274523 | 173 | |
4ad49000 LP |
174 | int manager_setup_cgroup(Manager *m); |
175 | void manager_shutdown_cgroup(Manager *m, bool delete); | |
6dde1f33 | 176 | |
91a6073e | 177 | unsigned manager_dispatch_cgroup_realize_queue(Manager *m); |
4fbf50b3 | 178 | |
4ad49000 | 179 | Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup); |
b3ac818b | 180 | Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid); |
4ad49000 | 181 | Unit* manager_get_unit_by_pid(Manager *m, pid_t pid); |
8e274523 | 182 | |
efdb0237 LP |
183 | int unit_search_main_pid(Unit *u, pid_t *ret); |
184 | int unit_watch_all_pids(Unit *u); | |
8e274523 | 185 | |
11aef522 LP |
186 | int unit_synthesize_cgroup_empty_event(Unit *u); |
187 | ||
5ad096b3 | 188 | int unit_get_memory_current(Unit *u, uint64_t *ret); |
03a7b521 | 189 | int unit_get_tasks_current(Unit *u, uint64_t *ret); |
5ad096b3 | 190 | int unit_get_cpu_usage(Unit *u, nsec_t *ret); |
906c06f6 DM |
191 | int unit_get_ip_accounting(Unit *u, CGroupIPAccountingMetric metric, uint64_t *ret); |
192 | ||
193 | int unit_reset_cpu_accounting(Unit *u); | |
194 | int unit_reset_ip_accounting(Unit *u); | |
5ad096b3 | 195 | |
2e4025c0 ZJS |
196 | #define UNIT_CGROUP_BOOL(u, name) \ |
197 | ({ \ | |
198 | CGroupContext *cc = unit_get_cgroup_context(u); \ | |
199 | cc ? cc->name : false; \ | |
200 | }) | |
e9db43d5 | 201 | |
611c4f8a LP |
202 | bool manager_owns_host_root_cgroup(Manager *m); |
203 | bool unit_has_host_root_cgroup(Unit *u); | |
f3725e64 | 204 | |
efdb0237 LP |
205 | int manager_notify_cgroup_empty(Manager *m, const char *group); |
206 | ||
e7ab4d1a | 207 | void unit_invalidate_cgroup(Unit *u, CGroupMask m); |
906c06f6 | 208 | void unit_invalidate_cgroup_bpf(Unit *u); |
e7ab4d1a LP |
209 | |
210 | void manager_invalidate_startup_units(Manager *m); | |
211 | ||
4ad49000 LP |
212 | const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_; |
213 | CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_; | |
1d9cc876 LP |
214 | |
215 | bool unit_cgroup_delegate(Unit *u); |