Merge pull request #5845 from alexandref75/fix-dir-device-support

Fix dir support for devices
This commit is contained in:
Phil Estes 2021-08-30 13:59:13 -04:00 committed by GitHub
commit 0d5223d700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 5 deletions

View File

@ -46,13 +46,13 @@ func WithDevices(devicePath, containerPath, permissions string) SpecOpts {
if err != nil {
return err
}
for _, dev := range devs {
s.Linux.Devices = append(s.Linux.Devices, dev)
for i := range devs {
s.Linux.Devices = append(s.Linux.Devices, devs[i])
s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, specs.LinuxDeviceCgroup{
Allow: true,
Type: dev.Type,
Major: &dev.Major,
Minor: &dev.Minor,
Type: devs[i].Type,
Major: &devs[i].Major,
Minor: &devs[i].Minor,
Access: permissions,
})
}

View File

@ -160,6 +160,37 @@ func TestGetDevices(t *testing.T) {
}
})
})
t.Run("two devices", func(t *testing.T) {
nullDev := filepath.Join(dir, "null")
if err := ioutil.WriteFile(nullDev, nil, 0600); err != nil {
t.Fatal(err)
}
if err := unix.Mount("/dev/null", nullDev, "", unix.MS_BIND, ""); err != nil {
t.Fatal(err)
}
defer unix.Unmount(filepath.Join(dir, "null"), unix.MNT_DETACH)
devices, err := getDevices(dir, "")
if err != nil {
t.Fatal(err)
}
if len(devices) != 2 {
t.Fatalf("expected two devices %v", devices)
}
if devices[0].Path == devices[1].Path {
t.Fatalf("got same path for the two devices %s", devices[0].Path)
}
if devices[0].Path != zero && devices[0].Path != nullDev {
t.Fatalf("got unexpected device path %s", devices[0].Path)
}
if devices[1].Path != zero && devices[1].Path != nullDev {
t.Fatalf("got unexpected device path %s", devices[1].Path)
}
if devices[0].Major == devices[1].Major && devices[0].Minor == devices[1].Minor {
t.Fatalf("got sema mojor and minor on two devices %s %s", devices[0].Path, devices[1].Path)
}
})
t.Run("With symlink in dir", func(t *testing.T) {
if err := os.Symlink("/dev/zero", filepath.Join(dir, "zerosym")); err != nil {
t.Fatal(err)