diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-06 10:59:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-06 10:59:56 -0800 |
commit | f50715ed25fd1bc58dad39982a2a5b5837dcd8ef (patch) | |
tree | 123b60e06eb870eb4a4019f4b854fc6b278a6a24 /pkg/spec/config_linux.go | |
parent | fb14db49fed07b934d5e71e642d8e1d31194568b (diff) | |
parent | c90e0ea346f8d7b01df4d55c58c4858b8208edf0 (diff) | |
download | podman-f50715ed25fd1bc58dad39982a2a5b5837dcd8ef.tar.gz podman-f50715ed25fd1bc58dad39982a2a5b5837dcd8ef.tar.bz2 podman-f50715ed25fd1bc58dad39982a2a5b5837dcd8ef.zip |
Merge pull request #2412 from QiWang19/iss2380
Enable specifying directory as device on container with --device
Diffstat (limited to 'pkg/spec/config_linux.go')
-rw-r--r-- | pkg/spec/config_linux.go | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/pkg/spec/config_linux.go b/pkg/spec/config_linux.go index eccd41ff9..a1873086e 100644 --- a/pkg/spec/config_linux.go +++ b/pkg/spec/config_linux.go @@ -46,19 +46,32 @@ func devicesFromPath(g *generate.Generator, devicePath string) error { return errors.Wrapf(err, "cannot stat %s", devicePath) } if st.IsDir() { + found := false + src := resolvedDevicePath + dest := src + var devmode string + if len(devs) > 1 { + if len(devs[1]) > 0 && devs[1][0] == '/' { + dest = devs[1] + } else { + devmode = devs[1] + } + } if len(devs) > 2 { - return errors.Wrapf(unix.EINVAL, "not allowed to specify destination with a directory %s", devicePath) + if devmode != "" { + return errors.Wrapf(unix.EINVAL, "invalid device specification %s", devicePath) + } + devmode = devs[2] } - found := false + // mount the internal devices recursively if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error { if f.Mode()&os.ModeDevice == os.ModeDevice { found = true - device := dpath - - if len(devs) > 1 { - device = fmt.Sprintf("%s:%s", dpath, devs[1]) + device := fmt.Sprintf("%s:%s", dpath, filepath.Join(dest, strings.TrimPrefix(dpath, src))) + if devmode != "" { + device = fmt.Sprintf("%s:%s", device, devmode) } if err := addDevice(g, device); err != nil { return errors.Wrapf(err, "failed to add %s device", dpath) |