mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
vendor: github.com/moby/sys/mountinfo v0.6.0
full diff: https://github.com/moby/sys/compare/mountinfo/v0.5.0...mountinfo/v0.6.0 - Add MountedFast (Note: most users should keep using Mounted, which already incorporates all optimizations from MountedFast) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c2b33f8684
commit
9c2646e486
5 changed files with 58 additions and 13 deletions
|
@ -55,7 +55,7 @@ require (
|
|||
github.com/moby/ipvs v1.0.1
|
||||
github.com/moby/locker v1.0.1
|
||||
github.com/moby/sys/mount v0.3.0
|
||||
github.com/moby/sys/mountinfo v0.5.0
|
||||
github.com/moby/sys/mountinfo v0.6.0
|
||||
github.com/moby/sys/signal v0.6.0
|
||||
github.com/moby/sys/symlink v0.2.0
|
||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
|
||||
|
|
|
@ -509,8 +509,9 @@ github.com/moby/sys/mount v0.3.0 h1:bXZYMmq7DBQPwHRxH/MG+u9+XF90ZOwoXpHTOznMGp0=
|
|||
github.com/moby/sys/mount v0.3.0/go.mod h1:U2Z3ur2rXPFrFmy4q6WMwWrBOAQGYtYTRVM8BIvzbwk=
|
||||
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
|
||||
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
|
||||
github.com/moby/sys/mountinfo v0.5.0 h1:2Ks8/r6lopsxWi9m58nlwjaeSzUX9iiL1vj5qB/9ObI=
|
||||
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
|
||||
github.com/moby/sys/mountinfo v0.6.0 h1:gUDhXQx58YNrpHlK4nSL+7y2pxFZkUcXqzFDKWdC0Oo=
|
||||
github.com/moby/sys/mountinfo v0.6.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
|
||||
github.com/moby/sys/signal v0.6.0 h1:aDpY94H8VlhTGa9sNYUFCFsMZIUh5wm0B6XkIoJj/iY=
|
||||
github.com/moby/sys/signal v0.6.0/go.mod h1:GQ6ObYZfqacOwTtlXvcmh9A26dVRul/hbOZn88Kg8Tg=
|
||||
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
|
||||
|
|
58
vendor/github.com/moby/sys/mountinfo/mounted_linux.go
generated
vendored
58
vendor/github.com/moby/sys/mountinfo/mounted_linux.go
generated
vendored
|
@ -7,6 +7,34 @@ import (
|
|||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// MountedFast is a method of detecting a mount point without reading
|
||||
// mountinfo from procfs. A caller can only trust the result if no error
|
||||
// and sure == true are returned. Otherwise, other methods (e.g. parsing
|
||||
// /proc/mounts) have to be used. If unsure, use Mounted instead (which
|
||||
// uses MountedFast, but falls back to parsing mountinfo if needed).
|
||||
//
|
||||
// If a non-existent path is specified, an appropriate error is returned.
|
||||
// In case the caller is not interested in this particular error, it should
|
||||
// be handled separately using e.g. errors.Is(err, os.ErrNotExist).
|
||||
//
|
||||
// This function is only available on Linux. When available (since kernel
|
||||
// v5.6), openat2(2) syscall is used to reliably detect all mounts. Otherwise,
|
||||
// the implementation falls back to using stat(2), which can reliably detect
|
||||
// normal (but not bind) mounts.
|
||||
func MountedFast(path string) (mounted, sure bool, err error) {
|
||||
// Root is always mounted.
|
||||
if path == string(os.PathSeparator) {
|
||||
return true, true, nil
|
||||
}
|
||||
|
||||
path, err = normalizePath(path)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
mounted, sure, err = mountedFast(path)
|
||||
return
|
||||
}
|
||||
|
||||
// mountedByOpenat2 is a method of detecting a mount that works for all kinds
|
||||
// of mounts (incl. bind mounts), but requires a recent (v5.6+) linux kernel.
|
||||
func mountedByOpenat2(path string) (bool, error) {
|
||||
|
@ -34,24 +62,40 @@ func mountedByOpenat2(path string) (bool, error) {
|
|||
return false, &os.PathError{Op: "openat2", Path: path, Err: err}
|
||||
}
|
||||
|
||||
func mounted(path string) (bool, error) {
|
||||
path, err := normalizePath(path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
// mountedFast is similar to MountedFast, except it expects a normalized path.
|
||||
func mountedFast(path string) (mounted, sure bool, err error) {
|
||||
// Root is always mounted.
|
||||
if path == string(os.PathSeparator) {
|
||||
return true, true, nil
|
||||
}
|
||||
|
||||
// Try a fast path, using openat2() with RESOLVE_NO_XDEV.
|
||||
mounted, err := mountedByOpenat2(path)
|
||||
mounted, err = mountedByOpenat2(path)
|
||||
if err == nil {
|
||||
return mounted, nil
|
||||
return mounted, true, nil
|
||||
}
|
||||
|
||||
// Another fast path: compare st.st_dev fields.
|
||||
mounted, err = mountedByStat(path)
|
||||
// This does not work for bind mounts, so false negative
|
||||
// is possible, therefore only trust if return is true.
|
||||
if mounted && err == nil {
|
||||
return true, true, nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func mounted(path string) (bool, error) {
|
||||
path, err := normalizePath(path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
mounted, sure, err := mountedFast(path)
|
||||
if sure && err == nil {
|
||||
return mounted, nil
|
||||
}
|
||||
|
||||
// Fallback to parsing mountinfo
|
||||
// Fallback to parsing mountinfo.
|
||||
return mountedByMountinfo(path)
|
||||
}
|
||||
|
|
6
vendor/github.com/moby/sys/mountinfo/mountinfo.go
generated
vendored
6
vendor/github.com/moby/sys/mountinfo/mountinfo.go
generated
vendored
|
@ -13,9 +13,9 @@ func GetMounts(f FilterFunc) ([]*Info, error) {
|
|||
// Mounted determines if a specified path is a mount point. In case of any
|
||||
// error, false (and an error) is returned.
|
||||
//
|
||||
// The non-existent path returns an error. If a caller is not interested
|
||||
// in this particular error, it should handle it separately using e.g.
|
||||
// errors.Is(err, os.ErrNotExist).
|
||||
// If a non-existent path is specified, an appropriate error is returned.
|
||||
// In case the caller is not interested in this particular error, it should
|
||||
// be handled separately using e.g. errors.Is(err, os.ErrNotExist).
|
||||
func Mounted(path string) (bool, error) {
|
||||
// root is always mounted
|
||||
if path == string(os.PathSeparator) {
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -640,7 +640,7 @@ github.com/moby/locker
|
|||
# github.com/moby/sys/mount v0.3.0
|
||||
## explicit; go 1.16
|
||||
github.com/moby/sys/mount
|
||||
# github.com/moby/sys/mountinfo v0.5.0
|
||||
# github.com/moby/sys/mountinfo v0.6.0
|
||||
## explicit; go 1.16
|
||||
github.com/moby/sys/mountinfo
|
||||
# github.com/moby/sys/signal v0.6.0
|
||||
|
|
Loading…
Reference in a new issue