4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
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.
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.
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/>.
25 #include "time-util.h"
27 typedef struct CGroupContext CGroupContext
;
28 typedef struct CGroupDeviceAllow CGroupDeviceAllow
;
29 typedef struct CGroupIODeviceWeight CGroupIODeviceWeight
;
30 typedef struct CGroupIODeviceLimit CGroupIODeviceLimit
;
31 typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight
;
32 typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth
;
34 typedef enum CGroupDevicePolicy
{
36 /* When devices listed, will allow those, plus built-in ones,
37 if none are listed will allow everything. */
40 /* Everything forbidden, except built-in ones and listed ones. */
43 /* Everythings forbidden, except for the listed devices */
46 _CGROUP_DEVICE_POLICY_MAX
,
47 _CGROUP_DEVICE_POLICY_INVALID
= -1
50 struct CGroupDeviceAllow
{
51 LIST_FIELDS(CGroupDeviceAllow
, device_allow
);
58 struct CGroupIODeviceWeight
{
59 LIST_FIELDS(CGroupIODeviceWeight
, device_weights
);
64 struct CGroupIODeviceLimit
{
65 LIST_FIELDS(CGroupIODeviceLimit
, device_limits
);
71 struct CGroupBlockIODeviceWeight
{
72 LIST_FIELDS(CGroupBlockIODeviceWeight
, device_weights
);
77 struct CGroupBlockIODeviceBandwidth
{
78 LIST_FIELDS(CGroupBlockIODeviceBandwidth
, device_bandwidths
);
84 struct CGroupContext
{
87 bool blockio_accounting
;
88 bool memory_accounting
;
89 bool tasks_accounting
;
91 /* For unified hierarchy */
93 uint64_t startup_io_weight
;
94 LIST_HEAD(CGroupIODeviceWeight
, io_device_weights
);
95 LIST_HEAD(CGroupIODeviceLimit
, io_device_limits
);
97 /* For legacy hierarchies */
99 uint64_t startup_cpu_shares
;
100 usec_t cpu_quota_per_sec_usec
;
102 uint64_t blockio_weight
;
103 uint64_t startup_blockio_weight
;
104 LIST_HEAD(CGroupBlockIODeviceWeight
, blockio_device_weights
);
105 LIST_HEAD(CGroupBlockIODeviceBandwidth
, blockio_device_bandwidths
);
107 uint64_t memory_limit
;
109 CGroupDevicePolicy device_policy
;
110 LIST_HEAD(CGroupDeviceAllow
, device_allow
);
118 #include "cgroup-util.h"
121 void cgroup_context_init(CGroupContext
*c
);
122 void cgroup_context_done(CGroupContext
*c
);
123 void cgroup_context_dump(CGroupContext
*c
, FILE* f
, const char *prefix
);
124 void cgroup_context_apply(CGroupContext
*c
, CGroupMask mask
, const char *path
, ManagerState state
);
126 CGroupMask
cgroup_context_get_mask(CGroupContext
*c
);
128 void cgroup_context_free_device_allow(CGroupContext
*c
, CGroupDeviceAllow
*a
);
129 void cgroup_context_free_io_device_weight(CGroupContext
*c
, CGroupIODeviceWeight
*w
);
130 void cgroup_context_free_io_device_limit(CGroupContext
*c
, CGroupIODeviceLimit
*l
);
131 void cgroup_context_free_blockio_device_weight(CGroupContext
*c
, CGroupBlockIODeviceWeight
*w
);
132 void cgroup_context_free_blockio_device_bandwidth(CGroupContext
*c
, CGroupBlockIODeviceBandwidth
*b
);
134 CGroupMask
unit_get_own_mask(Unit
*u
);
135 CGroupMask
unit_get_siblings_mask(Unit
*u
);
136 CGroupMask
unit_get_members_mask(Unit
*u
);
137 CGroupMask
unit_get_subtree_mask(Unit
*u
);
139 CGroupMask
unit_get_target_mask(Unit
*u
);
140 CGroupMask
unit_get_enable_mask(Unit
*u
);
142 void unit_update_cgroup_members_masks(Unit
*u
);
144 char *unit_default_cgroup_path(Unit
*u
);
145 int unit_set_cgroup_path(Unit
*u
, const char *path
);
147 int unit_realize_cgroup(Unit
*u
);
148 void unit_release_cgroup(Unit
*u
);
149 void unit_prune_cgroup(Unit
*u
);
150 int unit_watch_cgroup(Unit
*u
);
152 int unit_attach_pids_to_cgroup(Unit
*u
);
154 int manager_setup_cgroup(Manager
*m
);
155 void manager_shutdown_cgroup(Manager
*m
, bool delete);
157 unsigned manager_dispatch_cgroup_queue(Manager
*m
);
159 Unit
*manager_get_unit_by_cgroup(Manager
*m
, const char *cgroup
);
160 Unit
*manager_get_unit_by_pid_cgroup(Manager
*m
, pid_t pid
);
161 Unit
* manager_get_unit_by_pid(Manager
*m
, pid_t pid
);
163 int unit_search_main_pid(Unit
*u
, pid_t
*ret
);
164 int unit_watch_all_pids(Unit
*u
);
166 int unit_get_memory_current(Unit
*u
, uint64_t *ret
);
167 int unit_get_tasks_current(Unit
*u
, uint64_t *ret
);
168 int unit_get_cpu_usage(Unit
*u
, nsec_t
*ret
);
169 int unit_reset_cpu_usage(Unit
*u
);
171 bool unit_cgroup_delegate(Unit
*u
);
173 int unit_notify_cgroup_empty(Unit
*u
);
174 int manager_notify_cgroup_empty(Manager
*m
, const char *group
);
176 void unit_invalidate_cgroup(Unit
*u
, CGroupMask m
);
178 void manager_invalidate_startup_units(Manager
*m
);
180 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i
) _const_
;
181 CGroupDevicePolicy
cgroup_device_policy_from_string(const char *s
) _pure_
;