From cafd126ecdc6f7b5b17878d76fc6ef47e30313ee Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Fri, 19 Aug 2016 15:24:18 -0700 Subject: [PATCH] Add ismounted check in unmountpath function This change is for fixing PR #30930. The function should check if the mountpath is still mounted or not. If it is not, it should continue with removing the directory instead of returning error. --- pkg/volume/util/util.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 9d92bd0f3b4..9859506a14a 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -73,14 +73,28 @@ func UnmountPath(mountPath string, mounter mount.Interface) error { return nil } - err := mounter.Unmount(mountPath) - if err == nil { - // Only delete directory on successful unmount - glog.V(5).Infof("Unmounted %q. Deleting path.", mountPath) + 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) } - return err + // Unmount the mount path + if err := mounter.Unmount(mountPath); err != nil { + return err + } + notMnt, mntErr := mounter.IsLikelyNotMountPoint(mountPath) + if mntErr != nil { + return err + } + if notMnt { + glog.V(4).Info("%q is unmounted, deleting the directory", mountPath) + return os.Remove(mountPath) + } + return nil } // PathExists returns true if the specified path exists.