Merge pull request #727 from kolyshkin/mountinfo-0.3.1

vendor: bump mountinfo to v0.3.1
This commit is contained in:
Daniel J Walsh 2020-10-05 09:29:43 -04:00 committed by GitHub
commit 69ef37be2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 50 additions and 64 deletions

View File

@ -160,7 +160,7 @@ func lookupZfsDataset(rootdir string) (string, error) {
continue // may fail on fuse file systems
}
if stat.Dev == wantedDev && m.Fstype == "zfs" {
if stat.Dev == wantedDev && m.FSType == "zfs" {
return m.Source, nil
}
}

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/klauspost/pgzip v1.2.5
github.com/mattn/go-shellwords v1.0.10
github.com/mistifyio/go-zfs v2.1.1+incompatible
github.com/moby/sys/mountinfo v0.2.0
github.com/moby/sys/mountinfo v0.3.1
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/runc v1.0.0-rc91
github.com/opencontainers/runtime-spec v1.0.3-0.20200520003142-237cc4f519e2

4
go.sum
View File

@ -80,8 +80,8 @@ github.com/mistifyio/go-zfs v2.1.1+incompatible h1:gAMO1HM9xBRONLHHYnu5iFsOJUiJd
github.com/mistifyio/go-zfs v2.1.1+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
github.com/moby/sys/mountinfo v0.1.3 h1:KIrhRO14+AkwKvG/g2yIpNMOUVZ02xNhOw8KY1WsLOI=
github.com/moby/sys/mountinfo v0.1.3/go.mod h1:w2t2Avltqx8vE7gX5l+QiBKxODu2TX0+Syr3h52Tw4o=
github.com/moby/sys/mountinfo v0.2.0 h1:HgYSHMWCj8D7w7TE/cQJfWrY6W3TUxs3pwGFyC5qCvE=
github.com/moby/sys/mountinfo v0.2.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/mountinfo v0.3.1 h1:R+C9GycEzoR3GdwQ7mANRhJORnVDJiRkf0JMY82MeI0=
github.com/moby/sys/mountinfo v0.3.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 h1:7InQ7/zrOh6SlFjaXFubv0xX0HsuC9qJsdqm7bNQpYM=
github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618/go.mod h1:x8F1gnqOkIEiO4rqoeEEEqQbo7HjGMTvyoq3gej4iT0=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=

View File

