]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/cgroups/cgroup.h
cgroup: rename container specific cgroup functions
[mirror_lxc.git] / src / lxc / cgroups / cgroup.h
CommitLineData
576f946d 1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
9afe19d6 7 * Daniel Lezcano <daniel.lezcano at free.fr>
576f946d 8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
250b1eec 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
576f946d 22 */
33ad9f1a 23
f1a4a029
ÇO
24#ifndef __LXC_CGROUP_H
25#define __LXC_CGROUP_H
33ad9f1a 26
4fb3cba5
DE
27#include <stdbool.h>
28#include <stddef.h>
29#include <sys/types.h>
33ad9f1a 30
758437c5 31struct lxc_handler;
4fb3cba5 32struct lxc_conf;
b98f7d6e 33struct lxc_list;
33ad9f1a 34
d6337a5f
CB
35typedef enum {
36 CGROUP_LAYOUT_UNKNOWN = -1,
37 CGROUP_LAYOUT_LEGACY = 0,
38 CGROUP_LAYOUT_HYBRID = 1,
39 CGROUP_LAYOUT_UNIFIED = 2,
40} cgroup_layout_t;
41
2202afc9
CB
42/* A descriptor for a mounted hierarchy
43 *
44 * @controllers
45 * - legacy hierarchy
46 * Either NULL, or a null-terminated list of all the co-mounted controllers.
47 * - unified hierarchy
48 * Either NULL, or a null-terminated list of all enabled controllers.
49 *
50 * @mountpoint
51 * - The mountpoint we will use.
52 * - legacy hierarchy
53 * It will be either /sys/fs/cgroup/controller or
54 * /sys/fs/cgroup/controllerlist.
55 * - unified hierarchy
56 * It will either be /sys/fs/cgroup or /sys/fs/cgroup/<mountpoint-name>
57 * depending on whether this is a hybrid cgroup layout (mix of legacy and
58 * unified hierarchies) or a pure unified cgroup layout.
59 *
60 * @base_cgroup
61 * - The cgroup under which the container cgroup path
62 * is created. This will be either the caller's cgroup (if not root), or
63 * init's cgroup (if root).
64 *
65 * @fullcgpath
66 * - The full path to the containers cgroup.
67 *
68 * @version
69 * - legacy hierarchy
70 * If the hierarchy is a legacy hierarchy this will be set to
71 * CGROUP_SUPER_MAGIC.
72 * - unified hierarchy
73 * If the hierarchy is a legacy hierarchy this will be set to
74 * CGROUP2_SUPER_MAGIC.
75 */
76struct hierarchy {
77 char **controllers;
78 char *mountpoint;
79 char *base_cgroup;
80 char *fullcgpath;
81 int version;
82};
83
d4ef7c50 84struct cgroup_ops {
2202afc9 85 /* string constant */
d2a4d1db 86 const char *driver;
2202afc9
CB
87
88 /* string constant */
d2a4d1db 89 const char *version;
4fb3cba5 90
2202afc9 91 /* What controllers is the container supposed to use. */
b7b18fc5 92 char **cgroup_use;
2202afc9
CB
93 char *cgroup_pattern;
94 char *container_cgroup;
95
96 /* @hierarchies
97 * - A NULL-terminated array of struct hierarchy, one per legacy
98 * hierarchy. No duplicates. First sufficient, writeable mounted
99 * hierarchy wins.
100 */
101 struct hierarchy **hierarchies;
102 struct hierarchy *unified;
103
104 /*
105 * @cgroup_layout
106 * - What cgroup layout the container is running with.
107 * - CGROUP_LAYOUT_UNKNOWN
108 * The cgroup layout could not be determined. This should be treated
109 * as an error condition.
110 * - CGROUP_LAYOUT_LEGACY
111 * The container is running with all controllers mounted into legacy
112 * cgroup hierarchies.
113 * - CGROUP_LAYOUT_HYBRID
114 * The container is running with at least one controller mounted
115 * into a legacy cgroup hierarchy and a mountpoint for the unified
116 * hierarchy. The unified hierarchy can be empty (no controllers
117 * enabled) or non-empty (controllers enabled).
118 * - CGROUP_LAYOUT_UNIFIED
119 * The container is running on a pure unified cgroup hierarchy. The
120 * unified hierarchy can be empty (no controllers enabled) or
121 * non-empty (controllers enabled).
122 */
123 cgroup_layout_t cgroup_layout;
124
125 bool (*data_init)(struct cgroup_ops *ops);
126 void (*destroy)(struct cgroup_ops *ops, struct lxc_handler *handler);
e8b181f5
CB
127 bool (*payload_create)(struct cgroup_ops *ops, struct lxc_handler *handler);
128 bool (*payload_enter)(struct cgroup_ops *ops, pid_t pid);
2202afc9 129 const char *(*get_cgroup)(struct cgroup_ops *ops, const char *controller);
5a087e05 130 bool (*escape)(const struct cgroup_ops *ops, struct lxc_conf *conf);
2202afc9
CB
131 int (*num_hierarchies)(struct cgroup_ops *ops);
132 bool (*get_hierarchies)(struct cgroup_ops *ops, int n, char ***out);
133 int (*set)(struct cgroup_ops *ops, const char *filename,
134 const char *value, const char *name, const char *lxcpath);
135 int (*get)(struct cgroup_ops *ops, const char *filename, char *value,
136 size_t len, const char *name, const char *lxcpath);
137 bool (*unfreeze)(struct cgroup_ops *ops);
138 bool (*setup_limits)(struct cgroup_ops *ops, struct lxc_conf *conf,
139 bool with_devices);
140 bool (*chown)(struct cgroup_ops *ops, struct lxc_conf *conf);
141 bool (*attach)(struct cgroup_ops *ops, const char *name,
142 const char *lxcpath, pid_t pid);
143 bool (*mount)(struct cgroup_ops *ops, struct lxc_handler *handler,
144 const char *root, int type);
145 int (*nrtasks)(struct cgroup_ops *ops);
d4ef7c50
SH
146};
147
5a087e05 148extern struct cgroup_ops *cgroup_init(struct lxc_conf *conf);
2202afc9 149extern void cgroup_exit(struct cgroup_ops *ops);
d4ef7c50 150
f348e47c
SH
151extern void prune_init_scope(char *cg);
152
576f946d 153#endif