go.mod: github.com/moby/sys/mountinfo v0.4.1

full diff: https://github.com/moby/sys/compare/mountinfo/v0.4.0...mountinfo/v0.4.1

Fixes and improvements:

- Fix PrefixFilter() being too greedy
- TestMountedBy*: add missing pre-checks
- Documentation improvements

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-03-10 14:31:33 +01:00
parent 17ab5dd08c
commit d629a08ebf
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
6 changed files with 32 additions and 23 deletions

2
go.mod
View File

@ -37,7 +37,7 @@ require (
github.com/hashicorp/go-multierror v1.0.0
github.com/imdario/mergo v0.3.11
github.com/klauspost/compress v1.11.3
github.com/moby/sys/mountinfo v0.4.0
github.com/moby/sys/mountinfo v0.4.1
github.com/moby/sys/symlink v0.1.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.1

2
go.sum
View File

@ -383,6 +383,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/moby/sys/mountinfo v0.4.0 h1:1KInV3Huv18akCu58V7lzNlt+jFmqlu1EaErnEHE/VM=
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 h1:1O+1cHA1aujwEwwVMa2Xm2l+gIpUHyd3+D+d7LZh1kM=
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/symlink v0.1.0 h1:MTFZ74KtNI6qQQpuBxU+uKCim4WtOMokr03hCfJcazE=
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=

View File

@ -29,35 +29,38 @@ type Info struct {
// ID is a unique identifier of the mount (may be reused after umount).
ID int
// Parent indicates the ID of the mount parent (or of self for the top of the
// mount tree).
// Parent is the ID of the parent mount (or of self for the root
// of this mount namespace's mount tree).
Parent int
// Major indicates one half of the device ID which identifies the device class.
Major int
// Major and Minor are the major and the minor components of the Dev
// field of unix.Stat_t structure returned by unix.*Stat calls for
// files on this filesystem.
Major, Minor int
// Minor indicates one half of the device ID which identifies a specific
// instance of device.
Minor int
// Root of the mount within the filesystem.
// Root is the pathname of the directory in the filesystem which forms
// the root of this mount.
Root string
// Mountpoint indicates the mount point relative to the process's root.
// Mountpoint is the pathname of the mount point relative to the
// process's root directory.
Mountpoint string
// Options represents mount-specific options.
// Options is a comma-separated list of mount options.
Options string
// Optional represents optional fields.
// Optional are zero or more fields of the form "tag[:value]",
// separated by a space. Currently, the possible optional fields are
// "shared", "master", "propagate_from", and "unbindable". For more
// information, see mount_namespaces(7) Linux man page.
Optional string
// FSType indicates the type of filesystem, such as EXT3.
// FSType is the filesystem type in the form "type[.subtype]".
FSType string
// Source indicates filesystem specific information or "none".
// Source is filesystem-specific information, or "none".
Source string
// VFSOptions represents per super block options.
// VFSOptions is a comma-separated list of superblock options.
VFSOptions string
}

View File

@ -14,11 +14,16 @@ import "strings"
// stop: true if parsing should be stopped after the entry.
type FilterFunc func(*Info) (skip, stop bool)
// PrefixFilter discards all entries whose mount points
// do not start with a specific prefix.
// PrefixFilter discards all entries whose mount points do not start with, or
// are equal to the path specified in prefix. The prefix path must be absolute,
// have all symlinks resolved, and cleaned (i.e. no extra slashes or dots).
//
// PrefixFilter treats prefix as a path, not a partial prefix, which means that
// given "/foo", "/foo/bar" and "/foobar" entries, PrefixFilter("/foo") returns
// "/foo" and "/foo/bar", and discards "/foobar".
func PrefixFilter(prefix string) FilterFunc {
return func(m *Info) (bool, bool) {
skip := !strings.HasPrefix(m.Mountpoint, prefix)
skip := !strings.HasPrefix(m.Mountpoint+"/", prefix+"/")
return skip, false
}
}

View File

@ -12,7 +12,8 @@ import (
// GetMountsFromReader retrieves a list of mounts from the
// reader provided, with an optional filter applied (use nil
// for no filter). This can be useful in tests or benchmarks
// that provide a fake mountinfo data.
// that provide fake mountinfo data, or when a source other
// than /proc/self/mountinfo needs to be read from.
//
// This function is Linux-specific.
func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
@ -133,8 +134,6 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
return out, nil
}
// Parse /proc/self/mountinfo because comparing Dev and ino does not work from
// bind mounts
func parseMountTable(filter FilterFunc) ([]*Info, error) {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {

2
vendor/modules.txt vendored
View File

@ -250,7 +250,7 @@ github.com/matttproud/golang_protobuf_extensions/pbutil
github.com/miekg/pkcs11
# github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible
github.com/mistifyio/go-zfs
# github.com/moby/sys/mountinfo v0.4.0
# github.com/moby/sys/mountinfo v0.4.1
## explicit
github.com/moby/sys/mountinfo
# github.com/moby/sys/symlink v0.1.0