Browse Source

mount.Unmount(): don't look into /proc/self/mountinfo

Now, every Unmount() call takes a burden to parse the whole nine yards
of /proc/self/mountinfo to figure out whether the given mount point is
mounted or not (and returns an error in case parsing fails somehow).

Instead, let's just call umount() and ignore EINVAL, which results
in the same behavior, but much better performance.

Note that EINVAL is returned from umount(2) not only in the case when
`target` is not mounted, but also for invalid flags. As the flags are
hardcoded here, it can't be the case.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Kir Kolyshkin 7 năm trước cách đây
mục cha
commit
a1d095199d
1 tập tin đã thay đổi với 5 bổ sung4 xóa
  1. 5 4
      pkg/mount/mount.go

+ 5 - 4
pkg/mount/mount.go

@@ -3,7 +3,6 @@ package mount // import "github.com/docker/docker/pkg/mount"
 import (
 import (
 	"sort"
 	"sort"
 	"strings"
 	"strings"
-
 	"syscall"
 	"syscall"
 
 
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
@@ -90,10 +89,12 @@ func ForceMount(device, target, mType, options string) error {
 // Unmount lazily unmounts a filesystem on supported platforms, otherwise
 // Unmount lazily unmounts a filesystem on supported platforms, otherwise
 // does a normal unmount.
 // does a normal unmount.
 func Unmount(target string) error {
 func Unmount(target string) error {
-	if mounted, err := Mounted(target); err != nil || !mounted {
-		return err
+	err := unmount(target, mntDetach)
+	if err == syscall.EINVAL {
+		// ignore "not mounted" error
+		err = nil
 	}
 	}
-	return unmount(target, mntDetach)
+	return err
 }
 }
 
 
 // RecursiveUnmount unmounts the target and all mounts underneath, starting with
 // RecursiveUnmount unmounts the target and all mounts underneath, starting with