chiark / gitweb /
rules: simplify mmc RPMB handling
[elogind.git] / src / core / cgroup.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2013 Lennart Poettering
9
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.
14
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.
19
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/>.
22 ***/
23
24 #include <stdbool.h>
25
26 #include "list.h"
27 #include "time-util.h"
28
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         unsigned long weight;
62 };
63
64 struct CGroupBlockIODeviceBandwidth {
65         LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
66         char *path;
67         uint64_t bandwidth;
68         bool read;
69 };
70
71 struct CGroupContext {
72         bool cpu_accounting;
73         bool blockio_accounting;
74         bool memory_accounting;
75
76         unsigned long cpu_shares;
77         unsigned long startup_cpu_shares;
78         usec_t cpu_quota_per_sec_usec;
79
80         unsigned long blockio_weight;
81         unsigned long startup_blockio_weight;
82         LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
83         LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
84
85         uint64_t memory_limit;
86
87         CGroupDevicePolicy device_policy;
88         LIST_HEAD(CGroupDeviceAllow, device_allow);
89
90         bool delegate;
91 };
92
93 #include "unit.h"
94 #include "manager.h"
95 #include "cgroup-util.h"
96
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);
100 void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const char *path, ManagerState state);
101
102 CGroupControllerMask cgroup_context_get_mask(CGroupContext *c);
103
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);
107
108 CGroupControllerMask unit_get_cgroup_mask(Unit *u);
109 CGroupControllerMask unit_get_siblings_mask(Unit *u);
110 CGroupControllerMask unit_get_members_mask(Unit *u);
111 CGroupControllerMask unit_get_target_mask(Unit *u);
112
113 void unit_update_cgroup_members_masks(Unit *u);
114 int unit_realize_cgroup(Unit *u);
115 void unit_destroy_cgroup_if_empty(Unit *u);
116 int unit_attach_pids_to_cgroup(Unit *u);
117
118 int manager_setup_cgroup(Manager *m);
119 void manager_shutdown_cgroup(Manager *m, bool delete);
120
121 unsigned manager_dispatch_cgroup_queue(Manager *m);
122
123 Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
124 Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
125
126 pid_t unit_search_main_pid(Unit *u);
127
128 int manager_notify_cgroup_empty(Manager *m, const char *group);
129
130 const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
131 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;