libpod: Factor out usage of unix.MNT_DETACH from (*Volume).unmount

There is an existing wrapper for unix.Unmount(..., MNT_DETACH) in
util_linux.go but that filters all errors and for volumes, we only want
to filter EINVAL. The existing libpod.Unmount seems to only have one
call site so perhaps these can be merged.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
Doug Rabson
2022-09-20 11:30:12 +01:00
parent 9de2a5ff79
commit abe8dad344
2 changed files with 10 additions and 1 deletions

View File

@ -180,7 +180,7 @@ func (v *Volume) unmount(force bool) error {
}
// Unmount the volume
if err := unix.Unmount(v.config.MountPoint, unix.MNT_DETACH); err != nil {
if err := detachUnmount(v.config.MountPoint); err != nil {
if err == unix.EINVAL {
// Ignore EINVAL - the mount no longer exists.
return nil

View File

@ -0,0 +1,9 @@
package libpod
import (
"golang.org/x/sys/unix"
)
func detachUnmount(mountPoint string) error {
return unix.Unmount(mountPoint, unix.MNT_DETACH)
}