Version: v1.7.6 Latest Latest

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 23 Imported by: 48




This section is empty.


View Source
var (
	// ErrNotFound represents an error returned when object not found in meta store
	ErrNotFound = errdefs.ErrNotFound
	// ErrAlreadyExists represents an error returned when object can't be duplicated in meta store
	ErrAlreadyExists = errdefs.ErrAlreadyExists


This section is empty.


type Config

type Config struct {
	// Device snapshotter root directory for metadata
	RootPath string `toml:"root_path"`

	// Name for 'thin-pool' device to be used by snapshotter (without /dev/mapper/ prefix)
	PoolName string `toml:"pool_name"`

	// Defines how much space to allocate when creating base image for container
	BaseImageSize      string `toml:"base_image_size"`
	BaseImageSizeBytes uint64 `toml:"-"`

	// Flag to async remove device using Cleanup() callback in snapshots GC
	AsyncRemove bool `toml:"async_remove"`

	// Whether to discard blocks when removing a thin device.
	DiscardBlocks bool `toml:"discard_blocks"`

	// Defines file system to use for snapshout device mount. Defaults to "ext4"
	FileSystemType fsType `toml:"fs_type"`

	// Defines optional file system options passed through config file
	FsOptions string `toml:"fs_options"`

Config represents device mapper configuration loaded from file. Size units can be specified in human-readable string format (like "32KIB", "32GB", "32Tb")

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads devmapper configuration file from disk in TOML format

func (*Config) Validate

func (c *Config) Validate() error

Validate makes sure configuration fields are valid

type DeviceInfo

type DeviceInfo struct {
	// DeviceID is a 24-bit number assigned to a device within thin-pool device
	DeviceID uint32 `json:"device_id"`
	// Size is a thin device size
	Size uint64 `json:"size"`
	// Name is a device name to be used in /dev/mapper/
	Name string `json:"name"`
	// ParentName is a name of parent device (if snapshot)
	ParentName string `json:"parent_name"`
	// State represents current device state
	State DeviceState `json:"state"`
	// Error details if device state change failed
	Error string `json:"error"`

DeviceInfo represents metadata for thin device within thin-pool

type DeviceInfoCallback

type DeviceInfoCallback func(deviceInfo *DeviceInfo) error

DeviceInfoCallback is a callback used for device updates

type DeviceState

type DeviceState int

DeviceState represents current devmapper device state reflected in meta store

const (
	// Unknown means that device just allocated and no operations were performed
	Unknown DeviceState = iota
	// Creating means that device is going to be created
	// Created means that devices successfully created
	// Activating means that device is going to be activated
	// Activated means that device successfully activated
	// Suspending means that device is going to be suspended
	// Suspended means that device successfully suspended
	// Resuming means that device is going to be resumed from suspended state
	// Resumed means that device successfully resumed
	// Deactivating means that device is going to be deactivated
	// Deactivated means that device successfully deactivated
	// Removing means that device is going to be removed
	// Removed means that device successfully removed but not yet deleted from meta store
	// Faulty means that the device is errored and the snapshotter failed to rollback it

func (DeviceState) String

func (s DeviceState) String() string

type PoolDevice

type PoolDevice struct {
	// contains filtered or unexported fields

PoolDevice ties together data and metadata volumes, represents thin-pool and manages volumes, snapshots and device ids.

func NewPoolDevice

func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error)

NewPoolDevice creates new thin-pool from existing data and metadata volumes. If pool 'poolName' already exists, it'll be reloaded with new parameters.

func (*PoolDevice) Close

func (p *PoolDevice) Close() error

Close closes pool device (thin-pool will not be removed)

func (*PoolDevice) CreateSnapshotDevice

func (p *PoolDevice) CreateSnapshotDevice(ctx context.Context, deviceName string, snapshotName string, virtualSizeBytes uint64) (retErr error)

CreateSnapshotDevice creates and activates new thin-device from parent thin-device (makes snapshot)

func (*PoolDevice) CreateThinDevice

func (p *PoolDevice) CreateThinDevice(ctx context.Context, deviceName string, virtualSizeBytes uint64) (retErr error)

CreateThinDevice creates new devmapper thin-device with given name and size. Device ID for thin-device will be allocated from metadata store. If allocation successful, device will be activated with /dev/mapper/<deviceName>

func (*PoolDevice) DeactivateDevice

func (p *PoolDevice) DeactivateDevice(ctx context.Context, deviceName string, deferred, withForce bool) error

DeactivateDevice deactivates thin device

func (*PoolDevice) GetUsage

func (p *PoolDevice) GetUsage(deviceName string) (int64, error)

GetUsage reports total size in bytes consumed by a thin-device. It relies on the number of used blocks reported by 'dmsetup status'. The output looks like:

device2: 0 204800 thin 17280 204799

Where 17280 is the number of used sectors

func (*PoolDevice) IsActivated

func (p *PoolDevice) IsActivated(deviceName string) bool

IsActivated returns true if thin-device is activated

func (*PoolDevice) IsLoaded

func (p *PoolDevice) IsLoaded(deviceName string) bool

IsLoaded returns true if thin-device is visible for dmsetup

func (*PoolDevice) MarkDeviceState added in v1.4.0

func (p *PoolDevice) MarkDeviceState(ctx context.Context, name string, state DeviceState) error

MarkDeviceState changes the device's state in metastore

func (*PoolDevice) RemoveDevice

func (p *PoolDevice) RemoveDevice(ctx context.Context, deviceName string) error

RemoveDevice completely wipes out thin device from thin-pool and frees it's device ID

func (*PoolDevice) RemovePool

func (p *PoolDevice) RemovePool(ctx context.Context) error

RemovePool deactivates all child thin-devices and removes thin-pool device

func (*PoolDevice) ResumeDevice added in v1.3.7

func (p *PoolDevice) ResumeDevice(ctx context.Context, deviceName string) error

ResumeDevice resumes IO for the given device

func (*PoolDevice) SuspendDevice

func (p *PoolDevice) SuspendDevice(ctx context.Context, deviceName string) error

SuspendDevice flushes the outstanding IO and blocks the further IO

func (*PoolDevice) WalkDevices added in v1.4.0

func (p *PoolDevice) WalkDevices(ctx context.Context, cb func(info *DeviceInfo) error) error

WalkDevices iterates all devices in pool metadata

type PoolMetadata

type PoolMetadata struct {
	// contains filtered or unexported fields

PoolMetadata keeps device info for the given thin-pool device, generates next available device ids, and tracks devmapper transaction numbers

func NewPoolMetadata

func NewPoolMetadata(dbfile string) (*PoolMetadata, error)

NewPoolMetadata creates new or opens existing pool metadata database

func (*PoolMetadata) AddDevice

func (m *PoolMetadata) AddDevice(ctx context.Context, info *DeviceInfo) error

AddDevice saves device info to database.

func (*PoolMetadata) ChangeDeviceState added in v1.4.0

func (m *PoolMetadata) ChangeDeviceState(ctx context.Context, name string, state DeviceState) error

ChangeDeviceState changes the device state given the device name in devices bucket.

func (*PoolMetadata) Close

func (m *PoolMetadata) Close() error

Close closes metadata store

func (*PoolMetadata) GetDevice

func (m *PoolMetadata) GetDevice(ctx context.Context, name string) (*DeviceInfo, error)

GetDevice retrieves device info by name from database

func (*PoolMetadata) GetDeviceNames

func (m *PoolMetadata) GetDeviceNames(ctx context.Context) ([]string, error)

GetDeviceNames retrieves the list of device names currently stored in database

func (*PoolMetadata) MarkFaulty

func (m *PoolMetadata) MarkFaulty(ctx context.Context, name string) error

MarkFaulty marks the given device and corresponding devmapper device ID as faulty. The snapshotter might attempt to recreate a device in 'Faulty' state with another devmapper ID in subsequent calls, and in case of success its status will be changed to 'Created' or 'Activated'. The devmapper dev ID will remain in 'deviceFaulty' state until manually handled by a user.

func (*PoolMetadata) RemoveDevice

func (m *PoolMetadata) RemoveDevice(ctx context.Context, name string) error

RemoveDevice removes device info from store.

func (*PoolMetadata) UpdateDevice

func (m *PoolMetadata) UpdateDevice(ctx context.Context, name string, fn DeviceInfoCallback) error

UpdateDevice updates device info in metadata store. The callback should be used to indicate whether device info update was successful or not. An error returned from the callback will rollback the update transaction in the database. Name and Device ID are not allowed to change.

func (*PoolMetadata) WalkDevices

func (m *PoolMetadata) WalkDevices(ctx context.Context, cb func(info *DeviceInfo) error) error

WalkDevices walks all devmapper devices in metadata store and invokes the callback with device info. The provided callback function must not modify the bucket.

type Snapshotter

type Snapshotter struct {
	// contains filtered or unexported fields

Snapshotter implements containerd's snapshotter ( based on Linux device-mapper targets.

func NewSnapshotter

func NewSnapshotter(ctx context.Context, config *Config) (*Snapshotter, error)

NewSnapshotter creates new device mapper snapshotter. Internally it creates thin-pool device (or reloads if it's already exists) and initializes a database file for metadata.

func (*Snapshotter) Cleanup added in v1.4.0

func (s *Snapshotter) Cleanup(ctx context.Context) error

Cleanup cleans up all removed and unused resources

func (*Snapshotter) Close

func (s *Snapshotter) Close() error

Close releases devmapper snapshotter resources. All subsequent Close calls will be ignored.

func (*Snapshotter) Commit

func (s *Snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error

Commit marks an active snapshot as committed in meta store. Block device unmount operation captures snapshot changes by itself, so no additional actions needed within Commit operation.

func (*Snapshotter) Mounts

func (s *Snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error)

Mounts return the list of mounts for the active or view snapshot

func (*Snapshotter) Prepare

func (s *Snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error)

Prepare creates thin device for an active snapshot identified by key

func (*Snapshotter) Remove

func (s *Snapshotter) Remove(ctx context.Context, key string) error

Remove removes thin device and snapshot metadata by key

func (*Snapshotter) ResetPool

func (s *Snapshotter) ResetPool(ctx context.Context) error

ResetPool deactivates and deletes all thin devices in thin-pool. Used for cleaning pool after benchmarking.

func (*Snapshotter) Stat

func (s *Snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error)

Stat returns the info for an active or committed snapshot from store

func (*Snapshotter) Update

func (s *Snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error)

Update updates an existing snapshot info's data

func (*Snapshotter) Usage

func (s *Snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error)

Usage returns the resource usage of an active or committed snapshot excluding the usage of parent snapshots.

func (*Snapshotter) View

func (s *Snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error)

View creates readonly thin device for the given snapshot key

func (*Snapshotter) Walk

func (s *Snapshotter) Walk(ctx context.Context, fn snapshots.WalkFunc, fs ...string) error

Walk iterates through all metadata Info for the stored snapshots and calls the provided function for each.


Path Synopsis

Jump to

Keyboard shortcuts

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