diff --git a/src/runtime/pkg/resourcecontrol/cgroups.go b/src/runtime/pkg/resourcecontrol/cgroups.go index be8e9dc973..42006f4949 100644 --- a/src/runtime/pkg/resourcecontrol/cgroups.go +++ b/src/runtime/pkg/resourcecontrol/cgroups.go @@ -136,7 +136,7 @@ func NewResourceController(path string, resources *specs.LinuxResources) (Resour var cgroupPath string if cgroups.Mode() == cgroups.Legacy || cgroups.Mode() == cgroups.Hybrid { - cgroupPath, err = ValidCgroupPathV1(path, IsSystemdCgroup(path)) + cgroupPath, err = ValidCgroupPath(path, false, IsSystemdCgroup(path)) if err != nil { return nil, err } @@ -145,7 +145,7 @@ func NewResourceController(path string, resources *specs.LinuxResources) (Resour return nil, err } } else if cgroups.Mode() == cgroups.Unified { - cgroupPath, err = ValidCgroupPathV2(path, IsSystemdCgroup(path)) + cgroupPath, err = ValidCgroupPath(path, true, IsSystemdCgroup(path)) if err != nil { return nil, err } diff --git a/src/runtime/pkg/resourcecontrol/utils_linux.go b/src/runtime/pkg/resourcecontrol/utils_linux.go index 0acbc6c6af..52ac68f5af 100644 --- a/src/runtime/pkg/resourcecontrol/utils_linux.go +++ b/src/runtime/pkg/resourcecontrol/utils_linux.go @@ -21,35 +21,15 @@ import ( // DefaultResourceControllerID runtime-determined location in the cgroups hierarchy. const DefaultResourceControllerID = "/vc" -// ValidCgroupPathV1 returns a valid cgroup path for cgroup v1. +// ValidCgroupPath returns a valid cgroup path. // see https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#cgroups-path -func ValidCgroupPathV1(path string, systemdCgroup bool) (string, error) { +func ValidCgroupPath(path string, isCgroupV2 bool, systemdCgroup bool) (string, error) { if IsSystemdCgroup(path) { - return path, nil - } - - if systemdCgroup { - return "", fmt.Errorf("malformed systemd path '%v': expected to be of form 'slice:prefix:name'", path) - } - - // In the case of an absolute path (starting with /), the runtime MUST - // take the path to be relative to the cgroups mount point. - if filepath.IsAbs(path) { - return filepath.Clean(path), nil - } - - // In the case of a relative path (not starting with /), the runtime MAY - // interpret the path relative to a runtime-determined location in the cgroups hierarchy. - // clean up path and return a new path relative to DefaultResourceControllerID - return filepath.Join(DefaultResourceControllerID, filepath.Clean("/"+path)), nil -} - -// ValidCgroupPathV2 returns a valid cgroup path for cgroup v2. -// see https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#cgroups-path -func ValidCgroupPathV2(path string, systemdCgroup bool) (string, error) { - // In cgroup v2,path must be a "clean" absolute path starts with "/". - if IsSystemdCgroup(path) { - return filepath.Join("/", path), nil + if isCgroupV2 { + return filepath.Join("/", path), nil + } else { + return path, nil + } } if systemdCgroup {