Skip to content

Commit c95382c

Browse files
j4ckstrawk8s-publishing-bot
authored andcommitted
fallback to origin IsLikelyNotMountPoint to avoid regression
Signed-off-by: j4ckstraw <[email protected]> fix compile error Kubernetes-commit: 47b1002bab47ffee51f2d25679cf9fa1932d5361
1 parent a93a697 commit c95382c

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

mount_linux.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"path/filepath"
3030
"strconv"
3131
"strings"
32+
"syscall"
3233
"time"
3334

3435
"github.com/moby/sys/mountinfo"
@@ -403,21 +404,42 @@ func statx(file string) (unix.Statx_t, error) {
403404
return stat, nil
404405
}
405406

407+
func (mounter *Mounter) isLikelyNotMountPoint(file string) (bool, error) {
408+
stat, err := os.Stat(file)
409+
if err != nil {
410+
return true, err
411+
}
412+
rootStat, err := os.Stat(filepath.Dir(strings.TrimSuffix(file, "/")))
413+
if err != nil {
414+
return true, err
415+
}
416+
// If the directory has a different device as parent, then it is a mountpoint.
417+
if stat.Sys().(*syscall.Stat_t).Dev != rootStat.Sys().(*syscall.Stat_t).Dev {
418+
return false, nil
419+
}
420+
421+
return true, nil
422+
}
423+
406424
// IsLikelyNotMountPoint determines if a directory is not a mountpoint.
407-
// If fast check failed, fall back to slow path. If the path is in fact
408-
// a bind mount from one part of a mount to another it will be detected.
409-
// It also can distinguish between mountpoints and symbolic links.
425+
// It is fast but not necessarily ALWAYS correct. If the path is in fact
426+
// a bind mount from one part of a mount to another it will not be detected.
427+
// It also can not distinguish between mountpoints and symbolic links.
410428
// mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b")
411-
// will return false. When in fact /tmp/b is a mount point.
429+
// will return true. When in fact /tmp/b is a mount point. If this situation
430+
// is of interest to you, don't use this function...
412431
func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
413432
var stat, rootStat unix.Statx_t
414433
var err error
415434

416435
if stat, err = statx(file); err != nil {
417436
if errors.Is(err, errStatxNotSupport) {
418437
// not support statx, go slow path
419-
mnt, mntErr := mounter.IsMountPoint(file)
420-
return !mnt, mntErr
438+
// mnt, mntErr := mounter.IsMountPoint(file)
439+
// return !mnt, mntErr
440+
441+
// fall back to isLikelyNotMountPoint
442+
return mounter.isLikelyNotMountPoint(file)
421443
}
422444

423445
return false, err

0 commit comments

Comments
 (0)