go.mod: moby/sys/mount v0.2.0, moby/sys/mountinfo v0.4.1
github.com/moby/sys/mountinfo v0.4.1 ------------------------------------- - Fix PrefixFilter() being too greedy - TestMountedBy*: add missing pre-checks - Documentation improvements github.com/moby/sys/mount v0.2.0 ------------------------------------- Breaking changes: - Remove stub-implementations for Windows for Mount(), Unmount(), RecursiveUnmount(), MergeTmpfsOptions() Fixes and improvements: - go.mod: update github.com/moby/sys/mountinfo to v0.4.0 - use MNT_* flags from golang.org/x/sys/unix on freebsd - add support for OpenBSD in addition to FreeBSD - fix package overview documentation not showing - RecursiveUnmount(): minor improvements Signed-off-by: Sebastiaan van Stijn <github@gone.nl>v0.9
parent
2be23848e8
commit
583b4679f6
3
go.mod
3
go.mod
|
@ -38,7 +38,8 @@ require (
|
|||
github.com/jaguilar/vt100 v0.0.0-20150826170717-2703a27b14ea
|
||||
github.com/mitchellh/hashstructure v1.0.0
|
||||
github.com/moby/locker v1.0.1
|
||||
github.com/moby/sys/mount v0.1.1 // indirect; force more current version of sys/mount than go mod selects automatically
|
||||
github.com/moby/sys/mount v0.2.0 // indirect; force more current version of sys/mount than go mod selects automatically
|
||||
github.com/moby/sys/mountinfo v0.4.1 // indirect; force more current version of sys/mountinfo than go mod selects automatically
|
||||
github.com/moby/term v0.0.0-20200915141129-7f0af18e79f2 // indirect
|
||||
github.com/morikuni/aec v1.0.0
|
||||
github.com/opencontainers/go-digest v1.0.0
|
||||
|
|
7
go.sum
7
go.sum
|
@ -409,13 +409,16 @@ 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/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
|
||||
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
|
||||
github.com/moby/sys/mount v0.1.0 h1:Ytx78EatgFKtrqZ0BvJ0UtJE472ZvawVmil6pIfuCCU=
|
||||
github.com/moby/sys/mount v0.1.0/go.mod h1:FVQFLDRWwyBjDTBNQXDlWnSFREqOo3OKX9aqhmeoo74=
|
||||
github.com/moby/sys/mount v0.1.1 h1:mdhBytJ1SMmMat0gtzWWjFX/87K5j6E/7Q5z7rR0cZY=
|
||||
github.com/moby/sys/mount v0.1.1/go.mod h1:FVQFLDRWwyBjDTBNQXDlWnSFREqOo3OKX9aqhmeoo74=
|
||||
github.com/moby/sys/mount v0.2.0 h1:WhCW5B355jtxndN5ovugJlMFJawbUODuW8fSnEH6SSM=
|
||||
github.com/moby/sys/mount v0.2.0/go.mod h1:aAivFE2LB3W4bACsUXChRHQ0qKWsetY4Y9V7sxOougM=
|
||||
github.com/moby/sys/mountinfo v0.1.0/go.mod h1:w2t2Avltqx8vE7gX5l+QiBKxODu2TX0+Syr3h52Tw4o=
|
||||
github.com/moby/sys/mountinfo v0.1.3/go.mod h1:w2t2Avltqx8vE7gX5l+QiBKxODu2TX0+Syr3h52Tw4o=
|
||||
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/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
|
||||
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
|
||||
github.com/moby/term v0.0.0-20200915141129-7f0af18e79f2 h1:SPoLlS9qUUnXcIY4pvA4CTwYjk0Is5f4UPEkeESr53k=
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// Package mount provides a set of functions to mount and unmount mounts.
|
||||
//
|
||||
// Currently it supports Linux. For historical reasons, there is also some support for FreeBSD.
|
||||
package mount
|
|
@ -1,28 +1,25 @@
|
|||
// +build freebsd,cgo
|
||||
// +build freebsd openbsd
|
||||
|
||||
package mount
|
||||
|
||||
/*
|
||||
#include <sys/mount.h>
|
||||
*/
|
||||
import "C"
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
const (
|
||||
// RDONLY will mount the filesystem as read-only.
|
||||
RDONLY = C.MNT_RDONLY
|
||||
RDONLY = unix.MNT_RDONLY
|
||||
|
||||
// NOSUID will not allow set-user-identifier or set-group-identifier bits to
|
||||
// take effect.
|
||||
NOSUID = C.MNT_NOSUID
|
||||
NOSUID = unix.MNT_NOSUID
|
||||
|
||||
// NOEXEC will not allow execution of any binaries on the mounted file system.
|
||||
NOEXEC = C.MNT_NOEXEC
|
||||
NOEXEC = unix.MNT_NOEXEC
|
||||
|
||||
// SYNCHRONOUS will allow any I/O to the file system to be done synchronously.
|
||||
SYNCHRONOUS = C.MNT_SYNCHRONOUS
|
||||
SYNCHRONOUS = unix.MNT_SYNCHRONOUS
|
||||
|
||||
// NOATIME will not update the file access time when reading from a file.
|
||||
NOATIME = C.MNT_NOATIME
|
||||
NOATIME = unix.MNT_NOATIME
|
||||
)
|
||||
|
||||
// These flags are unsupported.
|
|
@ -1,3 +1,5 @@
|
|||
// +build !darwin,!windows
|
||||
|
||||
package mount
|
||||
|
||||
import (
|
|
@ -1,30 +0,0 @@
|
|||
// +build !linux,!freebsd freebsd,!cgo
|
||||
|
||||
package mount
|
||||
|
||||
// These flags are unsupported.
|
||||
const (
|
||||
BIND = 0
|
||||
DIRSYNC = 0
|
||||
MANDLOCK = 0
|
||||
NOATIME = 0
|
||||
NODEV = 0
|
||||
NODIRATIME = 0
|
||||
NOEXEC = 0
|
||||
NOSUID = 0
|
||||
UNBINDABLE = 0
|
||||
RUNBINDABLE = 0
|
||||
PRIVATE = 0
|
||||
RPRIVATE = 0
|
||||
SHARED = 0
|
||||
RSHARED = 0
|
||||
SLAVE = 0
|
||||
RSLAVE = 0
|
||||
RBIND = 0
|
||||
RELATIME = 0
|
||||
REMOUNT = 0
|
||||
STRICTATIME = 0
|
||||
SYNCHRONOUS = 0
|
||||
RDONLY = 0
|
||||
mntDetach = 0
|
||||
)
|
|
@ -3,6 +3,6 @@ module github.com/moby/sys/mount
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/moby/sys/mountinfo v0.1.0
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae
|
||||
github.com/moby/sys/mountinfo v0.4.0
|
||||
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
github.com/moby/sys/mountinfo v0.1.0 h1:r8vMRbMAFEAfiNptYVokP+nfxPJzvRuia5e2vzXtENo=
|
||||
github.com/moby/sys/mountinfo v0.1.0/go.mod h1:w2t2Avltqx8vE7gX5l+QiBKxODu2TX0+Syr3h52Tw4o=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
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=
|
||||
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 h1:YEu4SMq7D0cmT7CBbXfcH0NZeuChAXwsHe/9XueUO6o=
|
||||
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build go1.13
|
||||
// +build !darwin,!windows
|
||||
|
||||
package mount
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"github.com/moby/sys/mountinfo"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// Mount will mount filesystem according to the specified configuration.
|
||||
|
@ -18,9 +19,22 @@ func Mount(device, target, mType, options string) error {
|
|||
}
|
||||
|
||||
// Unmount lazily unmounts a filesystem on supported platforms, otherwise does
|
||||
// a normal unmount. If target is not a mount point, no error is returned.
|
||||
// a normal unmount. If target is not a mount point, no error is returned.
|
||||
func Unmount(target string) error {
|
||||
return unmount(target, mntDetach)
|
||||
err := unix.Unmount(target, mntDetach)
|
||||
if err == nil || err == unix.EINVAL {
|
||||
// Ignore "not mounted" error here. Note the same error
|
||||
// can be returned if flags are invalid, so this code
|
||||
// assumes that the flags value is always correct.
|
||||
return nil
|
||||
}
|
||||
|
||||
return &mountError{
|
||||
op: "umount",
|
||||
target: target,
|
||||
flags: uintptr(mntDetach),
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
// RecursiveUnmount unmounts the target and all mounts underneath, starting
|
||||
|
@ -32,7 +46,7 @@ func RecursiveUnmount(target string) error {
|
|||
// platforms, if there are submounts, we'll get EBUSY (and fall back
|
||||
// to the slow path). NOTE we do not ignore EINVAL here as target might
|
||||
// not be a mount point itself (but there can be mounts underneath).
|
||||
if err := unmountBare(target, mntDetach); err == nil {
|
||||
if err := unix.Unmount(target, mntDetach); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -47,12 +61,18 @@ func RecursiveUnmount(target string) error {
|
|||
return len(mounts[i].Mountpoint) > len(mounts[j].Mountpoint)
|
||||
})
|
||||
|
||||
var suberr error
|
||||
var (
|
||||
suberr error
|
||||
lastMount = len(mounts) - 1
|
||||
)
|
||||
for i, m := range mounts {
|
||||
err = unmount(m.Mountpoint, mntDetach)
|
||||
err = Unmount(m.Mountpoint)
|
||||
if err != nil {
|
||||
if i == len(mounts)-1 { // last mount
|
||||
return fmt.Errorf("%w (possible cause: %s)", err, suberr)
|
||||
if i == lastMount {
|
||||
if suberr != nil {
|
||||
return fmt.Errorf("%w (possible cause: %s)", err, suberr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
// This is a submount, we can ignore the error for now,
|
||||
// the final unmount will fail if this is a real problem.
|
|
@ -1,3 +1,5 @@
|
|||
// +build freebsd,cgo openbsd,cgo
|
||||
|
||||
package mount
|
||||
|
||||
/*
|
|
@ -1,7 +1,7 @@
|
|||
// +build !linux,!freebsd freebsd,!cgo
|
||||
// +build !linux,!freebsd,!openbsd,!windows freebsd,!cgo openbsd,!cgo
|
||||
|
||||
package mount
|
||||
|
||||
func mount(device, target, mType string, flag uintptr, data string) error {
|
||||
panic("Not implemented")
|
||||
panic("cgo required on freebsd and openbsd")
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package mount
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func unmountBare(target string, flags int) error {
|
||||
return unix.Unmount(target, flags)
|
||||
}
|
||||
|
||||
func unmount(target string, flags int) error {
|
||||
err := unmountBare(target, flags)
|
||||
if err == nil || err == unix.EINVAL {
|
||||
// Ignore "not mounted" error here. Note the same error
|
||||
// can be returned if flags are invalid, so this code
|
||||
// assumes that the flags value is always correct.
|
||||
return nil
|
||||
}
|
||||
|
||||
return &mountError{
|
||||
op: "umount",
|
||||
target: target,
|
||||
flags: uintptr(flags),
|
||||
err: err,
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
// +build windows
|
||||
|
||||
package mount
|
||||
|
||||
func unmountBare(_ string, _ int) error {
|
||||
panic("Not implemented")
|
||||
}
|
||||
|
||||
func unmount(_ string, _ int) error {
|
||||
panic("Not implemented")
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -276,9 +276,9 @@ github.com/klauspost/compress/zstd/internal/xxhash
|
|||
github.com/mitchellh/hashstructure
|
||||
# github.com/moby/locker v1.0.1
|
||||
github.com/moby/locker
|
||||
# github.com/moby/sys/mount v0.1.1
|
||||
# github.com/moby/sys/mount v0.2.0
|
||||
github.com/moby/sys/mount
|
||||
# github.com/moby/sys/mountinfo v0.4.0
|
||||
# github.com/moby/sys/mountinfo v0.4.1
|
||||
github.com/moby/sys/mountinfo
|
||||
# github.com/moby/term v0.0.0-20200915141129-7f0af18e79f2
|
||||
github.com/moby/term
|
||||
|
|
Loading…
Reference in New Issue