mount

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 24 Imported by: 212

Documentation

Index

Constants

View Source
const HasBindMounts = runtime.GOOS != "darwin" && runtime.GOOS != "openbsd"

HasBindMounts This is a flag to conditionally disable code that relies on working bind-mount support, so such code is easier to find across codebase.

Variables

This section is empty.

Functions

func All

func All(mounts []Mount, target string) error

All mounts all the provided mounts to the provided target. If submounts are present, it assumes that parent mounts come before child mounts.

func AttachLoopDevice

func AttachLoopDevice(backingFile string) (string, error)

AttachLoopDevice attaches a specified backing file to a loop device

func CanonicalizePath

func CanonicalizePath(path string) (string, error)

CanonicalizePath makes path absolute and resolves symlinks in it. Path must exist.

func CleanupTempMounts

func CleanupTempMounts(flags int) (warnings []error, err error)

CleanupTempMounts all temp mounts and remove the directories

func DetachLoopDevice

func DetachLoopDevice(devices ...string) error

DetachLoopDevice detaches the provided loop devices

func GetUsernsFD

func GetUsernsFD(uidmap, gidmap string) (_usernsFD *os.File, _ error)

GetUsernsFD forks the current process and creates a user namespace using the specified mappings. Expected syntax of ID mapping parameter is "%d:%d:%d[,%d:%d:%d,...]"

func IDMapMount

func IDMapMount(source, target string, usernsFd int) (err error)

IDMapMount clones the mount at source to target, applying GID/UID idmapping of the user namespace for target path

func IDMapMountWithAttrs added in v2.0.7

func IDMapMountWithAttrs(source, target string, usernsFd int, attrSet uint64, attrClr uint64) (err error)

IDMapMountWithAttrs clones the mount at source to target with the provided mount options and idmapping of the user namespace.

func SetTempMountLocation

func SetTempMountLocation(root string) error

SetTempMountLocation sets the temporary mount location

func SetupLoop added in v2.2.0

func SetupLoop(backingFile string, param LoopParams) (*os.File, error)

SetupLoop looks for (and possibly creates) a free loop device, and then attaches backingFile to it.

When autoclear is true, caller should take care to close it when done with the loop device. The loop device file handle keeps loFlagsAutoclear in effect and we rely on it to clean up the loop device. If caller closes the file handle after mounting the device, kernel will clear the loop device after it is umounted. Otherwise the loop device is cleared when the file handle is closed.

When autoclear is false, caller should be responsible to remove the loop device when done with it.

Upon success, the file handle to the loop device is returned.

func ToProto

func ToProto(mounts []Mount) []*types.Mount

ToProto converts from Mount to the containerd APIs protobuf definition of a Mount.

func Unmount

func Unmount(target string, flags int) error

Unmount the provided mount path with the flags

func UnmountAll

func UnmountAll(mount string, flags int) error

UnmountAll repeatedly unmounts the given mount point until there are no mounts remaining (EINVAL is returned by mount), which is useful for undoing a stack of mounts on the same mount point. UnmountAll all is noop when the first argument is an empty string. This is done when the containerd client did not specify any rootfs mounts (e.g. because the rootfs is managed outside containerd) UnmountAll is noop when the mount path does not exist.

func UnmountMounts

func UnmountMounts(mounts []Mount, target string, flags int) error

UnmountMounts unmounts all the mounts under a target in the reverse order of the mounts array provided.

func UnmountRecursive

func UnmountRecursive(target string, flags int) error

UnmountRecursive unmounts the target and all mounts underneath, starting with the deepest mount first.

func WithReadonlyTempMount

func WithReadonlyTempMount(ctx context.Context, mounts []Mount, f func(root string) error) (err error)

WithReadonlyTempMount mounts the provided mounts to a temp dir as readonly, and pass the temp dir to f. The mounts are valid during the call to the f. Finally we will unmount and remove the temp dir regardless of the result of f.

func WithTempMount

func WithTempMount(ctx context.Context, mounts []Mount, f func(root string) error) (err error)

WithTempMount mounts the provided mounts to a temp dir, and pass the temp dir to f. The mounts are valid during the call to the f. Finally we will unmount and remove the temp dir regardless of the result of f.

NOTE: The volatile option of overlayfs doesn't allow to mount again using the same upper / work dirs. Since it's a temp mount, avoid using that option here if found.

func WithTemporary added in v2.2.0

func WithTemporary(o *ActivateOptions)

WithTemporary indicates that the activation is for temporary access of the mounts. All mounts should be performed and a single bind mount is returned to access to the mounted filesystem.

Types

type ActivateOpt added in v2.2.0

type ActivateOpt func(*ActivateOptions)

ActivateOpt is a function option for Activate

func WithAllowMountType added in v2.2.0

func WithAllowMountType(mountType string) ActivateOpt

WithAllowMountType indicates the mount types that the performer of the mounts will support. Even if there is a custom handler registered for the mount type to the mount handler, these mounts should not be performed unless required to support subsequent mounts.

To claim a transform, such as "format" or "mkfs", use WithAllowTransform instead.

func WithAllowTransform added in v2.4.0

func WithAllowTransform(transform string) ActivateOpt

WithAllowTransform indicates a mount transform, such as "format" or "mkfs", that the performer of the mounts will apply itself. The mount manager will not apply it unless it is required to support subsequent mounts.

The transform is named on its own, without the "/<mount-type>" suffix that appears in a mount type, so "format" matches the mount types "format/bind" and "format/mkdir/overlay" alike.

func WithLabels added in v2.2.0

func WithLabels(labels map[string]string) ActivateOpt

WithLabels specifies the labels to use for the stored activation info.

type ActivateOptions added in v2.2.0

