From 5bf970f84863a70f726086a9e9a83d2eb05576ab Mon Sep 17 00:00:00 2001 From: David Zhu Date: Tue, 26 Feb 2019 13:38:56 -0800 Subject: [PATCH] GetMountRefs fixed to handle corrupted mounts by treating it like an unmounted volume --- pkg/util/mount/mount_helper.go | 2 +- pkg/util/mount/mount_linux.go | 10 +++++++--- pkg/util/mount/mount_windows.go | 10 +++++++--- pkg/util/mount/nsenter_mount.go | 9 ++++----- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/util/mount/mount_helper.go b/pkg/util/mount/mount_helper.go index 0d4acaae44..9984705183 100644 --- a/pkg/util/mount/mount_helper.go +++ b/pkg/util/mount/mount_helper.go @@ -120,5 +120,5 @@ func IsCorruptedMnt(err error) bool { underlyingError = pe.Err } - return underlyingError == syscall.ENOTCONN || underlyingError == syscall.ESTALE || underlyingError == syscall.EIO + return underlyingError == syscall.ENOTCONN || underlyingError == syscall.ESTALE || underlyingError == syscall.EIO || underlyingError == syscall.EACCES } diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index c66039e5e0..be3d152d36 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -1003,10 +1003,14 @@ func (mounter *Mounter) SafeMakeDir(subdir string, base string, perm os.FileMode } func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) { - if _, err := os.Stat(pathname); os.IsNotExist(err) { + pathExists, pathErr := PathExists(pathname) + if !pathExists { return []string{}, nil - } else if err != nil { - return nil, err + } else if IsCorruptedMnt(pathErr) { + klog.Warningf("GetMountRefs found corrupted mount at %s, treating as unmounted path", pathname) + return []string{}, nil + } else if pathErr != nil { + return nil, fmt.Errorf("error checking path %s: %v", pathname, pathErr) } realpath, err := filepath.EvalSymlinks(pathname) if err != nil { diff --git a/pkg/util/mount/mount_windows.go b/pkg/util/mount/mount_windows.go index 917d0ce511..a560aa5c17 100644 --- a/pkg/util/mount/mount_windows.go +++ b/pkg/util/mount/mount_windows.go @@ -496,10 +496,14 @@ func getAllParentLinks(path string) ([]string, error) { // GetMountRefs : empty implementation here since there is no place to query all mount points on Windows func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) { - if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) { + pathExists, pathErr := PathExists(normalizeWindowsPath(pathname)) + // TODO(#75012): Need a Windows specific IsCorruptedMnt function that checks against whatever errno's + // Windows emits when we try to Stat a corrupted mount + // https://golang.org/pkg/syscall/?GOOS=windows&GOARCH=amd64#Errno + if !pathExists { return []string{}, nil - } else if err != nil { - return nil, err + } else if pathErr != nil { + return nil, fmt.Errorf("error checking path %s: %v", normalizeWindowsPath(pathname), pathErr) } return []string{pathname}, nil } diff --git a/pkg/util/mount/nsenter_mount.go b/pkg/util/mount/nsenter_mount.go index ce5d825da7..c7051dd54f 100644 --- a/pkg/util/mount/nsenter_mount.go +++ b/pkg/util/mount/nsenter_mount.go @@ -344,12 +344,11 @@ func (mounter *NsenterMounter) SafeMakeDir(subdir string, base string, perm os.F } func (mounter *NsenterMounter) GetMountRefs(pathname string) ([]string, error) { - exists, err := mounter.ExistsPath(pathname) - if err != nil { - return nil, err - } - if !exists { + pathExists, pathErr := PathExists(pathname) + if !pathExists || IsCorruptedMnt(pathErr) { return []string{}, nil + } else if pathErr != nil { + return nil, fmt.Errorf("Error checking path %s: %v", pathname, pathErr) } hostpath, err := mounter.ne.EvalSymlinks(pathname, true /* mustExist */) if err != nil {