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:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user