浏览代码

Merge pull request #31391 from cpuguy83/fix_volume_unmount_disconnected_fs

Use lazy unmount for local volume driver unmount
Brian Goff 8 年之前
父节点
当前提交
ccc1324b59
共有 4 个文件被更改,包括 7 次插入19 次删除
  1. 1 0
      pkg/mount/flags_freebsd.go
  2. 2 0
      pkg/mount/flags_linux.go
  3. 1 0
      pkg/mount/flags_unsupported.go
  4. 3 19
      pkg/mount/mount.go

+ 1 - 0
pkg/mount/flags_freebsd.go

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

+ 2 - 0
pkg/mount/flags_linux.go

@@ -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
 )

+ 1 - 0
pkg/mount/flags_unsupported.go

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

+ 3 - 19
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 @@ 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)
 }