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 acbfe6bc56b9357d40a452f6b3901cb2c2d40404)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
diff --git a/pkg/mount/flags_freebsd.go b/pkg/mount/flags_freebsd.go
index f166cb2..5f76f33 100644
--- a/pkg/mount/flags_freebsd.go
+++ b/pkg/mount/flags_freebsd.go
@@ -45,4 +45,5 @@
RELATIME = 0
REMOUNT = 0
STRICTATIME = 0
+ mntDetach = 0
)
diff --git a/pkg/mount/flags_linux.go b/pkg/mount/flags_linux.go
index dc696dc..25f4661 100644
--- a/pkg/mount/flags_linux.go
+++ b/pkg/mount/flags_linux.go
@@ -82,4 +82,6 @@
// 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
)
diff --git a/pkg/mount/flags_unsupported.go b/pkg/mount/flags_unsupported.go
index 5564f7b..9ed741e3 100644
--- a/pkg/mount/flags_unsupported.go
+++ b/pkg/mount/flags_unsupported.go
@@ -27,4 +27,5 @@
STRICTATIME = 0
SYNCHRONOUS = 0
RDONLY = 0
+ mntDetach = 0
)
diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go
index bb4cd88..a57f397 100644
--- a/pkg/mount/mount.go
+++ b/pkg/mount/mount.go
@@ -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 @@
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)
}