2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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.
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.
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
24 #ifndef __LXC_CGROUP_H
25 #define __LXC_CGROUP_H
29 #include <sys/types.h>
36 CGROUP_LAYOUT_UNKNOWN
= -1,
37 CGROUP_LAYOUT_LEGACY
= 0,
38 CGROUP_LAYOUT_HYBRID
= 1,
39 CGROUP_LAYOUT_UNIFIED
= 2,
42 /* A descriptor for a mounted hierarchy
46 * Either NULL, or a null-terminated list of all the co-mounted controllers.
48 * Either NULL, or a null-terminated list of all enabled controllers.
51 * - The mountpoint we will use.
53 * It will be either /sys/fs/cgroup/controller or
54 * /sys/fs/cgroup/controllerlist.
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.
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).
66 * - The full path to the containers cgroup.
70 * If the hierarchy is a legacy hierarchy this will be set to
73 * If the hierarchy is a legacy hierarchy this will be set to
74 * CGROUP2_SUPER_MAGIC.
91 /* What controllers is the container supposed to use. */
94 char *container_cgroup
;
97 * - A NULL-terminated array of struct hierarchy, one per legacy
98 * hierarchy. No duplicates. First sufficient, writeable mounted
101 struct hierarchy
**hierarchies
;
102 struct hierarchy
*unified
;
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).
123 cgroup_layout_t cgroup_layout
;
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
,
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
);
148 extern struct cgroup_ops
*cgroup_init(struct lxc_conf
*conf
);
149 extern void cgroup_exit(struct cgroup_ops
*ops
);
151 extern void prune_init_scope(char *cg
);