chiark / gitweb /
core: update CGroupBlockIODeviceBandwidth to record both rbps and wbps
[elogind.git] / src / core / cgroup.h
1 #pragma once
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2013 Lennart Poettering
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
22 #include <stdbool.h>
23
24 //#include "list.h"
25 #include "logind.h"
26 //#include "time-util.h"
27
28 #if 0 /// UNNEEDED by elogind
29 typedef struct CGroupContext CGroupContext;
30 typedef struct CGroupDeviceAllow CGroupDeviceAllow;
31 typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
32 typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
33
34 typedef enum CGroupDevicePolicy {
35
36         /* When devices listed, will allow those, plus built-in ones,
37         if none are listed will allow everything. */
38         CGROUP_AUTO,
39
40         /* Everything forbidden, except built-in ones and listed ones. */
41         CGROUP_CLOSED,
42
43         /* Everythings forbidden, except for the listed devices */
44         CGROUP_STRICT,
45
46         _CGROUP_DEVICE_POLICY_MAX,
47         _CGROUP_DEVICE_POLICY_INVALID = -1
48 } CGroupDevicePolicy;
49
50 struct CGroupDeviceAllow {
51         LIST_FIELDS(CGroupDeviceAllow, device_allow);
52         char *path;
53         bool r:1;
54         bool w:1;
55         bool m:1;
56 };
57
58 struct CGroupBlockIODeviceWeight {
59         LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
60         char *path;
61         uint64_t weight;
62 };
63
64 struct CGroupBlockIODeviceBandwidth {
65         LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
66         char *path;
67         uint64_t rbps;
68         uint64_t wbps;
69 };
70
71 struct CGroupContext {
72         bool cpu_accounting;
73         bool blockio_accounting;
74         bool memory_accounting;
75         bool tasks_accounting;
76
77         uint64_t cpu_shares;
78         uint64_t startup_cpu_shares;
79         usec_t cpu_quota_per_sec_usec;
80
81         uint64_t blockio_weight;
82         uint64_t startup_blockio_weight;
83         LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
84         LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
85
86         uint64_t memory_limit;
87
88         CGroupDevicePolicy device_policy;
89         LIST_HEAD(CGroupDeviceAllow, device_allow);
90
91         uint64_t tasks_max;
92
93         bool delegate;
94 };
95
96 #include "cgroup-util.h"
97 #include "unit.h"
98
99 void cgroup_context_init(CGroupContext *c);
100 void cgroup_context_done(CGroupContext *c);
101 void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
102 void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state);
103
104 CGroupMask cgroup_context_get_mask(CGroupContext *c);
105
106 void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
107 void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
108 void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
109
110 CGroupMask unit_get_own_mask(Unit *u);
111 CGroupMask unit_get_siblings_mask(Unit *u);
112 CGroupMask unit_get_members_mask(Unit *u);
113 CGroupMask unit_get_subtree_mask(Unit *u);
114
115 CGroupMask unit_get_target_mask(Unit *u);
116 CGroupMask unit_get_enable_mask(Unit *u);
117
118 void unit_update_cgroup_members_masks(Unit *u);
119
120 char *unit_default_cgroup_path(Unit *u);
121 int unit_set_cgroup_path(Unit *u, const char *path);
122
123 int unit_realize_cgroup(Unit *u);
124 void unit_release_cgroup(Unit *u);
125 void unit_prune_cgroup(Unit *u);
126 int unit_watch_cgroup(Unit *u);
127
128 int unit_attach_pids_to_cgroup(Unit *u);
129
130 #endif // 0
131 int manager_setup_cgroup(Manager *m);
132 void manager_shutdown_cgroup(Manager *m, bool delete);
133
134 #if 0 /// UNNEEDED by elogind
135 unsigned manager_dispatch_cgroup_queue(Manager *m);
136
137 Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
138 Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
139 Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
140
141 int unit_search_main_pid(Unit *u, pid_t *ret);
142 int unit_watch_all_pids(Unit *u);
143
144 int unit_get_memory_current(Unit *u, uint64_t *ret);
145 int unit_get_tasks_current(Unit *u, uint64_t *ret);
146 int unit_get_cpu_usage(Unit *u, nsec_t *ret);
147 int unit_reset_cpu_usage(Unit *u);
148
149 bool unit_cgroup_delegate(Unit *u);
150
151 int unit_notify_cgroup_empty(Unit *u);
152 int manager_notify_cgroup_empty(Manager *m, const char *group);
153
154 void unit_invalidate_cgroup(Unit *u, CGroupMask m);
155
156 void manager_invalidate_startup_units(Manager *m);
157
158 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
159 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
160 #endif // 0