From 6b44c0debbd43830c19d8e4d81f370a920ee98ed Mon Sep 17 00:00:00 2001 From: Carter McKinnon Date: Tue, 26 Apr 2022 15:21:12 -0700 Subject: [PATCH] Correct detection of 'not mounted' behavior -- umount will exit with a non-zero code. --- staging/src/k8s.io/mount-utils/mount_linux.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/staging/src/k8s.io/mount-utils/mount_linux.go b/staging/src/k8s.io/mount-utils/mount_linux.go index a0def77afd7..0ae9cd4b208 100644 --- a/staging/src/k8s.io/mount-utils/mount_linux.go +++ b/staging/src/k8s.io/mount-utils/mount_linux.go @@ -247,16 +247,14 @@ func detectSafeNotMountedBehavior() bool { cmd := exec.Command("umount", path) output, err := cmd.CombinedOutput() if err != nil { - klog.V(2).Infof("Cannot run umount to detect safe 'not mounted' behavior: %v", err) - klog.V(4).Infof("'umount %s' output: %s, failed with: %v", path, string(output), err) - return false + if strings.Contains(string(output), errNotMounted) { + klog.V(2).Infof("Detected umount with safe 'not mounted' behavior") + return true + } + klog.V(4).Infof("'umount %s' failed with: %v, output: %s", path, err, string(output)) } - if !strings.Contains(string(output), errNotMounted) { - klog.V(2).Infof("Detected umount with unsafe 'not mounted' behavior") - return false - } - klog.V(2).Infof("Detected umount with safe 'not mounted' behavior") - return true + klog.V(2).Infof("Detected umount with unsafe 'not mounted' behavior") + return false } // MakeMountArgs makes the arguments to the mount(8) command.