mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-30 08:52:39 +00:00 
			
		
		
		
	runtime: clear virtcontainers cgroup duplicated function
There are `DeviceToDeviceCgroup` and `deviceToDeviceCgroup` two functions, creating a `specs.LinuxDeviceCgroup` object. We clear the new function `deviceToDeviceCgroup`. Fixes: #2694 Signed-off-by: wangyongchao.bj <wangyongchao.bj@inspur.com>
This commit is contained in:
		| @@ -13,8 +13,6 @@ import ( | |||||||
| 	v1 "github.com/containerd/cgroups/stats/v1" | 	v1 "github.com/containerd/cgroups/stats/v1" | ||||||
| 	"github.com/opencontainers/runtime-spec/specs-go" | 	"github.com/opencontainers/runtime-spec/specs-go" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
| 	"golang.org/x/sys/unix" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Cgroup struct { | type Cgroup struct { | ||||||
| @@ -37,33 +35,6 @@ func SetLogger(logger *logrus.Entry) { | |||||||
| 	cgroupsLogger = logger.WithFields(fields) | 	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 { | func sandboxDevices() []specs.LinuxDeviceCgroup { | ||||||
| 	devices := []specs.LinuxDeviceCgroup{} | 	devices := []specs.LinuxDeviceCgroup{} | ||||||
|  |  | ||||||
| @@ -90,12 +61,12 @@ func sandboxDevices() []specs.LinuxDeviceCgroup { | |||||||
| 	defaultDevices = append(defaultDevices, hypervisorDevices...) | 	defaultDevices = append(defaultDevices, hypervisorDevices...) | ||||||
|  |  | ||||||
| 	for _, device := range defaultDevices { | 	for _, device := range defaultDevices { | ||||||
| 		ldevice, err := deviceToDeviceCgroup(device) | 		ldevice, err := DeviceToLinuxDevice(device) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			cgroupsLogger.WithField("source", "cgroups").Warnf("Could not add %s to the devices cgroup", device) | 			cgroupsLogger.WithField("source", "cgroups").Warnf("Could not add %s to the devices cgroup", device) | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		devices = append(devices, *ldevice) | 		devices = append(devices, ldevice) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	wildcardMajor := int64(-1) | 	wildcardMajor := int64(-1) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user