From 209c8d9979e0a29baccf4e479b3066e992ef48c8 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Thu, 5 Nov 2015 19:08:35 +0800 Subject: [PATCH] Add some comments about cgroup We fixed some bugs and introduced some code hard to be understood, add some comments for them. Signed-off-by: Qiang Huang --- libcontainer/cgroups/fs/apply_raw.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libcontainer/cgroups/fs/apply_raw.go b/libcontainer/cgroups/fs/apply_raw.go index a6cf181e..68ebcfef 100644 --- a/libcontainer/cgroups/fs/apply_raw.go +++ b/libcontainer/cgroups/fs/apply_raw.go @@ -246,10 +246,15 @@ func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) { } func (raw *cgroupData) parentPath(subsystem, mountpoint, root string) (string, error) { + // Use GetThisCgroupDir instead of GetInitCgroupDir, because the creating + // process could in container and shared pid namespace with host, and + // /proc/1/cgroup could point to whole other world of cgroups. initPath, err := cgroups.GetThisCgroupDir(subsystem) if err != nil { return "", err } + // This is needed for nested containers, because in /proc/self/cgroup we + // see pathes from host, which don't exist in container. relDir, err := filepath.Rel(root, initPath) if err != nil { return "", err @@ -267,6 +272,7 @@ func (raw *cgroupData) path(subsystem string) (string, error) { cgPath := filepath.Join(raw.parent, raw.name) // If the cgroup name/path is absolute do not look relative to the cgroup of the init process. if filepath.IsAbs(cgPath) { + // Sometimes subsystems can be mounted togethger as 'cpu,cpuacct'. return filepath.Join(raw.root, filepath.Base(mnt), cgPath), nil }