1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2013 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 // #include "time-util.h"
30 #if 0 /// UNNEEDED by elogind
31 typedef struct CGroupContext CGroupContext;
32 Stypedef struct CGroupDeviceAllow CGroupDeviceAllow;
33 typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
34 typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
36 /* Maximum value for fixed (manual) net class ID assignment,
37 * and also the value at which the range of automatic assignments starts
39 #define CGROUP_NETCLASS_FIXED_MAX UINT32_C(65535)
41 typedef struct CGroupContext CGroupContext;
42 typedef struct CGroupDeviceAllow CGroupDeviceAllow;
43 typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
44 typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
46 typedef enum CGroupDevicePolicy {
48 /* When devices listed, will allow those, plus built-in ones,
49 if none are listed will allow everything. */
52 /* Everything forbidden, except built-in ones and listed ones. */
55 /* Everythings forbidden, except for the listed devices */
58 _CGROUP_DEVICE_POLICY_MAX,
59 _CGROUP_DEVICE_POLICY_INVALID = -1
62 typedef enum CGroupNetClassType {
63 /* Default - do not assign a net class */
64 CGROUP_NETCLASS_TYPE_NONE,
66 /* Automatically assign a net class */
67 CGROUP_NETCLASS_TYPE_AUTO,
69 /* Assign the net class that was provided by the user */
70 CGROUP_NETCLASS_TYPE_FIXED,
73 struct CGroupDeviceAllow {
74 LIST_FIELDS(CGroupDeviceAllow, device_allow);
81 struct CGroupBlockIODeviceWeight {
82 LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
87 struct CGroupBlockIODeviceBandwidth {
88 LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
94 struct CGroupContext {
96 bool blockio_accounting;
97 bool memory_accounting;
98 bool tasks_accounting;
101 uint64_t startup_cpu_shares;
102 usec_t cpu_quota_per_sec_usec;
104 uint64_t blockio_weight;
105 uint64_t startup_blockio_weight;
106 LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
107 LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
109 uint64_t memory_limit;
111 CGroupDevicePolicy device_policy;
112 LIST_HEAD(CGroupDeviceAllow, device_allow);
114 CGroupNetClassType netclass_type;
115 uint32_t netclass_id;
122 #include "cgroup-util.h"
125 void cgroup_context_init(CGroupContext *c);
126 void cgroup_context_done(CGroupContext *c);
127 void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
128 void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, uint32_t netclass_id, ManagerState state);
130 CGroupMask cgroup_context_get_mask(CGroupContext *c);
132 void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
133 void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
134 void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
136 CGroupMask unit_get_own_mask(Unit *u);
137 CGroupMask unit_get_siblings_mask(Unit *u);
138 CGroupMask unit_get_members_mask(Unit *u);
139 CGroupMask unit_get_subtree_mask(Unit *u);
141 vCGroupMask unit_get_target_mask(Unit *u);
142 CGroupMask unit_get_enable_mask(Unit *u);
144 void unit_update_cgroup_members_masks(Unit *u);
146 har *unit_default_cgroup_path(Unit *u);
147 int unit_set_cgroup_path(Unit *u, const char *path);
149 int unit_realize_cgroup(Unit *u);
150 void unit_release_cgroup(Unit *u);
151 void unit_prune_cgroup(Unit *u);
152 int unit_watch_cgroup(Unit *u);
154 int unit_attach_pids_to_cgroup(Unit *u);
156 int unit_add_to_netclass_cgroup(Unit *u);
157 int unit_remove_from_netclass_cgroup(Unit *u);
160 int manager_setup_cgroup(Manager *m);
161 void manager_shutdown_cgroup(Manager *m, bool delete);
163 #if 0 /// UNNEEDED by elogind
164 unsigned manager_dispatch_cgroup_queue(Manager *m);
166 Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
167 Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
168 Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
170 int unit_search_main_pid(Unit *u, pid_t *ret);
171 int unit_watch_all_pids(Unit *u);
173 int unit_get_memory_current(Unit *u, uint64_t *ret);
174 int unit_get_tasks_current(Unit *u, uint64_t *ret);
175 int unit_get_cpu_usage(Unit *u, nsec_t *ret);
176 int unit_reset_cpu_usage(Unit *u);
178 bool unit_cgroup_delegate(Unit *u);
180 int unit_notify_cgroup_empty(Unit *u);
181 int manager_notify_cgroup_empty(Manager *m, const char *group);
183 void unit_invalidate_cgroup(Unit *u, CGroupMask m);
185 void manager_invalidate_startup_units(Manager *m);
187 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
188 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;