Skip to content

Commit

Permalink
Merge pull request opencontainers#135 from LK4D4/fix_apply_cgroups
Browse files Browse the repository at this point in the history
Substract source mount from cgroup dir
  • Loading branch information
Mrunal Patel committed Jul 17, 2015
2 parents 11370f0 + fc31076 commit 618e0ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libcontainer/cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,20 @@ func getCgroupData(c *configs.Cgroup, pid int) (*data, error) {
}, nil
}

func (raw *data) parent(subsystem, mountpoint string) (string, error) {
func (raw *data) parent(subsystem, mountpoint, src string) (string, error) {
initPath, err := cgroups.GetInitCgroupDir(subsystem)
if err != nil {
return "", err
}
return filepath.Join(mountpoint, initPath), nil
relDir, err := filepath.Rel(src, initPath)
if err != nil {
return "", err
}
return filepath.Join(mountpoint, relDir), nil
}

func (raw *data) path(subsystem string) (string, error) {
mnt, err := cgroups.FindCgroupMountpoint(subsystem)
mnt, src, err := cgroups.FindCgroupMountpointAndSource(subsystem)
// If we didn't mount the subsystem, there is no point we make the path.
if err != nil {
return "", err
Expand All @@ -255,7 +259,7 @@ func (raw *data) path(subsystem string) (string, error) {
return filepath.Join(raw.root, subsystem, raw.cgroup), nil
}

parent, err := raw.parent(subsystem, mnt)
parent, err := raw.parent(subsystem, mnt, src)
if err != nil {
return "", err
}
Expand Down
22 changes: 22 additions & 0 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ func FindCgroupMountpoint(subsystem string) (string, error) {
return "", NewNotFoundError(subsystem)
}

func FindCgroupMountpointAndSource(subsystem string) (string, string, error) {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return "", "", err
}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
txt := scanner.Text()
fields := strings.Split(txt, " ")
for _, opt := range strings.Split(fields[len(fields)-1], ",") {
if opt == subsystem {
return fields[4], fields[3], nil
}
}
}
if err := scanner.Err(); err != nil {
return "", "", err
}

return "", "", NewNotFoundError(subsystem)
}

func FindCgroupMountpointDir() (string, error) {
mounts, err := mount.GetMounts()
if err != nil {
Expand Down

0 comments on commit 618e0ca

Please sign in to comment.