1
Description: set clone_children on init's cgroup, not on <init's cgroup>/lxc
2
Not doing so is causing containers to not be reclassified for cpusets.
3
This needs to be forwarded upstream but has not yet been.
4
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
6
Index: lxc/src/lxc/cgroup.c
7
===================================================================
8
--- lxc.orig/src/lxc/cgroup.c 2012-01-20 09:43:31.374700000 -0600
9
+++ lxc/src/lxc/cgroup.c 2012-01-20 11:18:14.655071424 -0600
11
static int lxc_one_cgroup_create(const char *name,
12
struct mntent *mntent, pid_t pid)
14
- char cgname[MAXPATHLEN], cgparent[MAXPATHLEN];
15
+ char cginit[MAXPATHLEN], cgname[MAXPATHLEN], cgparent[MAXPATHLEN];
16
char clonechild[MAXPATHLEN];
17
char initcgroup[MAXPATHLEN];
20
- /* cgparent is the parent dir, /sys/fs/cgroup/<init-cgroup>/lxc */
21
+ /* cgparent is the parent dir, /sys/fs/cgroup/<cgroup>/<init-cgroup>/lxc */
22
/* (remember get_init_cgroup() returns a path starting with '/') */
23
- /* cgname is the full name, /sys/fs/cgroup/<init-cgroup>/lxc/name */
24
- ret = snprintf(cgparent, MAXPATHLEN, "%s%s/lxc", mntent->mnt_dir,
25
+ /* cgname is the full name, /sys/fs/cgroup/</cgroup>/<init-cgroup>/lxc/name */
26
+ ret = snprintf(cginit, MAXPATHLEN, "%s%s", mntent->mnt_dir,
27
get_init_cgroup(NULL, mntent, initcgroup));
28
if (ret < 0 || ret >= MAXPATHLEN) {
29
+ SYSERROR("Failed creating pathname for init's cgroup (%d)\n", ret);
33
+ ret = snprintf(cgparent, MAXPATHLEN, "%s/lxc", cginit);
34
+ if (ret < 0 || ret >= MAXPATHLEN) {
35
SYSERROR("Failed creating pathname for cgroup parent (%d)\n", ret);
42
- /* if /sys/fs/cgroup/<init-cgroup>/lxc does not exist, create it */
43
- if (access(cgparent, F_OK) && mkdir(cgparent, 0755)) {
44
- SYSERROR("failed to create '%s' directory", cgparent);
49
- * There is a previous cgroup. Try to delete it. If that fails
50
- * (i.e. it is not empty) try to move it out of the way.
52
- if (!access(cgname, F_OK) && rmdir(cgname)) {
53
- if (try_to_move_cgname(cgparent, cgname)) {
54
- SYSERROR("failed to remove previous cgroup '%s'", cgname);
59
flags = get_cgroup_flags(mntent);
61
- /* We have the deprecated ns_cgroup subsystem */
62
+ /* Do we have the deprecated ns_cgroup subsystem? */
63
if (flags & CGROUP_NS_CGROUP) {
64
WARN("using deprecated ns_cgroup");
65
return cgroup_rename_nsgroup(cgparent, cgname, pid);
68
- ret = snprintf(clonechild, MAXPATHLEN, "%s/cgroup.clone_children", cgparent);
69
+ ret = snprintf(clonechild, MAXPATHLEN, "%s/cgroup.clone_children",
71
if (ret < 0 || ret >= MAXPATHLEN) {
72
SYSERROR("Failed creating pathname for clone_children (%d)\n", ret);
78
- /* we enable the clone_children flag of the cgroup */
79
+ /* enable the clone_children flag of the cgroup */
80
if (cgroup_enable_clone_children(clonechild)) {
81
SYSERROR("failed to enable 'clone_children flag");
85
+ /* if /sys/fs/cgroup/<cgroup>/<init-cgroup>/lxc does not exist, create it */
86
+ if (access(cgparent, F_OK) && mkdir(cgparent, 0755)) {
87
+ SYSERROR("failed to create '%s' directory", cgparent);
92
+ * There is a previous cgroup. Try to delete it. If that fails
93
+ * (i.e. it is not empty) try to move it out of the way.
95
+ if (!access(cgname, F_OK) && rmdir(cgname)) {
96
+ if (try_to_move_cgname(cgparent, cgname)) {
97
+ SYSERROR("failed to remove previous cgroup '%s'", cgname);
102
/* Let's create the cgroup */
103
if (mkdir(cgname, 0755)) {
104
SYSERROR("failed to create '%s' directory", cgname);