Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for mount command to finish when mounting volume #4305

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions libpod/volume_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package libpod

import (
"io/ioutil"
"os/exec"
"strings"

"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/rootless"
Expand Down Expand Up @@ -72,16 +72,10 @@ func (v *Volume) mount() error {
mountArgs = append(mountArgs, volDevice, v.config.MountPoint)
mountCmd := exec.Command(mountPath, mountArgs...)

errPipe, err := mountCmd.StderrPipe()
if err != nil {
return errors.Wrapf(err, "error getting stderr pipe for mount")
}
if err := mountCmd.Start(); err != nil {
out, err2 := ioutil.ReadAll(errPipe)
if err2 != nil {
return errors.Wrapf(err2, "error reading mount STDERR")
}
return errors.Wrapf(errors.New(string(out)), "error mounting volume %s", v.Name())
logrus.Debugf("Running mount command: %s %s", mountPath, strings.Join(mountArgs, " "))
if output, err := mountCmd.CombinedOutput(); err != nil {
logrus.Debugf("Mount failed with %v", err)
return errors.Wrapf(errors.Errorf(string(output)), "error mounting volume %s", v.Name())
Copy link
Member

@rhatdan rhatdan Oct 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should wrap the err, and then put the string(output) into the extra information.

 		return errors.Wrapf(err, "error mounting volume %s: %v", v.Name(),errors.Errorf(string(output)))

}

logrus.Debugf("Mounted volume %s", v.Name())
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,15 @@ var _ = Describe("Podman run with volumes", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(Not(ContainSubstring("noexec")))
})

It("podman mount with invalid option fails", func() {
volName := "testVol"
volCreate := podmanTest.Podman([]string{"volume", "create", "--opt", "type=tmpfs", "--opt", "device=tmpfs", "--opt", "o=invalid", volName})
volCreate.WaitWithDefaultTimeout()
Expect(volCreate.ExitCode()).To(Equal(0))

volMount := podmanTest.Podman([]string{"run", "--rm", "-v", fmt.Sprintf("%s:/tmp", volName), ALPINE, "ls"})
volMount.WaitWithDefaultTimeout()
Expect(volMount.ExitCode()).To(Not(Equal(0)))
})
})