Browse code

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>

Brian Goff authored on 2017/02/28 01:32:49
Showing 4 changed files
... ...
@@ -45,4 +45,5 @@ const (
45 45
 	RELATIME    = 0
46 46
 	REMOUNT     = 0
47 47
 	STRICTATIME = 0
48
+	mntDetach   = 0
48 49
 )
... ...
@@ -82,4 +82,6 @@ const (
82 82
 	// it possible for the kernel to default to relatime or noatime but still
83 83
 	// allow userspace to override it.
84 84
 	STRICTATIME = syscall.MS_STRICTATIME
85
+
86
+	mntDetach = syscall.MNT_DETACH
85 87
 )
... ...
@@ -27,4 +27,5 @@ const (
27 27
 	STRICTATIME = 0
28 28
 	SYNCHRONOUS = 0
29 29
 	RDONLY      = 0
30
+	mntDetach   = 0
30 31
 )
... ...
@@ -1,9 +1,5 @@
1 1
 package mount
2 2
 
3
-import (
4
-	"time"
5
-)
6
-
7 3
 // GetMounts retrieves a list of mounts for the current running process.
8 4
 func GetMounts() ([]*Info, error) {
9 5
 	return parseMountTable()
... ...
@@ -49,23 +45,11 @@ func ForceMount(device, target, mType, options string) error {
49 49
 	return mount(device, target, mType, uintptr(flag), data)
50 50
 }
51 51
 
52
-// Unmount will unmount the target filesystem, so long as it is mounted.
52
+// Unmount lazily unmounts a filesystem on supported platforms, otherwise
53
+// does a normal unmount.
53 54
 func Unmount(target string) error {
54 55
 	if mounted, err := Mounted(target); err != nil || !mounted {
55 56
 		return err
56 57
 	}
57
-	return ForceUnmount(target)
58
-}
59
-
60
-// ForceUnmount will force an unmount of the target filesystem, regardless if
61
-// it is mounted or not.
62
-func ForceUnmount(target string) (err error) {
63
-	// Simple retry logic for unmount
64
-	for i := 0; i < 10; i++ {
65
-		if err = unmount(target, 0); err == nil {
66
-			return nil
67
-		}
68
-		time.Sleep(100 * time.Millisecond)
69
-	}
70
-	return
58
+	return unmount(target, mntDetach)
71 59
 }