mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 14:32:33 +00:00
runtime: merged ValidCgroupPath method
Merged ValidCgroupPath method to handle cgroupv1 and cgroupv2. Fixes: #8930 Signed-off-by: yaoyinnan <35447132+yaoyinnan@users.noreply.github.com>
This commit is contained in:
parent
bf54a02e16
commit
feed5c8ff9
@ -136,7 +136,7 @@ func NewResourceController(path string, resources *specs.LinuxResources) (Resour
|
|||||||
var cgroupPath string
|
var cgroupPath string
|
||||||
|
|
||||||
if cgroups.Mode() == cgroups.Legacy || cgroups.Mode() == cgroups.Hybrid {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ func NewResourceController(path string, resources *specs.LinuxResources) (Resour
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if cgroups.Mode() == cgroups.Unified {
|
} else if cgroups.Mode() == cgroups.Unified {
|
||||||
cgroupPath, err = ValidCgroupPathV2(path, IsSystemdCgroup(path))
|
cgroupPath, err = ValidCgroupPath(path, true, IsSystemdCgroup(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -21,35 +21,15 @@ import (
|
|||||||
// DefaultResourceControllerID runtime-determined location in the cgroups hierarchy.
|
// DefaultResourceControllerID runtime-determined location in the cgroups hierarchy.
|
||||||
const DefaultResourceControllerID = "/vc"
|
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
|
// 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) {
|
if IsSystemdCgroup(path) {
|
||||||
|
if isCgroupV2 {
|
||||||
|
return filepath.Join("/", path), nil
|
||||||
|
} else {
|
||||||
return path, nil
|
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 systemdCgroup {
|
if systemdCgroup {
|
||||||
|
Loading…
Reference in New Issue
Block a user