diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index 79f3f6ec245..8f0489a3c3e 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -34,6 +34,7 @@ type Interface interface { // consistent. List() ([]MountPoint, error) // IsLikelyNotMountPoint determines if a directory is a mountpoint. + // It should return ErrNotExist when the directory does not exist. IsLikelyNotMountPoint(file string) (bool, error) } diff --git a/pkg/util/mount/nsenter_mount.go b/pkg/util/mount/nsenter_mount.go index 7c4ed261c80..0e8a7dcc043 100644 --- a/pkg/util/mount/nsenter_mount.go +++ b/pkg/util/mount/nsenter_mount.go @@ -170,6 +170,12 @@ func (n *NsenterMounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, err } + // Check the directory exists + if _, err = os.Stat(file); os.IsNotExist(err) { + 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} glog.V(5).Infof("findmnt command: %v %v", nsenterPath, args)