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>
Upstream-commit: a1d095199ddb9b4811e1417b6adcdfadad7d73f4
Component: engine
This commit is contained in:
Kir Kolyshkin
2018-01-19 13:09:11 -08:00
parent 96e23c4152
commit f00e9a9036

View File

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