Set unified mountpoint in find mnt func

This is needed for the fsv2 cgroups to work when there is a unified mountpoint.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2019-10-15 15:40:03 -04:00
parent c1485a1e88
commit b28f58f31b
No known key found for this signature in database
GPG Key ID: F3D4D52BDC000749
1 changed files with 9 additions and 5 deletions

View File

@ -20,8 +20,9 @@ import (
) )
const ( const (
CgroupNamePrefix = "name=" CgroupNamePrefix = "name="
CgroupProcesses = "cgroup.procs" CgroupProcesses = "cgroup.procs"
unifiedMountpoint = "/sys/fs/cgroup"
) )
var ( var (
@ -40,7 +41,7 @@ var HugePageSizeUnitList = []string{"B", "KB", "MB", "GB", "TB", "PB"}
func IsCgroup2UnifiedMode() bool { func IsCgroup2UnifiedMode() bool {
isUnifiedOnce.Do(func() { isUnifiedOnce.Do(func() {
var st syscall.Statfs_t var st syscall.Statfs_t
if err := syscall.Statfs("/sys/fs/cgroup", &st); err != nil { if err := syscall.Statfs(unifiedMountpoint, &st); err != nil {
panic("cannot statfs cgroup root") panic("cannot statfs cgroup root")
} }
isUnified = st.Type == unix.CGROUP2_SUPER_MAGIC isUnified = st.Type == unix.CGROUP2_SUPER_MAGIC
@ -50,6 +51,9 @@ func IsCgroup2UnifiedMode() bool {
// https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt // https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt
func FindCgroupMountpoint(cgroupPath, subsystem string) (string, error) { func FindCgroupMountpoint(cgroupPath, subsystem string) (string, error) {
if IsCgroup2UnifiedMode() {
return unifiedMountpoint, nil
}
mnt, _, err := FindCgroupMountpointAndRoot(cgroupPath, subsystem) mnt, _, err := FindCgroupMountpointAndRoot(cgroupPath, subsystem)
return mnt, err return mnt, err
} }
@ -235,8 +239,8 @@ func GetCgroupMounts(all bool) ([]Mount, error) {
return nil, err return nil, err
} }
m := Mount{ m := Mount{
Mountpoint: "/sys/fs/cgroup", Mountpoint: unifiedMountpoint,
Root: "/sys/fs/cgroup", Root: unifiedMountpoint,
Subsystems: availableControllers, Subsystems: availableControllers,
} }
return []Mount{m}, nil return []Mount{m}, nil