mounter

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMountOptions

func GetMountOptions(volumes *csi.VolumeCapability_MountVolume) []string

GetMountOptions returns mount options from VolumeCapability_MountVolume

func IsCorruptedMount

func IsCorruptedMount(err error) bool

IsCorruptedMount return true if err is about corrupted mount point

func IsMountPathAllowed

func IsMountPathAllowed(whitelist []string, path string) bool

IsMountPathAllowed checks if given path is allowed to mount

func ListProcMounts

func ListProcMounts(mountFilePath string) ([]mount.MountPoint, error)

ListProcMounts is shared with NsEnterMounter

func MakeDir

func MakeDir(path string) error

MakeDir creates a dir for the path

func MakeMountArgsSensitive

func MakeMountArgsSensitive(source, sourceMasked, target, fstype string, options []string, sensitiveOptions []string) (mountArgs []string, mountArgsLogStr string)

MakeMountArgsSensitive makes the arguments to the mount(8) command. sensitiveOptions is an extension of options except they will not be logged (because they may contain sensitive material)

func MountBind

func MountBind(mounter Mounter, sourcePath string, mntOptions []string, targetPath string) error

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if the specified path exists.

func SearchMountPoints

func SearchMountPoints(hostSource, mountInfoPath string) ([]string, error)

SearchMountPoints finds all mount references to the source, returns a list of mountpoints. The source can be a mount point or a normal directory (bind mount). We didn't support device because there is no use case by now. Some filesystems may share a source name, e.g. tmpfs. And for bind mounting, it's possible to mount a non-root path of a filesystem, so we need to use root path and major:minor to represent mount source uniquely. This implementation is shared between Linux and NsEnterMounter

Types

type MountInfo

type MountInfo struct {
	// Unique ID for the mount (maybe reused after umount).
	ID int
	// The ID of the parent mount (or of self for the root of this mount namespace's mount tree).
	ParentID int
	// Major indicates one half of the device ID which identifies the device class
	// (parsed from `st_dev` for files on this filesystem).
	Major int
	// Minor indicates one half of the device ID which identifies a specific
	// instance of device (parsed from `st_dev` for files on this filesystem).
	Minor int
	// The pathname of the directory in the filesystem which forms the root of this mount.
	Root string
	// Mount source, filesystem-specific information. e.g. device, tmpfs name.
	Source string
	// Mount point, the pathname of the mount point.
	MountPoint string
	// Optional fieds, zero or more fields of the form "tag[:value]".
	OptionalFields []string
	// The filesystem type in the form "type[.subtype]".
	FsType string
	// Per-mount options.
	MountOptions []string
	// Per-superblock options.
	SuperOptions []string
}

MountInfo represents a single line in /proc/<pid>/mountinfo.

func ParseMountInfo

func ParseMountInfo(filename string) ([]MountInfo, error)

ParseMountInfo parses /proc/xxx/mountinfo.

type Mounter

type Mounter interface {
	mount.Interface
	GetDeviceName(mountPath string) (string, int, error)
	MountSensitive2(source string, sourceMasked string, target string, fstype string, options []string, sensitiveOptions []string, stdinValues []string) error
	UnmountLazy(target string, lazy bool) error
	FuseUnmount(target string, lazy bool) error
}

func NewNodeMounter

func NewNodeMounter() Mounter

type NodeMounter

type NodeMounter struct {
	mount.Interface
}

func (*NodeMounter) FuseUnmount added in v0.9.4

func (mounter *NodeMounter) FuseUnmount(target string, lazy bool) error

FuseUnmount unmounts the fuse target.

func (*NodeMounter) GetDeviceName

func (mounter *NodeMounter) GetDeviceName(mountPath string) (string, int, error)

func (*NodeMounter) GetMountRefs

func (mounter *NodeMounter) GetMountRefs(pathname string) ([]string, error)

GetMountRefs finds all mount references to pathname, returns a list of paths. Path could be a mountpoint or a normal directory (for bind mount).

func (*NodeMounter) IsLikelyNotMountPoint

func (mounter *NodeMounter) IsLikelyNotMountPoint(file string) (bool, error)

IsLikelyNotMountPoint determines if a directory is not a mountpoint. It is fast but not necessarily ALWAYS correct. If the path is in fact a bind mount from one part of a mount to another it will not be detected. It also can not distinguish between mountpoints and symbolic links. mkdir /tmp/a /tmp/b; mount --bind /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b") will return true. When in fact /tmp/b is a mount point. If this situation is of interest to you, don't use this function...

func (*NodeMounter) List

func (mounter *NodeMounter) List() ([]mount.MountPoint, error)

List returns a list of all mounted filesystems.

func (*NodeMounter) Mount

func (mounter *NodeMounter) Mount(source string, target string, fstype string, options []string) error

Mount mounts source to target as fstype with given options. 'source' and 'fstype' must be an empty string in case it's not required, e.g. for remount, or for auto filesystem type, where kernel handles fstype for you. The mount 'options' is a list of options, currently come from mount(8), e.g. "ro", "remount", "bind", etc. If no more option is required, call Mount with an empty string list or nil.

func (*NodeMounter) MountSensitive

func (mounter *NodeMounter) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error

MountSensitive is the same as Mount() but this method allows sensitiveOptions to be passed in a separate parameter from the normal mount options and ensures the sensitiveOptions are never logged. This method should be used by callers that pass sensitive material (like passwords) as mount options.

func (*NodeMounter) MountSensitive2

func (mounter *NodeMounter) MountSensitive2(source string, sourceMasked string, target string, fstype string, options []string, sensitiveOptions []string, stdinValues []string) error

func (*NodeMounter) UnmountLazy added in v0.10.1

func (mounter *NodeMounter) UnmountLazy(target string, lazy bool) error

UnmountLazy unmounts the target.

Jump to

Keyboard shortcuts

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