Skip to content

Commit

Permalink
utils: takes the longest path on cgroup v1
Browse files Browse the repository at this point in the history
now getCgroupProcess takes the longest path on cgroup v1, instead of
complaining if the paths are different.

This should help when --cgroups=split is used on cgroup v1 and the
process cgroups look like:

$ cat /proc/self/cgroup
11:pids:/user.slice/user-0.slice/session-4.scope
10:blkio:/
9:cpuset:/
8:devices:/user.slice
7:freezer:/
6:memory:/user.slice/user-0.slice/session-4.scope
5:net_cls,net_prio:/
4:hugetlb:/
3:cpu,cpuacct:/
2:perf_event:/

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 11, 2021
1 parent 1b5f3ed commit 660a06f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
7 changes: 7 additions & 0 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ func SkipIfNotRootless(reason string) {
}
}

func SkipIfNotSystemd(manager, reason string) {
checkReason(reason)
if manager != "systemd" {
ginkgo.Skip("[notSystemd]: " + reason)
}
}

func SkipIfNotFedora() {
info := GetHostDistributionInfo()
if info.Distribution != "fedora" {
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,37 @@ USER mail`
Expect(found).To(BeTrue())
})

It("podman run with cgroups=split", func() {
SkipIfNotSystemd(podmanTest.CgroupManager, "do not test --cgroups=split if not running on systemd")
SkipIfRootlessCgroupsV1("Disable cgroups not supported on cgroupv1 for rootless users")
SkipIfRemote("--cgroups=split cannot be used in remote mode")

container := podmanTest.Podman([]string{"run", "--rm", "--cgroups=split", ALPINE, "cat", "/proc/self/cgroup"})
container.WaitWithDefaultTimeout()
Expect(container.ExitCode()).To(Equal(0))
lines := container.OutputToStringArray()

cgroup := ""
for _, line := range lines {
parts := strings.SplitN(line, ":", 3)
if !CGROUPSV2 {
// ignore unified on cgroup v1
// both runc and crun do not set it.
if parts[1] == "" {
continue
}
}
if parts[2] == "/" {
continue
}
if cgroup == "" {
cgroup = parts[2]
continue
}
Expect(cgroup).To(Equal(parts[2]))
}
})

It("podman run with cgroups=disabled runs without cgroups", func() {
SkipIfRootless("FIXME: I believe this should work but need to fix this test")
SkipIfRootlessCgroupsV1("Disable cgroups not supported on cgroupv1 for rootless users")
Expand Down
11 changes: 2 additions & 9 deletions utils/utils_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,9 @@ func getCgroupProcess(procFile string) (string, error) {
cgroup = line[3:]
break
}
// root cgroup, skip it
if parts[2] == "/" {
continue
}
// The process must have the same cgroup path for all controllers
// The OCI runtime spec file allow us to specify only one path.
if cgroup != "/" && cgroup != parts[2] {
return "", errors.Errorf("cgroup configuration not supported, the process is in two different cgroups")
if len(parts[2]) > len(cgroup) {
cgroup = parts[2]
}
cgroup = parts[2]
}
if cgroup == "/" {
return "", errors.Errorf("could not find cgroup mount in %q", procFile)
Expand Down

0 comments on commit 660a06f

Please sign in to comment.