From 776bbbb320392220482f9eef2eaa45c76d593ed7 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 29 Dec 2022 08:58:31 +0000 Subject: [PATCH] fix: tryUnmount with SafeNotMountedBehavior --- staging/src/k8s.io/mount-utils/mount_linux.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/mount-utils/mount_linux.go b/staging/src/k8s.io/mount-utils/mount_linux.go index 9e7faad232b..a7c00ea1b6d 100644 --- a/staging/src/k8s.io/mount-utils/mount_linux.go +++ b/staging/src/k8s.io/mount-utils/mount_linux.go @@ -383,7 +383,7 @@ func (mounter *Mounter) Unmount(target string) error { // UnmountWithForce unmounts given target but will retry unmounting with force option // after given timeout. func (mounter *Mounter) UnmountWithForce(target string, umountTimeout time.Duration) error { - err := tryUnmount(target, umountTimeout) + err := tryUnmount(mounter, target, umountTimeout) if err != nil { if err == context.DeadlineExceeded { klog.V(2).Infof("Timed out waiting for unmount of %s, trying with -f", target) @@ -775,7 +775,7 @@ func (mounter *Mounter) IsMountPoint(file string) (bool, error) { } // tryUnmount calls plain "umount" and waits for unmountTimeout for it to finish. -func tryUnmount(path string, unmountTimeout time.Duration) error { +func tryUnmount(mounter *Mounter, path string, unmountTimeout time.Duration) error { klog.V(4).Infof("Unmounting %s", path) ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout) defer cancel() @@ -790,6 +790,10 @@ func tryUnmount(path string, unmountTimeout time.Duration) error { } if cmderr != nil { + if mounter.withSafeNotMountedBehavior && strings.Contains(string(out), errNotMounted) { + klog.V(4).Infof("ignoring 'not mounted' error for %s", path) + return nil + } return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", cmderr, path, string(out)) } return nil