]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | #pragma once |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
14228c0d | 6 | Copyright 2013 Lennart Poettering |
663996b3 MS |
7 | |
8 | systemd is free software; you can redistribute it and/or modify it | |
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 | |
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 | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
e735f4d4 MP |
22 | #include <stdbool.h> |
23 | ||
14228c0d | 24 | #include "list.h" |
e735f4d4 | 25 | #include "time-util.h" |
663996b3 | 26 | |
14228c0d MB |
27 | typedef struct CGroupContext CGroupContext; |
28 | typedef struct CGroupDeviceAllow CGroupDeviceAllow; | |
29 | typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight; | |
30 | typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth; | |
663996b3 | 31 | |
14228c0d | 32 | typedef enum CGroupDevicePolicy { |
663996b3 | 33 | |
14228c0d MB |
34 | /* When devices listed, will allow those, plus built-in ones, |
35 | if none are listed will allow everything. */ | |
36 | CGROUP_AUTO, | |
663996b3 | 37 | |
14228c0d MB |
38 | /* Everything forbidden, except built-in ones and listed ones. */ |
39 | CGROUP_CLOSED, | |
663996b3 | 40 | |
14228c0d MB |
41 | /* Everythings forbidden, except for the listed devices */ |
42 | CGROUP_STRICT, | |
663996b3 | 43 | |
14228c0d MB |
44 | _CGROUP_DEVICE_POLICY_MAX, |
45 | _CGROUP_DEVICE_POLICY_INVALID = -1 | |
46 | } CGroupDevicePolicy; | |
663996b3 | 47 | |
14228c0d MB |
48 | struct CGroupDeviceAllow { |
49 | LIST_FIELDS(CGroupDeviceAllow, device_allow); | |
50 | char *path; | |
51 | bool r:1; | |
52 | bool w:1; | |
53 | bool m:1; | |
54 | }; | |
663996b3 | 55 | |
14228c0d MB |
56 | struct CGroupBlockIODeviceWeight { |
57 | LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights); | |
58 | char *path; | |
6300502b | 59 | uint64_t weight; |
663996b3 MS |
60 | }; |
61 | ||
14228c0d MB |
62 | struct CGroupBlockIODeviceBandwidth { |
63 | LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths); | |
64 | char *path; | |
65 | uint64_t bandwidth; | |
66 | bool read; | |
67 | }; | |
663996b3 | 68 | |
14228c0d MB |
69 | struct CGroupContext { |
70 | bool cpu_accounting; | |
71 | bool blockio_accounting; | |
72 | bool memory_accounting; | |
6300502b | 73 | bool tasks_accounting; |
663996b3 | 74 | |
6300502b MP |
75 | uint64_t cpu_shares; |
76 | uint64_t startup_cpu_shares; | |
60f067b4 | 77 | usec_t cpu_quota_per_sec_usec; |
663996b3 | 78 | |
6300502b MP |
79 | uint64_t blockio_weight; |
80 | uint64_t startup_blockio_weight; | |
14228c0d MB |
81 | LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights); |
82 | LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths); | |
663996b3 | 83 | |
14228c0d | 84 | uint64_t memory_limit; |
663996b3 | 85 | |
14228c0d MB |
86 | CGroupDevicePolicy device_policy; |
87 | LIST_HEAD(CGroupDeviceAllow, device_allow); | |
f47781d8 | 88 | |
6300502b MP |
89 | uint64_t tasks_max; |
90 | ||
f47781d8 | 91 | bool delegate; |
14228c0d | 92 | }; |
663996b3 | 93 | |
14228c0d | 94 | #include "cgroup-util.h" |
4c89c718 | 95 | #include "unit.h" |
663996b3 | 96 | |
14228c0d MB |
97 | void cgroup_context_init(CGroupContext *c); |
98 | void cgroup_context_done(CGroupContext *c); | |
99 | void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix); | |
4c89c718 | 100 | void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state); |
60f067b4 | 101 | |
d9dfd233 | 102 | CGroupMask cgroup_context_get_mask(CGroupContext *c); |
663996b3 | 103 | |
14228c0d MB |
104 | void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a); |
105 | void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w); | |
106 | void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b); | |
663996b3 | 107 | |
d9dfd233 MP |
108 | CGroupMask unit_get_own_mask(Unit *u); |
109 | CGroupMask unit_get_siblings_mask(Unit *u); | |
110 | CGroupMask unit_get_members_mask(Unit *u); | |
111 | CGroupMask unit_get_subtree_mask(Unit *u); | |
112 | ||
113 | CGroupMask unit_get_target_mask(Unit *u); | |
114 | CGroupMask unit_get_enable_mask(Unit *u); | |
60f067b4 JS |
115 | |
116 | void unit_update_cgroup_members_masks(Unit *u); | |
d9dfd233 MP |
117 | |
118 | char *unit_default_cgroup_path(Unit *u); | |
119 | int unit_set_cgroup_path(Unit *u, const char *path); | |
120 | ||
14228c0d | 121 | int unit_realize_cgroup(Unit *u); |
d9dfd233 MP |
122 | void unit_release_cgroup(Unit *u); |
123 | void unit_prune_cgroup(Unit *u); | |
124 | int unit_watch_cgroup(Unit *u); | |
125 | ||
f47781d8 | 126 | int unit_attach_pids_to_cgroup(Unit *u); |
663996b3 | 127 | |
14228c0d MB |
128 | int manager_setup_cgroup(Manager *m); |
129 | void manager_shutdown_cgroup(Manager *m, bool delete); | |
663996b3 | 130 | |
14228c0d | 131 | unsigned manager_dispatch_cgroup_queue(Manager *m); |
663996b3 | 132 | |
14228c0d | 133 | Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup); |
d9dfd233 | 134 | Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid); |
14228c0d | 135 | Unit* manager_get_unit_by_pid(Manager *m, pid_t pid); |
663996b3 | 136 | |
d9dfd233 MP |
137 | int unit_search_main_pid(Unit *u, pid_t *ret); |
138 | int unit_watch_all_pids(Unit *u); | |
663996b3 | 139 | |
e3bff60a | 140 | int unit_get_memory_current(Unit *u, uint64_t *ret); |
6300502b | 141 | int unit_get_tasks_current(Unit *u, uint64_t *ret); |
e3bff60a MP |
142 | int unit_get_cpu_usage(Unit *u, nsec_t *ret); |
143 | int unit_reset_cpu_usage(Unit *u); | |
144 | ||
d9dfd233 MP |
145 | bool unit_cgroup_delegate(Unit *u); |
146 | ||
147 | int unit_notify_cgroup_empty(Unit *u); | |
148 | int manager_notify_cgroup_empty(Manager *m, const char *group); | |
149 | ||
6300502b MP |
150 | void unit_invalidate_cgroup(Unit *u, CGroupMask m); |
151 | ||
152 | void manager_invalidate_startup_units(Manager *m); | |
153 | ||
14228c0d MB |
154 | const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_; |
155 | CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_; |