diff --git a/pkg/util/mount/fake.go b/pkg/util/mount/fake.go index 5aa34a399e6..66b877064d0 100644 --- a/pkg/util/mount/fake.go +++ b/pkg/util/mount/fake.go @@ -137,11 +137,6 @@ func (f *FakeMounter) List() ([]MountPoint, error) { return f.MountPoints, nil } -// IsMountPointMatch tests if dir and mp are the same path -func (f *FakeMounter) IsMountPointMatch(mp MountPoint, dir string) bool { - return mp.Path == dir -} - // IsLikelyNotMountPoint determines whether a path is a mountpoint by checking // if the absolute path to file is in the in-memory mountpoints func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index c303e129d02..72650884fb5 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -41,8 +41,6 @@ type Interface interface { // consistent (i.e. it could change between chunked reads). This is guaranteed // to be consistent. List() ([]MountPoint, error) - // IsMountPointMatch determines if the mountpoint matches the dir. - IsMountPointMatch(mp MountPoint, dir string) bool // IsLikelyNotMountPoint uses heuristics to determine if a directory // is not a mountpoint. // It should return ErrNotExist when the directory does not exist. @@ -162,7 +160,7 @@ func GetDeviceNameFromMount(mounter Interface, mountPath string) (string, int, e // IsNotMountPoint detects bind mounts in linux. // IsNotMountPoint enumerates all the mountpoints using List() and // the list of mountpoints may be large, then it uses -// IsMountPointMatch to evaluate whether the directory is a mountpoint. +// isMountPointMatch to evaluate whether the directory is a mountpoint. func IsNotMountPoint(mounter Interface, file string) (bool, error) { // IsLikelyNotMountPoint provides a quick check // to determine whether file IS A mountpoint. @@ -195,7 +193,7 @@ func IsNotMountPoint(mounter Interface, file string) (bool, error) { return notMnt, mountPointsErr } for _, mp := range mountPoints { - if mounter.IsMountPointMatch(mp, resolvedFile) { + if isMountPointMatch(mp, resolvedFile) { notMnt = false break } diff --git a/pkg/util/mount/mount_helper_unix.go b/pkg/util/mount/mount_helper_unix.go index 440576322b3..b0602bc08c3 100644 --- a/pkg/util/mount/mount_helper_unix.go +++ b/pkg/util/mount/mount_helper_unix.go @@ -131,3 +131,10 @@ func parseMountInfo(filename string) ([]mountInfo, error) { } return infos, nil } + +// isMountPointMatch returns true if the path in mp is the same as dir. +// Handles case where mountpoint dir has been renamed due to stale NFS mount. +func isMountPointMatch(mp MountPoint, dir string) bool { + deletedDir := fmt.Sprintf("%s\\040(deleted)", dir) + return ((mp.Path == dir) || (mp.Path == deletedDir)) +} diff --git a/pkg/util/mount/mount_helper_windows.go b/pkg/util/mount/mount_helper_windows.go index 69ab3deaeb6..5e6b1dd9adc 100644 --- a/pkg/util/mount/mount_helper_windows.go +++ b/pkg/util/mount/mount_helper_windows.go @@ -91,3 +91,8 @@ func ValidateDiskNumber(disk string) error { return nil } + +// isMountPointMatch determines if the mountpoint matches the dir +func isMountPointMatch(mp MountPoint, dir string) bool { + return mp.Path == dir +} diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index 792ac43d8f2..fe762e347b6 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -213,12 +213,6 @@ func (*Mounter) List() ([]MountPoint, error) { return ListProcMounts(procMountsPath) } -// IsMountPointMatch returns true if the path in mp is the same as dir -func (mounter *Mounter) IsMountPointMatch(mp MountPoint, dir string) bool { - deletedDir := fmt.Sprintf("%s\\040(deleted)", dir) - return ((mp.Path == dir) || (mp.Path == deletedDir)) -} - // IsLikelyNotMountPoint determines if a directory is not a mountpoint. // It is fast but not necessarily ALWAYS correct. If the path is in fact // a bind mount from one part of a mount to another it will not be detected. diff --git a/pkg/util/mount/mount_unsupported.go b/pkg/util/mount/mount_unsupported.go index 1e2aed63aa2..5a1d107abd9 100644 --- a/pkg/util/mount/mount_unsupported.go +++ b/pkg/util/mount/mount_unsupported.go @@ -53,11 +53,6 @@ func (mounter *Mounter) List() ([]MountPoint, error) { return []MountPoint{}, errUnsupported } -// IsMountPointMatch returns true if the path in mp is the same as dir -func (mounter *Mounter) IsMountPointMatch(mp MountPoint, dir string) bool { - return (mp.Path == dir) -} - // IsLikelyNotMountPoint always returns an error on unsupported platforms func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, errUnsupported diff --git a/pkg/util/mount/mount_windows.go b/pkg/util/mount/mount_windows.go index 4d6600280f0..9176a066528 100644 --- a/pkg/util/mount/mount_windows.go +++ b/pkg/util/mount/mount_windows.go @@ -164,11 +164,6 @@ func (mounter *Mounter) List() ([]MountPoint, error) { return []MountPoint{}, nil } -// IsMountPointMatch determines if the mountpoint matches the dir -func (mounter *Mounter) IsMountPointMatch(mp MountPoint, dir string) bool { - return mp.Path == dir -} - // IsLikelyNotMountPoint determines if a directory is not a mountpoint. func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) { stat, err := os.Lstat(file) diff --git a/pkg/volume/util/exec/exec_mount.go b/pkg/volume/util/exec/exec_mount.go index b8d3c1dc7f6..1732f424c44 100644 --- a/pkg/volume/util/exec/exec_mount.go +++ b/pkg/volume/util/exec/exec_mount.go @@ -91,10 +91,6 @@ func (m *execMounter) List() ([]mount.MountPoint, error) { return m.wrappedMounter.List() } -func (m *execMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool { - return m.wrappedMounter.IsMountPointMatch(mp, dir) -} - // IsLikelyNotMountPoint determines whether a path is a mountpoint. func (m *execMounter) IsLikelyNotMountPoint(file string) (bool, error) { return m.wrappedMounter.IsLikelyNotMountPoint(file) diff --git a/pkg/volume/util/exec/exec_mount_unsupported.go b/pkg/volume/util/exec/exec_mount_unsupported.go index 37ca41c3ef7..1c4f8ecf38c 100644 --- a/pkg/volume/util/exec/exec_mount_unsupported.go +++ b/pkg/volume/util/exec/exec_mount_unsupported.go @@ -46,10 +46,6 @@ func (mounter *execMounter) List() ([]mount.MountPoint, error) { return []mount.MountPoint{}, nil } -func (mounter *execMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool { - return (mp.Path == dir) -} - func (mounter *execMounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, nil }