]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/cgroup.h
cgroup: add fields to accommodate eBPF related details
[thirdparty/systemd.git] / src / core / cgroup.h
CommitLineData
c2f1db8f 1#pragma once
8e274523
LP
2
3/***
4 This file is part of systemd.
5
4ad49000 6 Copyright 2013 Lennart Poettering
8e274523
LP
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
8e274523
LP
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
8e274523 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
8e274523
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
c1ff5570
TA
22#include <stdbool.h>
23
6a48d82f
DM
24#include "cgroup-util.h"
25#include "ip-address-access.h"
4ad49000 26#include "list.h"
c1ff5570 27#include "time-util.h"
8e274523 28
4ad49000
LP
29typedef struct CGroupContext CGroupContext;
30typedef struct CGroupDeviceAllow CGroupDeviceAllow;
13c31542
TH
31typedef struct CGroupIODeviceWeight CGroupIODeviceWeight;
32typedef struct CGroupIODeviceLimit CGroupIODeviceLimit;
4ad49000
LP
33typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
34typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
8e274523 35
4ad49000 36typedef enum CGroupDevicePolicy {
8e274523 37
4ad49000
LP
38 /* When devices listed, will allow those, plus built-in ones,
39 if none are listed will allow everything. */
40 CGROUP_AUTO,
8e274523 41
4ad49000
LP
42 /* Everything forbidden, except built-in ones and listed ones. */
43 CGROUP_CLOSED,
9d58f1db 44
4ad49000
LP
45 /* Everythings forbidden, except for the listed devices */
46 CGROUP_STRICT,
9d58f1db 47
4ad49000
LP
48 _CGROUP_DEVICE_POLICY_MAX,
49 _CGROUP_DEVICE_POLICY_INVALID = -1
50} CGroupDevicePolicy;
8e274523 51
4ad49000
LP
52struct CGroupDeviceAllow {
53 LIST_FIELDS(CGroupDeviceAllow, device_allow);
54 char *path;
55 bool r:1;
56 bool w:1;
57 bool m:1;
58};
8c6db833 59
13c31542
TH
60struct CGroupIODeviceWeight {
61 LIST_FIELDS(CGroupIODeviceWeight, device_weights);
62 char *path;
63 uint64_t weight;
64};
65
66struct CGroupIODeviceLimit {
67 LIST_FIELDS(CGroupIODeviceLimit, device_limits);
68 char *path;
9be57249 69 uint64_t limits[_CGROUP_IO_LIMIT_TYPE_MAX];
13c31542
TH
70};
71
4ad49000
LP
72struct CGroupBlockIODeviceWeight {
73 LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
74 char *path;
d53d9474 75 uint64_t weight;
8e274523
LP
76};
77
4ad49000
LP
78struct CGroupBlockIODeviceBandwidth {
79 LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
80 char *path;
979d0311
TH
81 uint64_t rbps;
82 uint64_t wbps;
4ad49000 83};
8e274523 84
4ad49000
LP
85struct CGroupContext {
86 bool cpu_accounting;
13c31542 87 bool io_accounting;
4ad49000
LP
88 bool blockio_accounting;
89 bool memory_accounting;
03a7b521 90 bool tasks_accounting;
6a48d82f 91 bool ip_accounting;
8e274523 92
13c31542 93 /* For unified hierarchy */
66ebf6c0
TH
94 uint64_t cpu_weight;
95 uint64_t startup_cpu_weight;
96 usec_t cpu_quota_per_sec_usec;
97
13c31542
TH
98 uint64_t io_weight;
99 uint64_t startup_io_weight;
100 LIST_HEAD(CGroupIODeviceWeight, io_device_weights);
101 LIST_HEAD(CGroupIODeviceLimit, io_device_limits);
102
da4d897e
TH
103 uint64_t memory_low;
104 uint64_t memory_high;
105 uint64_t memory_max;
96e131ea 106 uint64_t memory_swap_max;
da4d897e 107
6a48d82f
DM
108 LIST_HEAD(IPAddressAccessItem, ip_address_allow);
109 LIST_HEAD(IPAddressAccessItem, ip_address_deny);
110
13c31542 111 /* For legacy hierarchies */
d53d9474
LP
112 uint64_t cpu_shares;
113 uint64_t startup_cpu_shares;
8e274523 114
d53d9474
LP
115 uint64_t blockio_weight;
116 uint64_t startup_blockio_weight;
4ad49000
LP
117 LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
118 LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
246aa6dd 119
4ad49000 120 uint64_t memory_limit;
64747e2d 121
4ad49000
LP
122 CGroupDevicePolicy device_policy;
123 LIST_HEAD(CGroupDeviceAllow, device_allow);
a931ad47 124
13c31542 125 /* Common */
03a7b521 126 uint64_t tasks_max;
d53d9474
LP
127
128 bool delegate;
4ad49000 129};
64747e2d 130
71d35b6b 131#include "unit.h"
8e274523 132
4ad49000
LP
133void cgroup_context_init(CGroupContext *c);
134void cgroup_context_done(CGroupContext *c);
135void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
bc432dc7 136
efdb0237 137CGroupMask cgroup_context_get_mask(CGroupContext *c);
fb385181 138
4ad49000 139void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
13c31542
TH
140void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w);
141void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l);
4ad49000
LP
142void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
143void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
8e274523 144
efdb0237
LP
145CGroupMask unit_get_own_mask(Unit *u);
146CGroupMask unit_get_siblings_mask(Unit *u);
147CGroupMask unit_get_members_mask(Unit *u);
148CGroupMask unit_get_subtree_mask(Unit *u);
149
150CGroupMask unit_get_target_mask(Unit *u);
151CGroupMask unit_get_enable_mask(Unit *u);
bc432dc7
LP
152
153void unit_update_cgroup_members_masks(Unit *u);
efdb0237
LP
154
155char *unit_default_cgroup_path(Unit *u);
156int unit_set_cgroup_path(Unit *u, const char *path);
157
0a1eb06d 158int unit_realize_cgroup(Unit *u);
efdb0237
LP
159void unit_release_cgroup(Unit *u);
160void unit_prune_cgroup(Unit *u);
161int unit_watch_cgroup(Unit *u);
162
7b3fd631 163int unit_attach_pids_to_cgroup(Unit *u);
8e274523 164
4ad49000
LP
165int manager_setup_cgroup(Manager *m);
166void manager_shutdown_cgroup(Manager *m, bool delete);
6dde1f33 167
4ad49000 168unsigned manager_dispatch_cgroup_queue(Manager *m);
4fbf50b3 169
4ad49000 170Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
b3ac818b 171Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
4ad49000 172Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
8e274523 173
efdb0237
LP
174int unit_search_main_pid(Unit *u, pid_t *ret);
175int unit_watch_all_pids(Unit *u);
8e274523 176
5ad096b3 177int unit_get_memory_current(Unit *u, uint64_t *ret);
03a7b521 178int unit_get_tasks_current(Unit *u, uint64_t *ret);
5ad096b3
LP
179int unit_get_cpu_usage(Unit *u, nsec_t *ret);
180int unit_reset_cpu_usage(Unit *u);
181
e9db43d5
LP
182bool unit_cgroup_delegate(Unit *u);
183
efdb0237
LP
184int unit_notify_cgroup_empty(Unit *u);
185int manager_notify_cgroup_empty(Manager *m, const char *group);
186
e7ab4d1a
LP
187void unit_invalidate_cgroup(Unit *u, CGroupMask m);
188
189void manager_invalidate_startup_units(Manager *m);
190
4ad49000
LP
191const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
192CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;