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/>.
26 typedef struct CGroupContext CGroupContext;
27 typedef struct CGroupDeviceAllow CGroupDeviceAllow;
28 typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
29 typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
31 typedef enum CGroupDevicePolicy {
33 /* When devices listed, will allow those, plus built-in ones,
34 if none are listed will allow everything. */
37 /* Everything forbidden, except built-in ones and listed ones. */
40 /* Everythings forbidden, except for the listed devices */
43 _CGROUP_DEVICE_POLICY_MAX,
44 _CGROUP_DEVICE_POLICY_INVALID = -1
47 struct CGroupDeviceAllow {
48 LIST_FIELDS(CGroupDeviceAllow, device_allow);
55 struct CGroupBlockIODeviceWeight {
56 LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
61 struct CGroupBlockIODeviceBandwidth {
62 LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
68 struct CGroupContext {
70 bool blockio_accounting;
71 bool memory_accounting;
73 unsigned long cpu_shares;
74 unsigned long startup_cpu_shares;
75 bool startup_cpu_shares_set:1;
76 usec_t cpu_quota_per_sec_usec;
77 usec_t cpu_quota_usec;
78 usec_t cpu_quota_period_usec;
80 unsigned long blockio_weight;
81 unsigned long startup_blockio_weight;
82 bool startup_blockio_weight_set:1;
83 LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
84 LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
86 uint64_t memory_limit;
88 CGroupDevicePolicy device_policy;
89 LIST_HEAD(CGroupDeviceAllow, device_allow);
94 #include "cgroup-util.h"
96 void cgroup_context_init(CGroupContext *c);
97 void cgroup_context_done(CGroupContext *c);
98 void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
99 void cgroup_context_apply(Manager *m, CGroupContext *c, CGroupControllerMask mask, const char *path);
101 CGroupControllerMask cgroup_context_get_mask(Manager *m, CGroupContext *c);
103 void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
104 void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
105 void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
107 usec_t cgroup_context_get_cpu_quota_usec(CGroupContext *c);
108 usec_t cgroup_context_get_cpu_quota_per_sec_usec(CGroupContext *c);
110 CGroupControllerMask unit_get_cgroup_mask(Unit *u);
111 CGroupControllerMask unit_get_siblings_mask(Unit *u);
112 CGroupControllerMask unit_get_members_mask(Unit *u);
113 CGroupControllerMask unit_get_target_mask(Unit *u);
115 void unit_update_cgroup_members_masks(Unit *u);
116 int unit_realize_cgroup(Unit *u);
117 void unit_destroy_cgroup(Unit *u);
119 int manager_setup_cgroup(Manager *m);
120 void manager_shutdown_cgroup(Manager *m, bool delete);
122 unsigned manager_dispatch_cgroup_queue(Manager *m);
124 Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
125 Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
127 pid_t unit_search_main_pid(Unit *u);
129 int manager_notify_cgroup_empty(Manager *m, const char *group);
131 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
132 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;