mount

package
v9.4.32+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllDevices designates all devices that show up as source.
	AllDevices = "AllDevices"
)
View Source
const (
	// NFSAllServers is a catch all for all servers.
	NFSAllServers = "NFSAllServers"
)

Variables

View Source
var (
	// ErrExist is returned if path is already mounted to a different device.
	ErrExist = errors.New("Mountpath already exists")
	// ErrEnoent is returned for a non existent mount point
	ErrEnoent = errors.New("Mountpath is not mounted")
	// ErrEinval is returned is fields for an entry do no match
	// existing fields
	ErrEinval = errors.New("Invalid arguments for mount entry")
	// ErrUnsupported is returned for an unsupported operation or a mount type.
	ErrUnsupported = errors.New("Not supported")
	// ErrMountpathNotAllowed is returned when the requested mountpath is not
	// a part of the provided allowed mount paths
	ErrMountpathNotAllowed = errors.New("Mountpath is not allowed")
)
View Source
var ErrLimitReached = errors.New("the read limit is reached")

ErrLimitReached means that the read limit is reached.

Functions

func GetMounts

func GetMounts() ([]*mount.Info, error)

GetMounts is a wrapper over mount.GetMounts(). It is mainly used to add a switch to enable device mounter tests.

func NewBindMounter

func NewBindMounter(
	rootSubstrings []string,
	mountImpl MountImpl,
	allowedDirs []string,
	trashLocation string,
) (*bindMounter, error)

NewBindMounter returns a new bindMounter

func NewDeletedMounter

func NewDeletedMounter(
	rootSubstring string,
	mountImpl MountImpl,
) (*deletedMounter, error)

NewDeletedMounter returns a new deletedMounter

func NewDeviceMounter

func NewDeviceMounter(
	devPrefixes []string,
	mountImpl MountImpl,
	allowedDirs []string,
	trashLocation string,
) (*deviceMounter, error)

NewDeviceMounter returns a new deviceMounter

func NewRawBindMounter

func NewRawBindMounter(
	rootSubstrings []string,
	mountImpl MountImpl,
	allowedDirs []string,
	trashLocation string,
) (*rawMounter, error)

NewRawBindMounter returns a new rawBindMounter

Types

type CustomLoad

type CustomLoad func([]string, DeviceMap, PathMap) error

CustomLoad defines the mounter.Load callback function for customer mounters

type CustomMounter

type CustomMounter func() (CustomLoad, CustomReload)

CustomMounter defines the CustomMount function that retursn the load and reload callbacks

type CustomMounterHandler

type CustomMounterHandler struct {
	Mounter
	// contains filtered or unexported fields
}

CustomMounterHandler implements the Mounter interface

func NewCustomMounter

func NewCustomMounter(
	devPrefixes []string,
	mountImpl MountImpl,
	customMounter CustomMounter,
	allowedDirs []string,
) (*CustomMounterHandler, error)

NewCustomMounter returns a new CustomMounter

func (*CustomMounterHandler) Load

func (c *CustomMounterHandler) Load(devPrefixes []string) error

Load mount table

func (*CustomMounterHandler) Reload

func (c *CustomMounterHandler) Reload(device string) error

Reload mount table for a device

type CustomReload

type CustomReload func(string, DeviceMap, PathMap) error

CustomReload defines the mounter.Reload callback function for customer mounters

type DefaultMounter

type DefaultMounter struct {
}

DefaultMounter defaults to syscall implementation.

func (*DefaultMounter) Mount

func (m *DefaultMounter) Mount(
	source string,
	target string,
	fstype string,
	flags uintptr,
	data string,
	timeout int,
) error

Mount default mount implementation is syscall.

func (*DefaultMounter) Unmount

func (m *DefaultMounter) Unmount(target string, flags int, timeout int) error

Unmount default unmount implementation is syscall.

type DeviceMap

type DeviceMap map[string]*Info

DeviceMap map device name to Info

type Info

type Info struct {
	sync.Mutex
	Device     string
	Minor      int
	Mountpoint []*PathInfo
	Fs         string
}

Info per device

type Manager

