diff options
author | Qi Wang <qiwan@redhat.com> | 2019-02-26 11:05:39 -0500 |
---|---|---|
committer | Qi Wang <qiwan@redhat.com> | 2019-03-06 10:14:52 -0500 |
commit | c90e0ea346f8d7b01df4d55c58c4858b8208edf0 (patch) | |
tree | 4492ce39377ef2f10c859179ffa30cbbb36f0619 | |
parent | 7418ff988b520466d04cacf6d88b50d67bfa8ddf (diff) | |
download | podman-c90e0ea346f8d7b01df4d55c58c4858b8208edf0.tar.gz podman-c90e0ea346f8d7b01df4d55c58c4858b8208edf0.tar.bz2 podman-c90e0ea346f8d7b01df4d55c58c4858b8208edf0.zip |
fix bug --device enable specifying directory as device
Signed-off-by: Qi Wang <qiwan@redhat.com>
-rw-r--r-- | pkg/spec/config_linux.go | 25 | ||||
-rw-r--r-- | test/e2e/run_device_test.go | 8 |
2 files changed, 27 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) diff --git a/test/e2e/run_device_test.go b/test/e2e/run_device_test.go index 4f26ac8ee..8734bb71c 100644 --- a/test/e2e/run_device_test.go +++ b/test/e2e/run_device_test.go @@ -72,4 +72,12 @@ var _ = Describe("Podman run device", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Not(Equal(0))) }) + + It("podman run device host device and container device parameter are directories", func() { + SystemExec("mkdir", []string{"/dev/foodevdir"}) + SystemExec("mknod", []string{"/dev/foodevdir/null", "c", "1", "3"}) + session := podmanTest.Podman([]string{"run", "-q", "--device", "/dev/foodevdir:/dev/bar", ALPINE, "ls", "/dev/bar/null"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) }) |