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