1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use lazy unmount for local volume driver unmount

This fixes issues where the underlying filesystem may be disconnected and
attempting to unmount may cause a hang.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit acbfe6bc56)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
Brian Goff 2017-02-27 11:32:49 -05:00 committed by Victor Vieux
parent 90d35abf7b
commit c4bd13b650
4 changed files with 7 additions and 19 deletions

View file

@ -45,4 +45,5 @@ const (
RELATIME = 0
REMOUNT = 0
STRICTATIME = 0
mntDetach = 0
)

View file

@ -82,4 +82,6 @@ const (
// it possible for the kernel to default to relatime or noatime but still
// allow userspace to override it.
STRICTATIME = syscall.MS_STRICTATIME
mntDetach = syscall.MNT_DETACH
)

View file

@ -27,4 +27,5 @@ const (
STRICTATIME = 0
SYNCHRONOUS = 0
RDONLY = 0
mntDetach = 0
)

View file

@ -1,9 +1,5 @@
package mount
import (
"time"
)
// GetMounts retrieves a list of mounts for the current running process.
func GetMounts() ([]*Info, error) {
return parseMountTable()
@ -49,23 +45,11 @@ func ForceMount(device, target, mType, options string) error {
return mount(device, target, mType, uintptr(flag), data)
}
// Unmount will unmount the target filesystem, so long as it is mounted.
// Unmount lazily unmounts a filesystem on supported platforms, otherwise
// does a normal unmount.
func Unmount(target string) error {
if mounted, err := Mounted(target); err != nil || !mounted {
return err
}
return ForceUnmount(target)
}
// ForceUnmount will force an unmount of the target filesystem, regardless if
// it is mounted or not.
func ForceUnmount(target string) (err error) {
// Simple retry logic for unmount
for i := 0; i < 10; i++ {
if err = unmount(target, 0); err == nil {
return nil
}
time.Sleep(100 * time.Millisecond)
}
return
return unmount(target, mntDetach)
}