]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/cgroups/cgroup.h
cgroups: s/fullcgpath/container_full_path/g
[mirror_lxc.git] / src / lxc / cgroups / cgroup.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef __LXC_CGROUP_H
25 #define __LXC_CGROUP_H
26
27 #include <stdbool.h>
28 #include <stddef.h>
29 #include <sys/types.h>
30
31 struct lxc_handler;
32 struct lxc_conf;
33 struct lxc_list;
34
35 typedef 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
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 * @container_full_path
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 */
76 struct hierarchy {
77 char **controllers;
78 char *mountpoint;
79 char *base_cgroup;
80 char *container_full_path;
81 int version;
82 };
83
84 struct cgroup_ops {
85 /* string constant */
86 const char *driver;
87
88 /* string constant */
89 const char *version;
90
91 /* What controllers is the container supposed to use. */
92 char **cgroup_use;
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);
127 bool (*payload_create)(struct cgroup_ops *ops, struct lxc_handler *handler);
128 bool (*payload_enter)(struct cgroup_ops *ops, pid_t pid);
129 const char *(*get_cgroup)(struct cgroup_ops *ops, const char *controller);
130 bool (*escape)(const struct cgroup_ops *ops, struct lxc_conf *conf);
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);
146 };
147
148 extern struct cgroup_ops *cgroup_init(struct lxc_conf *conf);
149 extern void cgroup_exit(struct cgroup_ops *ops);
150
151 extern void prune_init_scope(char *cg);
152
153 #endif