From 0d9f8e188c1c4832e4f6b9de646478947ae86877 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Mon, 13 Jul 2009 23:12:10 +0200 Subject: [PATCH] detect a cgroup named 'lxc' This patch makes lxc to detect a specific cgroup dedicated to lxc which is mounted with the lxc name. That allows to mount different cgroup in different places with different options (aka subsystems) and assign one to be used by lxc. If no such mount point is found, the first cgroup mount point is used. Signed-off-by: Daniel Lezcano --- doc/lxc.sgml.in | 31 ++++++++++++++++++++----------- src/lxc/cgroup.c | 25 ++++++++++++++++--------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/doc/lxc.sgml.in b/doc/lxc.sgml.in index 77795a54c..85988da3d 100644 --- a/doc/lxc.sgml.in +++ b/doc/lxc.sgml.in @@ -126,27 +126,36 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - For the moment the easiest way to have all the features in the - kernel is to use the git tree at: - - git://git.kernel.org/pub/scm/linux/kernel/git/daveh/linux-2.6-lxc.git - - But the kernel version >= 2.6.27 shipped with the distros, may + The kernel version >= 2.6.27 shipped with the distros, will work with lxc, this one will have less functionalities but enough to be interesting. - The planned kernel version which lxc should - be fully functionaly is 2.6.29. + With the kernel 2.6.29, lxc is fully + functional. Before using the lxc, your system should be configured with the file capabilities, otherwise you will need - to run the lxc commands as root. The - control group should be mounted anywhere, eg: - mount -t cgroup cgroup /cgroup + to run the lxc commands as root. + + + The control group can be mounted anywhere, eg: + mount -t cgroup cgroup /cgroup. + + If you want to dedicate a specific cgroup mount point + for lxc, that is to have different cgroups + mounted at different places with different options but + let lxc to use one location, you can bind + the mount point with the name, eg: + mount -t cgroup lxc /cgroup4lxc or + mount -t cgroup -ons,cpuset,freezer,devices + lxc /cgroup4lxc + + + diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index bc90b9aea..26440427a 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -58,11 +58,20 @@ static int get_cgroup_mount(const char *mtab, char *mnt) } while ((mntent = getmntent(file))) { - if (strcmp(mntent->mnt_type, "cgroup")) - continue; - strcpy(mnt, mntent->mnt_dir); - err = 0; - break; + + /* there is a cgroup mounted named "lxc" */ + if (!strcmp(mntent->mnt_fsname, "lxc") && + !strcmp(mntent->mnt_type, "cgroup")) { + strcpy(mnt, mntent->mnt_dir); + err = 0; + break; + } + + /* fallback to the first non-lxc cgroup found */ + if (!strcmp(mntent->mnt_type, "cgroup") && err) { + strcpy(mnt, mntent->mnt_dir); + err = 0; + } }; fclose(file); @@ -87,8 +96,7 @@ int lxc_rename_nsgroup(const char *name, pid_t pid) ret = rename(oldname, newname); if (ret) - SYSERROR("failed to rename cgroup %s->%s", - oldname, newname); + SYSERROR("failed to rename cgroup %s->%s", oldname, newname); return ret; } @@ -110,8 +118,7 @@ int lxc_link_nsgroup(const char *name) unlink(lxc); ret = symlink(nsgroup, lxc); if (ret) - SYSERROR("failed to create symlink %s->%s", - nsgroup, lxc); + SYSERROR("failed to create symlink %s->%s", nsgroup, lxc); return ret; } -- 2.47.2