Skip to content

Commit

Permalink
Merge pull request kubernetes#81730 from codenrhoden/mountpoint-match
Browse files Browse the repository at this point in the history
Internalize mount.Interface.IsMountPointMatch
  • Loading branch information
k8s-ci-robot authored Aug 27, 2019
2 parents ee73d27 + a30ba61 commit f789e1e
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 33 deletions.
5 changes: 0 additions & 5 deletions pkg/util/mount/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions pkg/util/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/util/mount/mount_helper_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
5 changes: 5 additions & 0 deletions pkg/util/mount/mount_helper_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions pkg/util/mount/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions pkg/util/mount/mount_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions pkg/util/mount/mount_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions pkg/volume/util/exec/exec_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions pkg/volume/util/exec/exec_mount_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f789e1e

Please sign in to comment.