Skip to content

Commit

Permalink
Add support for * for device name in --device
Browse files Browse the repository at this point in the history
This takes care of the [issue](docker/cli#2968)
from the server side

Signed-off-by: Venky Natham <[email protected]>
  • Loading branch information
aws-vrnatham committed Dec 9, 2021
1 parent d456264 commit 3b0be33
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions oci/devices_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ func deviceCgroup(d *devices.Device) specs.LinuxDeviceCgroup {
func DevicesFromPath(pathOnHost, pathInContainer, cgroupPermissions string) (devs []specs.LinuxDevice, devPermissions []specs.LinuxDeviceCgroup, err error) {
resolvedPathOnHost := pathOnHost

// Only wildcard * is supported
if strings.HasSuffix(resolvedPathOnHost, "*") {
devicePaths, _ := filepath.Glob(resolvedPathOnHost)
var err error
var dev *devices.Device
for _, devicePath := range devicePaths {
dev, err = devices.DeviceFromPath(devicePath, cgroupPermissions)
if err != nil {
return nil, nil, fmt.Errorf("no device %q %s", devicePath, err)
}
devs = append(devs, Device(dev))
devPermissions = append(devPermissions, deviceCgroup(dev))
}
if len(devs) > 0 {
return devs, devPermissions, nil
} else {
return devs, devPermissions, fmt.Errorf("error gathering device information while adding custom device %q: %s", pathOnHost, err)
}
}

// check if it is a symbolic link
if src, e := os.Lstat(pathOnHost); e == nil && src.Mode()&os.ModeSymlink == os.ModeSymlink {
if linkedPathOnHost, e := filepath.EvalSymlinks(pathOnHost); e == nil {
Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/containerd/containerd/oci/utils_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b0be33

Please sign in to comment.