mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 15:32:30 +00:00
Merge pull request #2695 from YchauWang/wyc-vc-cgroup
runtime: clear virtcontainers cgroup duplicated function
This commit is contained in:
commit
39df808f6a
@ -13,8 +13,6 @@ import (
|
||||
v1 "github.com/containerd/cgroups/stats/v1"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type Cgroup struct {
|
||||
@ -37,33 +35,6 @@ func SetLogger(logger *logrus.Entry) {
|
||||
cgroupsLogger = logger.WithFields(fields)
|
||||
}
|
||||
|
||||
func deviceToDeviceCgroup(device string) (*specs.LinuxDeviceCgroup, error) {
|
||||
var st unix.Stat_t
|
||||
|
||||
if err := unix.Stat(device, &st); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
devType := ""
|
||||
switch st.Mode & unix.S_IFMT {
|
||||
case unix.S_IFCHR:
|
||||
devType = "c"
|
||||
case unix.S_IFBLK:
|
||||
devType = "b"
|
||||
}
|
||||
|
||||
major := int64(unix.Major(st.Rdev))
|
||||
minor := int64(unix.Minor(st.Rdev))
|
||||
|
||||
return &specs.LinuxDeviceCgroup{
|
||||
Allow: true,
|
||||
Type: devType,
|
||||
Major: &major,
|
||||
Minor: &minor,
|
||||
Access: "rwm",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func sandboxDevices() []specs.LinuxDeviceCgroup {
|
||||
devices := []specs.LinuxDeviceCgroup{}
|
||||
|
||||
@ -90,12 +61,12 @@ func sandboxDevices() []specs.LinuxDeviceCgroup {
|
||||
defaultDevices = append(defaultDevices, hypervisorDevices...)
|
||||
|
||||
for _, device := range defaultDevices {
|
||||
ldevice, err := deviceToDeviceCgroup(device)
|
||||
ldevice, err := DeviceToLinuxDevice(device)
|
||||
if err != nil {
|
||||
cgroupsLogger.WithField("source", "cgroups").Warnf("Could not add %s to the devices cgroup", device)
|
||||
continue
|
||||
}
|
||||
devices = append(devices, *ldevice)
|
||||
devices = append(devices, ldevice)
|
||||
}
|
||||
|
||||
wildcardMajor := int64(-1)
|
||||
|
Loading…
Reference in New Issue
Block a user