-
Notifications
You must be signed in to change notification settings - Fork 141
/
linux_resources_devices.go
46 lines (40 loc) · 1.46 KB
/
linux_resources_devices.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package util
import (
"fmt"
"github.com/mndrix/tap-go"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/specerror"
)
// ValidateLinuxResourcesDevices validates linux.resources.devices.
func ValidateLinuxResourcesDevices(config *rspec.Spec, t *tap.T, state *rspec.State) error {
cg, err := cgroups.FindCgroup()
t.Ok((err == nil), "find devices")
if err != nil {
t.Diagnostic(err.Error())
return nil
}
lnd, err := cg.GetDevicesData(state.Pid, config.Linux.CgroupsPath)
t.Ok((err == nil), "get devices data")
if err != nil {
t.Diagnostic(err.Error())
return nil
}
for i, device := range config.Linux.Resources.Devices {
if device.Allow {
found := false
if lnd[i-1].Type == device.Type && *lnd[i-1].Major == *device.Major && *lnd[i-1].Minor == *device.Minor && lnd[i-1].Access == device.Access {
found = true
}
t.Ok(found, fmt.Sprintf("devices %s %d:%d %s is set correctly", device.Type, *device.Major, *device.Minor, device.Access))
t.Diagnosticf("expect: %s %d:%d %s, actual: %s %d:%d %s",
device.Type, *device.Major, *device.Minor, device.Access, lnd[i-1].Type, *lnd[i-1].Major, *lnd[i-1].Minor, lnd[i-1].Access)
if !found {
err := specerror.NewError(specerror.DevicesApplyInOrder, fmt.Errorf("The runtime MUST apply entries in the listed order"), rspec.Version)
t.Diagnostic(err.Error())
return nil
}
}
}
return nil
}