mirror of
https://github.com/containers/podman.git
synced 2025-06-20 17:13:43 +08:00
Merge pull request #2412 from QiWang19/iss2380
Enable specifying directory as device on container with --device
This commit is contained in:
@ -46,19 +46,32 @@ func devicesFromPath(g *generate.Generator, devicePath string) error {
|
|||||||
return errors.Wrapf(err, "cannot stat %s", devicePath)
|
return errors.Wrapf(err, "cannot stat %s", devicePath)
|
||||||
}
|
}
|
||||||
if st.IsDir() {
|
if st.IsDir() {
|
||||||
if len(devs) > 2 {
|
|
||||||
return errors.Wrapf(unix.EINVAL, "not allowed to specify destination with a directory %s", devicePath)
|
|
||||||
}
|
|
||||||
found := false
|
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 {
|
||||||
|
if devmode != "" {
|
||||||
|
return errors.Wrapf(unix.EINVAL, "invalid device specification %s", devicePath)
|
||||||
|
}
|
||||||
|
devmode = devs[2]
|
||||||
|
}
|
||||||
|
|
||||||
// mount the internal devices recursively
|
// mount the internal devices recursively
|
||||||
if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error {
|
if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error {
|
||||||
|
|
||||||
if f.Mode()&os.ModeDevice == os.ModeDevice {
|
if f.Mode()&os.ModeDevice == os.ModeDevice {
|
||||||
found = true
|
found = true
|
||||||
device := dpath
|
device := fmt.Sprintf("%s:%s", dpath, filepath.Join(dest, strings.TrimPrefix(dpath, src)))
|
||||||
|
if devmode != "" {
|
||||||
if len(devs) > 1 {
|
device = fmt.Sprintf("%s:%s", device, devmode)
|
||||||
device = fmt.Sprintf("%s:%s", dpath, devs[1])
|
|
||||||
}
|
}
|
||||||
if err := addDevice(g, device); err != nil {
|
if err := addDevice(g, device); err != nil {
|
||||||
return errors.Wrapf(err, "failed to add %s device", dpath)
|
return errors.Wrapf(err, "failed to add %s device", dpath)
|
||||||
|
@ -72,4 +72,12 @@ var _ = Describe("Podman run device", func() {
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Not(Equal(0)))
|
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))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user