From a1d095199ddb9b4811e1417b6adcdfadad7d73f4 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 19 Jan 2018 13:09:11 -0800 Subject: [PATCH] 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 --- pkg/mount/mount.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index c440b81ce9..874aff6545 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -3,7 +3,6 @@ package mount // import "github.com/docker/docker/pkg/mount" import ( "sort" "strings" - "syscall" "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 // does a normal unmount. 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