mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 07:22:20 +00:00
resourcecontrol: SystemdCgroup check is not necessarily linux specific
This utility function is also used to check the spec that will run in the guest - no need for this to be linux specific. Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
cc58cf6993
commit
6a5c634490
@ -7,6 +7,7 @@ package resourcecontrol
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/devices"
|
"github.com/opencontainers/runc/libcontainer/devices"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
@ -57,3 +58,20 @@ func DeviceToLinuxDevice(device string) (specs.LinuxDeviceCgroup, error) {
|
|||||||
Access: string(dev.Permissions),
|
Access: string(dev.Permissions),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsSystemdCgroup(cgroupPath string) bool {
|
||||||
|
|
||||||
|
// If we are utilizing systemd to manage cgroups, we expect to receive a path
|
||||||
|
// in the format slice:scopeprefix:name. A typical example would be:
|
||||||
|
//
|
||||||
|
// system.slice:docker:6b4c4a4d0cc2a12c529dcb13a2b8e438dfb3b2a6af34d548d7d
|
||||||
|
//
|
||||||
|
// Based on this, let's split by the ':' delimiter and verify that the first
|
||||||
|
// section has .slice as a suffix.
|
||||||
|
parts := strings.Split(cgroupPath, ":")
|
||||||
|
if len(parts) == 3 && strings.HasSuffix(parts[0], ".slice") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -43,23 +43,6 @@ func ValidCgroupPath(path string, systemdCgroup bool) (string, error) {
|
|||||||
return filepath.Join(DefaultResourceControllerID, filepath.Clean("/"+path)), nil
|
return filepath.Join(DefaultResourceControllerID, filepath.Clean("/"+path)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsSystemdCgroup(cgroupPath string) bool {
|
|
||||||
|
|
||||||
// If we are utilizing systemd to manage cgroups, we expect to receive a path
|
|
||||||
// in the format slice:scopeprefix:name. A typical example would be:
|
|
||||||
//
|
|
||||||
// system.slice:docker:6b4c4a4d0cc2a12c529dcb13a2b8e438dfb3b2a6af34d548d7d
|
|
||||||
//
|
|
||||||
// Based on this, let's split by the ':' delimiter and verify that the first
|
|
||||||
// section has .slice as a suffix.
|
|
||||||
parts := strings.Split(cgroupPath, ":")
|
|
||||||
if len(parts) == 3 && strings.HasSuffix(parts[0], ".slice") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func newProperty(name string, units interface{}) systemdDbus.Property {
|
func newProperty(name string, units interface{}) systemdDbus.Property {
|
||||||
return systemdDbus.Property{
|
return systemdDbus.Property{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
Loading…
Reference in New Issue
Block a user