type Manager interface {
	// String representation of the mount table
	String() string
	// Reload mount table for specified device.
	Reload(source string) error
	// Load mount table for all devices that match the list of identifiers
	Load(source []string) error
	// Inspect mount table for specified source. ErrEnoent may be returned.
	Inspect(source string) []*PathInfo
	// Mounts returns paths for specified source.
	Mounts(source string) []string
	// HasMounts determines returns the number of mounts for the source.
	HasMounts(source string) int
	// HasTarget determines returns the number of mounts for the target.
	HasTarget(target string) (string, bool)
	// Exists returns true if the device is mounted at specified path.
	// returned if the device does not exists.
	Exists(source, path string) (bool, error)
	// GetRootPath scans mounts for a specified mountPath and returns the
	// rootPath if found or returns an ErrEnoent
	GetRootPath(mountPath string) (string, error)
	// GetSourcePath scans mount for a specified mountPath and returns the
	// sourcePath if found or returns an ErrEnoent
	GetSourcePath(mountPath string) (string, error)
	// GetSourcePaths returns all source paths from the mount table
	GetSourcePaths() []string
	// Mount device at mountpoint
	Mount(
		minor int,
		device string,
		path string,
		fs string,
		flags uintptr,
		data string,
		timeout int,
		opts map[string]string) error
	// Unmount device at mountpoint and remove from the matrix.
	// ErrEnoent is returned if the device or mountpoint for the device
	// is not found.
	Unmount(source, path string, flags int, timeout int, opts map[string]string) error
	// RemoveMountPath removes the given path
	RemoveMountPath(path string, opts map[string]string) error
	// EmptyTrashDir removes all directories from the mounter trash directory
	EmptyTrashDir() error
}

Manager defines the interface for keep track of volume driver mounts.

func New

func New(
	mounterType MountType,
	mountImpl MountImpl,
	identifiers []string,
	customMounter CustomMounter,
	allowedDirs []string,
	trashLocation string,
) (Manager, error)

New returns a new Mount Manager

func NewNFSMounter

func NewNFSMounter(servers []string,
	mountImpl MountImpl,
	allowedDirs []string,
) (Manager, error)

NewnfsMounter returns a Mounter specific to parse NFS mounts. This can work VFS also if 'servers' is nil. Use NFSAllServers if the destination server is unknown.

type MountImpl

type MountImpl interface {
	Mount(source, target, fstype string, flags uintptr, data string, timeout int) error
	Unmount(target string, flags int, timeout int) error
}

MountImpl backend implementation for Mount/Unmount calls

type MountType

type MountType int

MountType indicates different mount types supported

const (
	// DeviceMount indicates a device mount type
	DeviceMount MountType = 1 << iota
	// NFSMount indicates a NFS mount point
	NFSMount
	// CustomMount indicates a custom mount type with its
	// own defined way of handling mount table
	CustomMount
	// BindMount indicates a bind mount point
	BindMount
	// RawMount indicates a raw mount point
	RawMount
)

type Mounter

type Mounter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Mounter implements Ops and keeps track of active mounts for volume drivers.

func (*Mounter) EmptyTrashDir

func (m *Mounter) EmptyTrashDir() error

func (*Mounter) Exists

func (m *Mounter) Exists(sourcePath string, path string) (bool, error)

Exists scans mountpaths for specified device and returns true if path is one of the mountpaths. ErrEnoent may be retuned if the device is not found

func (*Mounter) GetRootPath

func (m *Mounter) GetRootPath(mountPath string) (string, error)

GetRootPath scans mounts for a specified mountPath and return the rootPath if found or returns an ErrEnoent

func (*Mounter) GetSourcePath

func (m *Mounter) GetSourcePath(mountPath string) (string, error)

GetSourcePath scans mount for a specified mountPath and returns the sourcePath if found or returnes an ErrEnoent

func (*Mounter) GetSourcePaths

func (m *Mounter) GetSourcePaths() []string

GetSourcePaths returns all source paths from the mount table

func (*Mounter) HasMounts

func (m *Mounter) HasMounts(sourcePath string) int

HasMounts determines returns the number of mounts for the device.

func (*Mounter) HasTarget

func (m *Mounter) HasTarget(targetPath string) (string, bool)

HasTarget returns true/false based on the target provided

func (*Mounter) Inspect

func (m *Mounter) Inspect(sourcePath string) []*PathInfo

Inspect mount table for device

func (*Mounter) Mount

func (m *Mounter) Mount(
	minor int,
	devPath, path, fs string,
	flags uintptr,
	data string,
	timeout int,
	opts map[string]string,
) error

Mount new mountpoint for specified device.

func (*Mounter) Mounts

func (m *Mounter) Mounts(sourcePath string) []string

Mounts returns mount table for device

func (*Mounter) RemoveMountPath

func (m *Mounter) RemoveMountPath(mountPath string, opts map[string]string) error

RemoveMountPath makes the path writeable and removes it after a fixed delay

func (*Mounter) String

func (m *Mounter) String() string

String representation of Mounter

func (*Mounter) Unmount

func (m *Mounter) Unmount(
	devPath string,
	path string,
	flags int,
	timeout int,
	opts map[string]string,
) error

Unmount device at mountpoint and from the matrix. ErrEnoent is returned if the device or mountpoint for the device is not found.

type PathInfo

type PathInfo struct {
	Root string
	Path string
}

PathInfo is a reference counted path

type PathMap

type PathMap map[string]string

PathMap map path name to device

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL