mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-18 16:21:13 +00:00
fallback to origin IsLikelyNotMountPoint to avoid regression
Signed-off-by: j4ckstraw <j4ckstraw@foxmail.com> fix compile error
This commit is contained in:
parent
81ef146e2f
commit
47b1002bab
@ -29,6 +29,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/moby/sys/mountinfo"
|
"github.com/moby/sys/mountinfo"
|
||||||
@ -403,12 +404,30 @@ func statx(file string) (unix.Statx_t, error) {
|
|||||||
return stat, nil
|
return stat, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mounter *Mounter) isLikelyNotMountPoint(file string) (bool, error) {
|
||||||
|
stat, err := os.Stat(file)
|
||||||
|
if err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
rootStat, err := os.Stat(filepath.Dir(strings.TrimSuffix(file, "/")))
|
||||||
|
if err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
// If the directory has a different device as parent, then it is a mountpoint.
|
||||||
|
if stat.Sys().(*syscall.Stat_t).Dev != rootStat.Sys().(*syscall.Stat_t).Dev {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// IsLikelyNotMountPoint determines if a directory is not a mountpoint.
|
// IsLikelyNotMountPoint determines if a directory is not a mountpoint.
|
||||||
// If fast check failed, fall back to slow path. If the path is in fact
|
// 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 be detected.
|
// a bind mount from one part of a mount to another it will not be detected.
|
||||||
// It also can distinguish between mountpoints and symbolic links.
|
// It also can not distinguish between mountpoints and symbolic links.
|
||||||
// mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b")
|
// mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b")
|
||||||
// will return false. When in fact /tmp/b is a mount point.
|
// will return true. When in fact /tmp/b is a mount point. If this situation
|
||||||
|
// is of interest to you, don't use this function...
|
||||||
func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
||||||
var stat, rootStat unix.Statx_t
|
var stat, rootStat unix.Statx_t
|
||||||
var err error
|
var err error
|
||||||
@ -416,8 +435,11 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
|||||||
if stat, err = statx(file); err != nil {
|
if stat, err = statx(file); err != nil {
|
||||||
if errors.Is(err, errStatxNotSupport) {
|
if errors.Is(err, errStatxNotSupport) {
|
||||||
// not support statx, go slow path
|
// not support statx, go slow path
|
||||||
mnt, mntErr := mounter.IsMountPoint(file)
|
// mnt, mntErr := mounter.IsMountPoint(file)
|
||||||
return !mnt, mntErr
|
// return !mnt, mntErr
|
||||||
|
|
||||||
|
// fall back to isLikelyNotMountPoint
|
||||||
|
return mounter.isLikelyNotMountPoint(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false, err
|
return false, err
|
||||||
|
Loading…
Reference in New Issue
Block a user