Skip to content

Commit 36d09a4

Browse files
authored
Merge pull request #5941 from alexandref75/release/1.5
[release/1.5] Fix dir support for devices
2 parents f40ee07 + c7ed09d commit 36d09a4

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

oci/spec_opts_linux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ func WithDevices(devicePath, containerPath, permissions string) SpecOpts {
4848
if err != nil {
4949
return err
5050
}
51-
for _, dev := range devs {
52-
s.Linux.Devices = append(s.Linux.Devices, dev)
51+
for i := range devs {
52+
s.Linux.Devices = append(s.Linux.Devices, devs[i])
5353
s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, specs.LinuxDeviceCgroup{
5454
Allow: true,
55-
Type: dev.Type,
56-
Major: &dev.Major,
57-
Minor: &dev.Minor,
55+
Type: devs[i].Type,
56+
Major: &devs[i].Major,
57+
Minor: &devs[i].Minor,
5858
Access: permissions,
5959
})
6060
}

oci/spec_opts_linux_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,37 @@ func TestGetDevices(t *testing.T) {
160160
}
161161
})
162162
})
163+
t.Run("two devices", func(t *testing.T) {
164+
nullDev := filepath.Join(dir, "null")
165+
if err := ioutil.WriteFile(nullDev, nil, 0600); err != nil {
166+
t.Fatal(err)
167+
}
168+
169+
if err := unix.Mount("/dev/null", nullDev, "", unix.MS_BIND, ""); err != nil {
170+
t.Fatal(err)
171+
}
172+
defer unix.Unmount(filepath.Join(dir, "null"), unix.MNT_DETACH)
173+
devices, err := getDevices(dir, "")
174+
if err != nil {
175+
t.Fatal(err)
176+
}
177+
178+
if len(devices) != 2 {
179+
t.Fatalf("expected two devices %v", devices)
180+
}
181+
if devices[0].Path == devices[1].Path {
182+
t.Fatalf("got same path for the two devices %s", devices[0].Path)
183+
}
184+
if devices[0].Path != zero && devices[0].Path != nullDev {
185+
t.Fatalf("got unexpected device path %s", devices[0].Path)
186+
}
187+
if devices[1].Path != zero && devices[1].Path != nullDev {
188+
t.Fatalf("got unexpected device path %s", devices[1].Path)
189+
}
190+
if devices[0].Major == devices[1].Major && devices[0].Minor == devices[1].Minor {
191+
t.Fatalf("got sema mojor and minor on two devices %s %s", devices[0].Path, devices[1].Path)
192+
}
193+
})
163194
t.Run("With symlink in dir", func(t *testing.T) {
164195
if err := os.Symlink("/dev/zero", filepath.Join(dir, "zerosym")); err != nil {
165196
t.Fatal(err)

0 commit comments

Comments
 (0)