From 53a723cdcc024fa940b1b7e70a9fa7d55e54c8ae Mon Sep 17 00:00:00 2001 From: Ian Chakeres Date: Sat, 1 Jul 2017 15:51:28 -0500 Subject: [PATCH] Fixes bind-mount teardown failure with non-mount point Local volumes Added IsNotMountPoint method to mount utils (pkg/util/mount/mount.go) Added UnmountMountPoint method to volume utils (pkg/volume/util/util.go) Call UnmountMountPoint method from local storage (pkg/volume/local/local.go) IsLikelyNotMountPoint behavior was not modified, so the logic/behavior for UnmountPath is not modified --- pkg/volume/util/util.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 08f0776..98e436c 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -75,6 +75,15 @@ func SetReady(dir string) { // UnmountPath is a common unmount routine that unmounts the given path and // deletes the remaining directory if successful. func UnmountPath(mountPath string, mounter mount.Interface) error { + return UnmountMountPoint(mountPath, mounter, false /* extensiveMountPointCheck */) +} + +// UnmountMountPoint is a common unmount routine that unmounts the given path and +// deletes the remaining directory if successful. +// if extensiveMountPointCheck is true +// IsNotMountPoint will be called instead of IsLikelyNotMountPoint. +// IsNotMountPoint is more expensive but properly handles bind mounts. +func UnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool) error { if pathExists, pathErr := PathExists(mountPath); pathErr != nil { return fmt.Errorf("Error checking if path exists: %v", pathErr) } else if !pathExists { @@ -82,16 +91,26 @@ func UnmountPath(mountPath string, mounter mount.Interface) error { return nil } - notMnt, err := mounter.IsLikelyNotMountPoint(mountPath) + var notMnt bool + var err error + + if extensiveMountPointCheck { + notMnt, err = mount.IsNotMountPoint(mounter, mountPath) + } else { + notMnt, err = mounter.IsLikelyNotMountPoint(mountPath) + } + if err != nil { return err } + if notMnt { glog.Warningf("Warning: %q is not a mountpoint, deleting", mountPath) return os.Remove(mountPath) } // Unmount the mount path + glog.V(4).Infof("%q is a mountpoint, unmounting", mountPath) if err := mounter.Unmount(mountPath); err != nil { return err }