diff --git a/pkg/util/mount/nsenter_mount.go b/pkg/util/mount/nsenter_mount.go index 9be0e551d35..a5ccd89929b 100644 --- a/pkg/util/mount/nsenter_mount.go +++ b/pkg/util/mount/nsenter_mount.go @@ -175,8 +175,11 @@ func (n *NsenterMounter) IsLikelyNotMountPoint(file string) (bool, error) { glog.V(5).Infof("findmnt: directory %s does not exist", file) return true, err } - - args := []string{"--mount=/rootfs/proc/1/ns/mnt", "--", n.absHostPath("findmnt"), "-o", "target", "--noheadings", "--target", file} + // Add --first-only option: since we are testing for the absense of a mountpoint, it is sufficient to get only + // the first of multiple possible mountpoints using --first-only. + // Also add fstype output to make sure that the output of target file will give the full path + // TODO: Need more refactoring for this function. Track the solution with issue #26996 + args := []string{"--mount=/rootfs/proc/1/ns/mnt", "--", n.absHostPath("findmnt"), "-o", "target,fstype", "--noheadings", "--first-only", "--target", file} glog.V(5).Infof("findmnt command: %v %v", nsenterPath, args) exec := exec.New() @@ -188,13 +191,15 @@ func (n *NsenterMounter) IsLikelyNotMountPoint(file string) (bool, error) { // It's safer to assume that it's not a mount point. return true, nil } - strOut := strings.TrimSuffix(string(out), "\n") + mountTarget := strings.Split(string(out), " ")[0] + mountTarget = strings.TrimSuffix(mountTarget, "\n") + glog.V(5).Infof("IsLikelyNotMountPoint findmnt output for path %s: %v:", file, mountTarget) - glog.V(5).Infof("IsLikelyNotMountPoint findmnt output for path %s: %v", file, strOut) - if strOut == file { + if mountTarget == file { + glog.V(5).Infof("IsLikelyNotMountPoint: %s is a mount point", file) return false, nil } - + glog.V(5).Infof("IsLikelyNotMountPoint: %s is not a mount point", file) return true, nil }