Commit fc3c7f7f by Serge Hallyn Committed by Daniel Lezcano

cgroups: fix broken support for deprecated ns cgroup

when using ns cgroup, use /cgroup/<init-cgroup> rather than /cgroup/<init-cgroup>/lxc At least lxc-start, lxc-stop, lxc-cgroup, lxc-console and lxc-ls work with this patch. I've tested this in a 2.6.35 kernel with ns cgroup, and in a 3.2 kernel without ns cgroup. Note also that because of the check for container reboot support, if we're using the ns cgroup we now end up with a /cgroup/<container>/2 cgroup created, empty, by the clone(CLONE_NEWPID). I'm really not sure how much time we want to spend cleaning such things up since ns cgroup is deprecated in kernel. Signed-off-by: 's avatarSerge Hallyn <serge@hallyn.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 09f2410e
...@@ -137,6 +137,21 @@ found: ...@@ -137,6 +137,21 @@ found:
return dsg; return dsg;
} }
static int get_cgroup_flags(struct mntent *mntent)
{
int flags = 0;
if (hasmntopt(mntent, "ns"))
flags |= CGROUP_NS_CGROUP;
if (hasmntopt(mntent, "clone_children"))
flags |= CGROUP_CLONE_CHILDREN;
DEBUG("cgroup %s has flags 0x%x", mntent->mnt_dir, flags);
return flags;
}
static int get_cgroup_mount(const char *subsystem, char *mnt) static int get_cgroup_mount(const char *subsystem, char *mnt)
{ {
struct mntent *mntent; struct mntent *mntent;
...@@ -155,10 +170,12 @@ static int get_cgroup_mount(const char *subsystem, char *mnt) ...@@ -155,10 +170,12 @@ static int get_cgroup_mount(const char *subsystem, char *mnt)
continue; continue;
if (!subsystem || hasmntopt_multiple(mntent, subsystem)) { if (!subsystem || hasmntopt_multiple(mntent, subsystem)) {
int ret; int ret;
ret = snprintf(mnt, MAXPATHLEN, "%s%s/lxc", int flags = get_cgroup_flags(mntent);
ret = snprintf(mnt, MAXPATHLEN, "%s%s%s",
mntent->mnt_dir, mntent->mnt_dir,
get_init_cgroup(subsystem, NULL, get_init_cgroup(subsystem, NULL,
initcgroup)); initcgroup),
(flags & CGROUP_NS_CGROUP) ? "" : "/lxc");
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= MAXPATHLEN)
goto fail; goto fail;
fclose(file); fclose(file);
...@@ -183,33 +200,26 @@ int lxc_ns_is_mounted(void) ...@@ -183,33 +200,26 @@ int lxc_ns_is_mounted(void)
return (get_cgroup_mount("ns", buf) == 0); return (get_cgroup_mount("ns", buf) == 0);
} }
static int get_cgroup_flags(struct mntent *mntent)
{
int flags = 0;
if (hasmntopt(mntent, "ns"))
flags |= CGROUP_NS_CGROUP;
if (hasmntopt(mntent, "clone_children"))
flags |= CGROUP_CLONE_CHILDREN;
DEBUG("cgroup %s has flags 0x%x", mntent->mnt_dir, flags);
return flags;
}
static int cgroup_rename_nsgroup(const char *mnt, const char *name, pid_t pid) static int cgroup_rename_nsgroup(const char *mnt, const char *name, pid_t pid)
{ {
char oldname[MAXPATHLEN]; char oldname[MAXPATHLEN];
char newname[MAXPATHLEN];
int ret;
ret = snprintf(oldname, MAXPATHLEN, "%s/%d", mnt, pid);
if (ret >= MAXPATHLEN)
return -1;
snprintf(oldname, MAXPATHLEN, "%s/%d", mnt, pid); ret = snprintf(newname, MAXPATHLEN, "%s/%s", mnt, name);
if (ret >= MAXPATHLEN)
return -1;
if (rename(oldname, name)) { if (rename(oldname, newname)) {
SYSERROR("failed to rename cgroup %s->%s", oldname, name); SYSERROR("failed to rename cgroup %s->%s", oldname, newname);
return -1; return -1;
} }
DEBUG("'%s' renamed to '%s'", oldname, name); DEBUG("'%s' renamed to '%s'", oldname, newname);
return 0; return 0;
} }
...@@ -321,7 +331,7 @@ static int lxc_one_cgroup_create(const char *name, ...@@ -321,7 +331,7 @@ static int lxc_one_cgroup_create(const char *name,
/* Do we have the deprecated ns_cgroup subsystem? */ /* Do we have the deprecated ns_cgroup subsystem? */
if (flags & CGROUP_NS_CGROUP) { if (flags & CGROUP_NS_CGROUP) {
WARN("using deprecated ns_cgroup"); WARN("using deprecated ns_cgroup");
return cgroup_rename_nsgroup(cgparent, cgname, pid); return cgroup_rename_nsgroup(cginit, name, pid);
} }
ret = snprintf(clonechild, MAXPATHLEN, "%s/cgroup.clone_children", ret = snprintf(clonechild, MAXPATHLEN, "%s/cgroup.clone_children",
...@@ -464,9 +474,11 @@ int lxc_one_cgroup_destroy(struct mntent *mntent, const char *name) ...@@ -464,9 +474,11 @@ int lxc_one_cgroup_destroy(struct mntent *mntent, const char *name)
{ {
char cgname[MAXPATHLEN], initcgroup[MAXPATHLEN]; char cgname[MAXPATHLEN], initcgroup[MAXPATHLEN];
char *cgmnt = mntent->mnt_dir; char *cgmnt = mntent->mnt_dir;
int flags = get_cgroup_flags(mntent);
snprintf(cgname, MAXPATHLEN, "%s%s/lxc/%s", cgmnt, snprintf(cgname, MAXPATHLEN, "%s%s%s/%s", cgmnt,
get_init_cgroup(NULL, mntent, initcgroup), name); get_init_cgroup(NULL, mntent, initcgroup),
(flags & CGROUP_NS_CGROUP) ? "" : "/lxc", name);
DEBUG("destroying %s\n", cgname); DEBUG("destroying %s\n", cgname);
if (recursive_rmdir(cgname)) { if (recursive_rmdir(cgname)) {
SYSERROR("failed to remove cgroup '%s'", cgname); SYSERROR("failed to remove cgroup '%s'", cgname);
......
...@@ -33,7 +33,11 @@ if test -n "$active"; then ...@@ -33,7 +33,11 @@ if test -n "$active"; then
if test -n "$mount_point"; then if test -n "$mount_point"; then
# get cgroup for init # get cgroup for init
init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1` init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1`
cd $mount_point/$init_cgroup/lxc if [ ! -d $mount_point/$init_cgroup/lxc ]; then
cd $mount_point/$init_cgroup
else
cd $mount_point/$init_cgroup/lxc
fi
ls "$@" -d $active ls "$@" -d $active
fi fi
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment