Skip to content

Commit

Permalink
cgroupv2: fix fs2 driver default path
Browse files Browse the repository at this point in the history
When the cgroupv2 fs driver is used without setting cgroupsPath,
it picks up a path from /proc/self/cgroup. On a host with systemd,
such a path can look like (examples from my machines):

 - /user.slice/user-1000.slice/session-4.scope
 - /user.slice/user-1000.slice/[email protected]/gnome-launched-xfce4-terminal.desktop-4260.scope
 - /user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service

This cgroup already contains processes in it, which prevents to enable
controllers for a sub-cgroup (writing to cgroup.subtree_control fails
with EBUSY or EOPNOTSUPP).

Obviously, a parent cgroup (which does not contain tasks) should be used.

Fixes opencontainers/runc/issues/2298

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Apr 9, 2020
1 parent 158381f commit 5b9d813
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libcontainer/cgroups/fs2/defaultpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func defaultDirPath(c *configs.Cgroup) (string, error) {
if err != nil {
return "", err
}
// The current user scope most probably has tasks in it already,
// making it impossible to enable controllers for its sub-cgroup.
// A parent cgroup (with no tasks in it) is what we need.
ownCgroup = filepath.Dir(ownCgroup)

return _defaultDirPath(UnifiedMountpoint, cgPath, cgParent, cgName, ownCgroup)
}

Expand Down

0 comments on commit 5b9d813

Please sign in to comment.