]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
663996b3 MS |
2 | #pragma once |
3 | ||
e735f4d4 MP |
4 | #include <stdbool.h> |
5 | ||
f5e65279 MB |
6 | #include "cgroup-util.h" |
7 | #include "ip-address-access.h" | |
14228c0d | 8 | #include "list.h" |
e735f4d4 | 9 | #include "time-util.h" |
663996b3 | 10 | |
14228c0d MB |
11 | typedef struct CGroupContext CGroupContext; |
12 | typedef struct CGroupDeviceAllow CGroupDeviceAllow; | |
aa27b158 MP |
13 | typedef struct CGroupIODeviceWeight CGroupIODeviceWeight; |
14 | typedef struct CGroupIODeviceLimit CGroupIODeviceLimit; | |
6e866b33 | 15 | typedef struct CGroupIODeviceLatency CGroupIODeviceLatency; |
14228c0d MB |
16 | typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight; |
17 | typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth; | |
663996b3 | 18 | |
14228c0d | 19 | typedef enum CGroupDevicePolicy { |
663996b3 | 20 | |
14228c0d MB |
21 | /* When devices listed, will allow those, plus built-in ones, |
22 | if none are listed will allow everything. */ | |
23 | CGROUP_AUTO, | |
663996b3 | 24 | |
14228c0d MB |
25 | /* Everything forbidden, except built-in ones and listed ones. */ |
26 | CGROUP_CLOSED, | |
663996b3 | 27 | |
14228c0d MB |
28 | /* Everythings forbidden, except for the listed devices */ |
29 | CGROUP_STRICT, | |
663996b3 | 30 | |
14228c0d MB |
31 | _CGROUP_DEVICE_POLICY_MAX, |
32 | _CGROUP_DEVICE_POLICY_INVALID = -1 | |
33 | } CGroupDevicePolicy; | |
663996b3 | 34 | |
14228c0d MB |
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 | }; | |
663996b3 | 42 | |
aa27b158 MP |
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; | |
52 | uint64_t limits[_CGROUP_IO_LIMIT_TYPE_MAX]; | |
53 | }; | |
54 | ||
6e866b33 MB |
55 | struct CGroupIODeviceLatency { |
56 | LIST_FIELDS(CGroupIODeviceLatency, device_latencies); | |
57 | char *path; | |
58 | usec_t target_usec; | |
59 | }; | |
60 | ||
14228c0d MB |
61 | struct CGroupBlockIODeviceWeight { |
62 | LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights); | |
63 | char *path; | |
6300502b | 64 | uint64_t weight; |
663996b3 MS |
65 | }; |
66 | ||
14228c0d MB |
67 | struct CGroupBlockIODeviceBandwidth { |
68 | LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths); | |
69 | char *path; | |
aa27b158 MP |
70 | uint64_t rbps; |
71 | uint64_t wbps; | |
14228c0d | 72 | }; |
663996b3 | 73 | |
14228c0d MB |
74 | struct CGroupContext { |
75 | bool cpu_accounting; | |
aa27b158 | 76 | bool io_accounting; |
14228c0d MB |
77 | bool blockio_accounting; |
78 | bool memory_accounting; | |
6300502b | 79 | bool tasks_accounting; |
f5e65279 | 80 | bool ip_accounting; |
663996b3 | 81 | |
aa27b158 | 82 | /* For unified hierarchy */ |
8a584da2 MP |
83 | uint64_t cpu_weight; |
84 | uint64_t startup_cpu_weight; | |
85 | usec_t cpu_quota_per_sec_usec; | |
86 | ||
aa27b158 MP |
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); | |
6e866b33 | 91 | LIST_HEAD(CGroupIODeviceLatency, io_device_latencies); |
aa27b158 | 92 | |
6e866b33 | 93 | uint64_t memory_min; |
5a920b42 MP |
94 | uint64_t memory_low; |
95 | uint64_t memory_high; | |
96 | uint64_t memory_max; | |
8a584da2 | 97 | uint64_t memory_swap_max; |
5a920b42 | 98 | |
f5e65279 MB |
99 | LIST_HEAD(IPAddressAccessItem, ip_address_allow); |
100 | LIST_HEAD(IPAddressAccessItem, ip_address_deny); | |
101 | ||
aa27b158 | 102 | /* For legacy hierarchies */ |
6300502b MP |
103 | uint64_t cpu_shares; |
104 | uint64_t startup_cpu_shares; | |
663996b3 | 105 | |
6300502b MP |
106 | uint64_t blockio_weight; |
107 | uint64_t startup_blockio_weight; | |
14228c0d MB |
108 | LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights); |
109 | LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths); | |
663996b3 | 110 | |
14228c0d | 111 | uint64_t memory_limit; |
663996b3 | 112 | |
14228c0d MB |
113 | CGroupDevicePolicy device_policy; |
114 | LIST_HEAD(CGroupDeviceAllow, device_allow); | |
f47781d8 | 115 | |
aa27b158 | 116 | /* Common */ |
6300502b MP |
117 | uint64_t tasks_max; |
118 | ||
f47781d8 | 119 | bool delegate; |
52ad194e | 120 | CGroupMask delegate_controllers; |
6e866b33 MB |
121 | |
122 | CGroupMask disable_controllers; | |
14228c0d | 123 | }; |
663996b3 | 124 | |
f5e65279 MB |
125 | /* Used when querying IP accounting data */ |
126 | typedef enum CGroupIPAccountingMetric { | |
127 | CGROUP_IP_INGRESS_BYTES, | |
128 | CGROUP_IP_INGRESS_PACKETS, | |
129 | CGROUP_IP_EGRESS_BYTES, | |
130 | CGROUP_IP_EGRESS_PACKETS, | |
131 | _CGROUP_IP_ACCOUNTING_METRIC_MAX, | |
132 | _CGROUP_IP_ACCOUNTING_METRIC_INVALID = -1, | |
133 | } CGroupIPAccountingMetric; | |
134 | ||
b012e921 MB |
135 | typedef struct Unit Unit; |
136 | typedef struct Manager Manager; | |
663996b3 | 137 | |
14228c0d MB |
138 | void cgroup_context_init(CGroupContext *c); |
139 | void cgroup_context_done(CGroupContext *c); | |
140 | void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix); | |
60f067b4 | 141 | |
14228c0d | 142 | void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a); |
aa27b158 MP |
143 | void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w); |
144 | void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l); | |
6e866b33 | 145 | void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLatency *l); |
14228c0d MB |
146 | void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w); |
147 | void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b); | |
663996b3 | 148 | |
6e866b33 MB |
149 | int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode); |
150 | ||
d9dfd233 | 151 | CGroupMask unit_get_own_mask(Unit *u); |
52ad194e | 152 | CGroupMask unit_get_delegate_mask(Unit *u); |
d9dfd233 | 153 | CGroupMask unit_get_members_mask(Unit *u); |
52ad194e | 154 | CGroupMask unit_get_siblings_mask(Unit *u); |
d9dfd233 | 155 | CGroupMask unit_get_subtree_mask(Unit *u); |
6e866b33 MB |
156 | CGroupMask unit_get_disable_mask(Unit *u); |
157 | CGroupMask unit_get_ancestor_disable_mask(Unit *u); | |
d9dfd233 MP |
158 | |
159 | CGroupMask unit_get_target_mask(Unit *u); | |
160 | CGroupMask unit_get_enable_mask(Unit *u); | |
60f067b4 | 161 | |
6e866b33 | 162 | void unit_invalidate_cgroup_members_masks(Unit *u); |
f5e65279 | 163 | |
6e866b33 | 164 | void unit_add_to_cgroup_realize_queue(Unit *u); |
d9dfd233 | 165 | |
98393f85 | 166 | const char *unit_get_realized_cgroup_path(Unit *u, CGroupMask mask); |
6e866b33 | 167 | char *unit_default_cgroup_path(const Unit *u); |
d9dfd233 | 168 | int unit_set_cgroup_path(Unit *u, const char *path); |
52ad194e | 169 | int unit_pick_cgroup_path(Unit *u); |
d9dfd233 | 170 | |
14228c0d | 171 | int unit_realize_cgroup(Unit *u); |
d9dfd233 MP |
172 | void unit_release_cgroup(Unit *u); |
173 | void unit_prune_cgroup(Unit *u); | |
174 | int unit_watch_cgroup(Unit *u); | |
175 | ||
f5e65279 MB |
176 | void unit_add_to_cgroup_empty_queue(Unit *u); |
177 | ||
98393f85 | 178 | int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path); |
663996b3 | 179 | |
14228c0d MB |
180 | int manager_setup_cgroup(Manager *m); |
181 | void manager_shutdown_cgroup(Manager *m, bool delete); | |
663996b3 | 182 | |
f5e65279 | 183 | unsigned manager_dispatch_cgroup_realize_queue(Manager *m); |
663996b3 | 184 | |
14228c0d | 185 | Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup); |
d9dfd233 | 186 | Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid); |
14228c0d | 187 | Unit* manager_get_unit_by_pid(Manager *m, pid_t pid); |
663996b3 | 188 | |
d9dfd233 MP |
189 | int unit_search_main_pid(Unit *u, pid_t *ret); |
190 | int unit_watch_all_pids(Unit *u); | |
663996b3 | 191 | |
1d42b86d MB |
192 | int unit_synthesize_cgroup_empty_event(Unit *u); |
193 | ||
e3bff60a | 194 | int unit_get_memory_current(Unit *u, uint64_t *ret); |
6300502b | 195 | int unit_get_tasks_current(Unit *u, uint64_t *ret); |
e3bff60a | 196 | int unit_get_cpu_usage(Unit *u, nsec_t *ret); |
f5e65279 MB |
197 | int unit_get_ip_accounting(Unit *u, CGroupIPAccountingMetric metric, uint64_t *ret); |
198 | ||
199 | int unit_reset_cpu_accounting(Unit *u); | |
200 | int unit_reset_ip_accounting(Unit *u); | |
e3bff60a | 201 | |
f5e65279 MB |
202 | #define UNIT_CGROUP_BOOL(u, name) \ |
203 | ({ \ | |
204 | CGroupContext *cc = unit_get_cgroup_context(u); \ | |
205 | cc ? cc->name : false; \ | |
206 | }) | |
d9dfd233 | 207 | |
6e866b33 MB |
208 | bool manager_owns_host_root_cgroup(Manager *m); |
209 | bool unit_has_host_root_cgroup(Unit *u); | |
1d42b86d | 210 | |
d9dfd233 MP |
211 | int manager_notify_cgroup_empty(Manager *m, const char *group); |
212 | ||
6300502b | 213 | void unit_invalidate_cgroup(Unit *u, CGroupMask m); |
f5e65279 | 214 | void unit_invalidate_cgroup_bpf(Unit *u); |
6300502b MP |
215 | |
216 | void manager_invalidate_startup_units(Manager *m); | |
217 | ||
14228c0d MB |
218 | const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_; |
219 | CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_; | |
98393f85 MB |
220 | |
221 | bool unit_cgroup_delegate(Unit *u); |