type ActivateOptions struct {
	// Labels are the labels to use for the activation
	Labels map[string]string

	// Temporary specifies that the mount will be used temporarily
	// and all mounts should be performed
	Temporary bool

	// AllowMountTypes indicates that the caller will handle the specified
	// mount types and should not be handled by the mount manager even if
	// there is a configured handler for the type.
	AllowMountTypes []string

	// AllowTransforms indicates that the caller will apply the specified
	// mount transforms, such as "format" or "mkfs", and that the mount
	// manager should not apply them.
	//
	// Transforms are named without the "/<mount-type>" suffix that appears
	// in a mount type, so "format" here matches the mount types "format/bind"
	// and "format/mkdir/overlay" alike.
	AllowTransforms []string
}

ActivateOptions are used to modify activation behavior. Activate may be performed differently based on the different scenarios, such as mounting to view a filesystem or preparing a filesystem for a container that may have specific runtime requirements. The runtime for a container may also have different capabilities that would allow it to handle mounts which would not need to be handled by the mount manager.

type ActivationInfo added in v2.2.0

type ActivationInfo struct {
	Name string

	// Active are the mounts which was successfully mounted on activate
	Active []ActiveMount

	// System is the list of system mounts to access the filesystem root
	// This will always be non-empty and a bind mount will be created
	// and filled in here when all mounts are performed
	System []Mount
	Labels map[string]string
}

ActivationInfo represents the state of an active set of mounts being managed by a mount manager. The Name is unique and can be used to reference the activation from other resources.

type ActiveMount added in v2.2.0

type ActiveMount struct {
	Mount
	MountedAt *time.Time

	// MountPoint is the filesystem mount location
	MountPoint string

	// MountData is metadata used by the mount type which can also be used by
	// subsequent mounts.
	MountData map[string]string
}

ActiveMount represents a mount which has been mounted by a MountHandler or directly mounted by a mount manager.

type Handler added in v2.2.0

type Handler interface {
	Mount(context.Context, Mount, string, []ActiveMount) (ActiveMount, error)
	Unmount(context.Context, string) error
}

Handler is an interface for plugins to perform a mount which is managed by a MountManager. The MountManager will be responsible for associating mount types to MountHandlers and determining what the plugin should be used. The Handler interface is intended to be used for custom mount plugins and does not replace the mount calls for system mounts.

func LoopbackHandler added in v2.2.0

func LoopbackHandler() Handler

type Info

type Info = mountinfo.Info

Info reveals information about a particular mounted filesystem. This struct is populated from the content in the /proc/<pid>/mountinfo file.

func Lookup

func Lookup(dir string) (Info, error)

Lookup returns the mount info corresponds to the path.

type LoopParams

type LoopParams struct {
	// Loop device should forbid write
	Readonly bool
	// Loop device is automatically cleared by kernel when the
	// last opener closes it
	Autoclear bool
	// Use direct IO to access the loop backing file
	Direct bool
}

LoopParams parameters to control loop device setup

type Manager added in v2.2.0

Manager handles activating a mount array to be mounted by the system. It supports custom mount types that can be handled by plugins and don't need to be directly mountable. For example, this can be used to do device activation and setting up process or sockets such as for fuse or tcmu. The returned activation info will contain the remaining mounts which must be performed by the system, likely in a container's mount namespace. Any mounts or devices activated by the mount manager will be done outside the container's namespace.

type Mount

type Mount struct {
	// Type specifies the host-specific of the mount.
	Type string
	// Source specifies where to mount from. Depending on the host system, this
	// can be a source path or device.
	Source string
	// Target specifies an optional subdirectory as a mountpoint. It assumes that
	// the subdirectory exists in a parent mount.
	Target string
	// Options contains zero or more fstab-style mount options. Typically,
	// these are platform specific.
	//
	// These options are formatted as required for passing to mount(8) or
	// the legacy mount(2) API after joining with ",", so some values may
	// have option-specific quoting or escaping applied. For example,
	// SELinux contexts (which can contain commas) are quoted, and
	// overlayfs uses backslash escaping on paths.
	Options []string
}

Mount is the lingua franca of containerd. A mount represents a serialized mount syscall. Components either emit or consume mounts.

func FromProto

func FromProto(mm []*types.Mount) []Mount

FromProto converts from the protobuf definition types.Mount to Mount.

func RemoveIDMapOption added in v2.0.7

func RemoveIDMapOption(mounts []Mount) []Mount

RemoveIDMapOption copies and removes the uidmap/gidmap options on any of the mounts using it.

func RemoveVolatileOption

func RemoveVolatileOption(mounts []Mount) []Mount

RemoveVolatileOption copies and remove the volatile option for overlay type, since overlayfs doesn't allow to mount again using the same upper/work dirs.

REF: https://docs.kernel.org/filesystems/overlayfs.html#volatile-mount

TODO: Make this logic conditional once the kernel supports reusing overlayfs volatile mounts.

func (*Mount) Mount

func (m *Mount) Mount(target string) error

Mount to the provided target path.

func (*Mount) ReadOnly

func (m *Mount) ReadOnly() bool

ReadOnly reports whether this mount is read-only, deriving it from the mount type where the options alone don't say so.

type Transformer added in v2.2.0

type Transformer interface {
	Transform(context.Context, Mount, []ActiveMount) (Mount, error)
}

Transformer is an interface that can make changes to the mount based on the previous mount state. This can be used to update the values of the mount, such as with formatting, or for mount initialization that do not require runtime state, such as device formatting.

Directories

Path Synopsis
Package manager is used to manage mounts in a bolt database, normally backed by a tempfs.
Package manager is used to manage mounts in a bolt database, normally backed by a tempfs.

Jump to

Keyboard shortcuts

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