@ -154,8 +154,8 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
// Use parent info as the defaults
p := mnts[mi.Parent]
pOpts := make(map[string]struct{})
if p.Opts != "" {
for _, opt := range strings.Split(p.Opts, ",") {
if p.Options != "" {
for _, opt := range strings.Split(p.Options, ",") {
pOpts[clean(opt)] = struct{}{}
}
}
@ -166,9 +166,9 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
}
}
// Validate Opts
if mi.Opts != "" {
for _, opt := range strings.Split(mi.Opts, ",") {
// Validate Options
if mi.Options != "" {
for _, opt := range strings.Split(mi.Options, ",") {
opt = clean(opt)
if !has(volunteeredOPT, opt) && !has(wantedOpts, opt) && !has(pOpts, opt) {
t.Errorf("unexpected mount option %q, expected %q", opt, opts)
@ -177,7 +177,7 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
}
}
for opt := range wantedOpts {
t.Errorf("missing mount option %q found %q", opt, mi.Opts)
t.Errorf("missing mount option %q found %q", opt, mi.Options)
}
// Validate Optional
@ -196,8 +196,8 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
// Validate VFS if set
if vfs != "" {
if mi.VfsOpts != "" {
for _, opt := range strings.Split(mi.VfsOpts, ",") {
if mi.VFSOptions != "" {
for _, opt := range strings.Split(mi.VFSOptions, ",") {
opt = clean(opt)
if !has(wantedVFS, opt) && !has(volunteeredVFS, opt) {
t.Errorf("unexpected vfs option %q, expected %q", opt, vfs)
@ -206,7 +206,7 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
}
}
for opt := range wantedVFS {
t.Errorf("missing vfs option %q, found %q", opt, mi.VfsOpts)
t.Errorf("missing vfs option %q, found %q", opt, mi.VFSOptions)
}
}

View File

@ -1,5 +1,6 @@
// Package mountinfo provides a set of functions to retrieve information about OS mounts.
// Currently it supports Linux. For historical reasons, there is also some support for FreeBSD,
//
// Currently it supports Linux. For historical reasons, there is also some support for FreeBSD and OpenBSD,
// and a shallow implementation for Windows, but in general this is Linux-only package, so
// the rest of the document only applies to Linux, unless explicitly specified otherwise.
//
@ -8,7 +9,7 @@
// see different mounts. A per-process mountinfo table is available from /proc/<PID>/mountinfo,
// where <PID> is a numerical process identifier.
//
// In general, /proc is not a very effective interface, and mountinfo is not an exception.
// In general, /proc is not a very efficient interface, and mountinfo is not an exception.
// For example, there is no way to get information about a specific mount point (i.e. it
// is all-or-nothing). This package tries to hide the /proc ineffectiveness by using
// parse filters while reading mountinfo. A filter can skip some entries, or stop
@ -27,7 +28,7 @@
// of the cases where mountinfo should not be parsed:
//
// 1. Before performing a mount. Usually, this is not needed, but if required (say to
// prevent overmounts), to check whether a directory is mounted, call os.Lstat
// prevent over-mounts), to check whether a directory is mounted, call os.Lstat
// on it and its parent directory, and compare their st.Sys().(*syscall.Stat_t).Dev
// fields -- if they differ, then the directory is the mount point. NOTE this does
// not work for bind mounts. Optionally, the filesystem type can also be checked
@ -43,5 +44,4 @@
//
// 5. To find the mount point root of a specific directory. You can perform os.Stat()
// on the directory and traverse up until the Dev field of a parent directory differs.
package mountinfo

View File

@ -1,4 +1,4 @@
// +build linux freebsd,cgo
// +build linux freebsd,cgo openbsd,cgo
package mountinfo

View File

@ -1,7 +1,6 @@
package mountinfo
import (
"io"
"os"
)
@ -11,14 +10,6 @@ func GetMounts(f FilterFunc) ([]*Info, error) {
return parseMountTable(f)
}
// 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.
func GetMountsFromReader(reader io.Reader, f FilterFunc) ([]*Info, error) {
return parseInfoFile(reader, f)
}
// Mounted determines if a specified path is a mount point.
//
// The argument must be an absolute path, with all symlinks resolved, and clean.
@ -55,18 +46,18 @@ type Info struct {
// Mountpoint indicates the mount point relative to the process's root.
Mountpoint string
// Opts represents mount-specific options.
Opts string
// Options represents mount-specific options.
Options string
// Optional represents optional fields.
Optional string
// Fstype indicates the type of filesystem, such as EXT3.
Fstype string
// FSType indicates the type of filesystem, such as EXT3.
FSType string
// Source indicates filesystem specific information or "none".
Source string
// VfsOpts represents per super block options.
VfsOpts string
// VFSOptions represents per super block options.
VFSOptions string
}

View File

@ -1,3 +1,5 @@
// +build freebsd,cgo openbsd,cgo
package mountinfo
/*
@ -33,7 +35,7 @@ func parseMountTable(filter FilterFunc) ([]*Info, error) {
var mountinfo Info
var skip, stop bool
mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0])
mountinfo.Fstype = C.GoString(&entry.f_fstypename[0])
mountinfo.FSType = C.GoString(&entry.f_fstypename[0])
mountinfo.Source = C.GoString(&entry.f_mntfromname[0])
if filter != nil {
@ -54,7 +56,7 @@ func parseMountTable(filter FilterFunc) ([]*Info, error) {
func mounted(path string) (bool, error) {
// Fast path: compare st.st_dev fields.
// This should always work for FreeBSD.
// This should always work for FreeBSD and OpenBSD.
mounted, err := mountedByStat(path)
if err == nil {
return mounted, nil

View File

@ -7,8 +7,8 @@ import "strings"
// and/or stop further processing if we found what we wanted.
//
// It takes a pointer to the Info struct (not fully populated,
// currently only Mountpoint, Fstype, Source, and (on Linux)
// VfsOpts are filled in), and returns two booleans:
// currently only Mountpoint, FSType, Source, and (on Linux)
// VFSOptions are filled in), and returns two booleans:
//
// - skip: true if the entry should be skipped
// - stop: true if parsing should be stopped after the entry
@ -45,12 +45,12 @@ func ParentsFilter(path string) FilterFunc {
}
}
// FstypeFilter returns all entries that match provided fstype(s).
func FstypeFilter(fstype ...string) FilterFunc {
// FSTypeFilter returns all entries that match provided fstype(s).
func FSTypeFilter(fstype ...string) FilterFunc {
return func(m *Info) (bool, bool) {
for _, t := range fstype {
if m.Fstype == t {
return false, false // don't skeep, keep going
if m.FSType == t {
return false, false // don't skip, keep going
}
}
return true, false // skip, keep going

View File

@ -1,5 +1,3 @@
// +build go1.13
package mountinfo
import (
@ -11,7 +9,13 @@ import (
"strings"
)
func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) {
// 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.
//
// This function is Linux-specific.
func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
s := bufio.NewScanner(r)
out := []*Info{}
var err error
@ -75,7 +79,7 @@ func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) {
if err != nil {
return nil, fmt.Errorf("Parsing '%s' failed: mount point: %w", fields[4], err)
}
p.Fstype, err = unescape(fields[sepIdx+1])
p.FSType, err = unescape(fields[sepIdx+1])
if err != nil {
return nil, fmt.Errorf("Parsing '%s' failed: fstype: %w", fields[sepIdx+1], err)
}
@ -83,9 +87,9 @@ func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) {
if err != nil {
return nil, fmt.Errorf("Parsing '%s' failed: source: %w", fields[sepIdx+2], err)
}
p.VfsOpts = fields[sepIdx+3]
p.VFSOptions = fields[sepIdx+3]
// Run a filter soon so we can skip parsing/adding entries
// Run a filter early so we can skip parsing/adding entries
// the caller is not interested in
var skip, stop bool
if filter != nil {
@ -112,7 +116,7 @@ func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) {
return nil, fmt.Errorf("Parsing '%s' failed: root: %w", fields[3], err)
}
p.Opts = fields[5]
p.Options = fields[5]
// zero or more optional fields
switch {
@ -141,7 +145,7 @@ func parseMountTable(filter FilterFunc) ([]*Info, error) {
}
defer f.Close()
return parseInfoFile(f, filter)
return GetMountsFromReader(f, filter)
}
// PidMountInfo collects the mounts for a specific process ID. If the process
@ -154,7 +158,7 @@ func PidMountInfo(pid int) ([]*Info, error) {
}
defer f.Close()
return parseInfoFile(f, nil)
return GetMountsFromReader(f, nil)
}
// A few specific characters in mountinfo path entries (root and mountpoint)
@ -173,7 +177,7 @@ func unescape(path string) (string, error) {
}
// The following code is UTF-8 transparent as it only looks for some
// specific characters (backslach and 0..7) with values < utf8.RuneSelf,
// specific characters (backslash and 0..7) with values < utf8.RuneSelf,
// and everything else is passed through as is.
buf := make([]byte, len(path))
bufLen := 0

View File

@ -1,10 +1,9 @@
// +build !windows,!linux,!freebsd freebsd,!cgo
// +build !windows,!linux,!freebsd,!openbsd freebsd,!cgo openbsd,!cgo
package mountinfo
import (
"fmt"
"io"
"runtime"
)
@ -14,10 +13,6 @@ func parseMountTable(_ FilterFunc) ([]*Info, error) {
return nil, errNotImplemented
}
func parseInfoFile(_ io.Reader, f FilterFunc) ([]*Info, error) {
return parseMountTable(f)
}
func mounted(path string) (bool, error) {
return false, errNotImplemented
}

View File

@ -1,16 +1,10 @@
package mountinfo
import "io"
func parseMountTable(_ FilterFunc) ([]*Info, error) {
// Do NOT return an error!
return nil, nil
}
func parseInfoFile(_ io.Reader, f FilterFunc) ([]*Info, error) {
return parseMountTable(f)
}
func mounted(_ string) (bool, error) {
return false, nil
}

2
vendor/modules.txt vendored
View File

@ -69,7 +69,7 @@ github.com/mattn/go-shellwords
# github.com/mistifyio/go-zfs v2.1.1+incompatible
## explicit
github.com/mistifyio/go-zfs
# github.com/moby/sys/mountinfo v0.2.0
# github.com/moby/sys/mountinfo v0.3.1
## explicit
github.com/moby/sys/mountinfo
# github.com/opencontainers/go-digest v1.0.0