From 95852d7b8ec6bff61f6bad456ba4a0e9ad4356e1 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Mon, 14 Dec 2020 21:51:33 -0500 Subject: [PATCH] Only skip unmount if path does not exist and there is no error --- .../k8s.io/mount-utils/mount_helper_common.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/staging/src/k8s.io/mount-utils/mount_helper_common.go b/staging/src/k8s.io/mount-utils/mount_helper_common.go index 5691edeabce..a7987485562 100644 --- a/staging/src/k8s.io/mount-utils/mount_helper_common.go +++ b/staging/src/k8s.io/mount-utils/mount_helper_common.go @@ -30,7 +30,7 @@ import ( // but properly handles bind mounts within the same fs. func CleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool) error { pathExists, pathErr := PathExists(mountPath) - if !pathExists { + if !pathExists && pathErr == nil { klog.Warningf("Warning: Unmount skipped because path does not exist: %v", mountPath) return nil } @@ -43,7 +43,7 @@ func CleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointC func CleanupMountWithForce(mountPath string, mounter MounterForceUnmounter, extensiveMountPointCheck bool, umountTimeout time.Duration) error { pathExists, pathErr := PathExists(mountPath) - if !pathExists { + if !pathExists && pathErr == nil { klog.Warningf("Warning: Unmount skipped because path does not exist: %v", mountPath) return nil } @@ -54,8 +54,10 @@ func CleanupMountWithForce(mountPath string, mounter MounterForceUnmounter, exte var notMnt bool var err error if !corruptedMnt { - _, err = removePathIfNotMountPoint(mountPath, mounter, extensiveMountPointCheck) - if err != nil { + notMnt, err = removePathIfNotMountPoint(mountPath, mounter, extensiveMountPointCheck) + // if mountPath was not a mount point - we would have attempted to remove mountPath + // and hence return errors if any. + if err != nil || notMnt { return err } } @@ -85,8 +87,10 @@ func doCleanupMountPoint(mountPath string, mounter Interface, extensiveMountPoin var notMnt bool var err error if !corruptedMnt { - _, err = removePathIfNotMountPoint(mountPath, mounter, extensiveMountPointCheck) - if err != nil { + notMnt, err = removePathIfNotMountPoint(mountPath, mounter, extensiveMountPointCheck) + // if mountPath was not a mount point - we would have attempted to remove mountPath + // and hence return errors if any. + if err != nil || notMnt { return err } }