Documentation ¶
Index ¶
- Variables
- type Config
- type DeviceInfo
- type DeviceInfoCallback
- type DeviceState
- type PoolDevice
- func (p *PoolDevice) Close() error
- func (p *PoolDevice) CreateSnapshotDevice(ctx context.Context, deviceName string, snapshotName string, ...) (retErr error)
- func (p *PoolDevice) CreateThinDevice(ctx context.Context, deviceName string, virtualSizeBytes uint64) (retErr error)
- func (p *PoolDevice) DeactivateDevice(ctx context.Context, deviceName string, deferred, withForce bool) error
- func (p *PoolDevice) GetUsage(deviceName string) (int64, error)
- func (p *PoolDevice) IsActivated(deviceName string) bool
- func (p *PoolDevice) IsLoaded(deviceName string) bool
- func (p *PoolDevice) RemoveDevice(ctx context.Context, deviceName string) error
- func (p *PoolDevice) RemovePool(ctx context.Context) error
- func (p *PoolDevice) SuspendDevice(ctx context.Context, deviceName string) error
- type PoolMetadata
- func (m *PoolMetadata) AddDevice(ctx context.Context, info *DeviceInfo) error
- func (m *PoolMetadata) Close() error
- func (m *PoolMetadata) GetDevice(ctx context.Context, name string) (*DeviceInfo, error)
- func (m *PoolMetadata) GetDeviceNames(ctx context.Context) ([]string, error)
- func (m *PoolMetadata) MarkFaulty(ctx context.Context, name string) error
- func (m *PoolMetadata) RemoveDevice(ctx context.Context, name string) error
- func (m *PoolMetadata) UpdateDevice(ctx context.Context, name string, fn DeviceInfoCallback) error
- func (m *PoolMetadata) WalkDevices(ctx context.Context, cb func(info *DeviceInfo) error) error
- type Snapshotter
- func (s *Snapshotter) Close() error
- func (s *Snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error
- func (s *Snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error)
- func (s *Snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error)
- func (s *Snapshotter) Remove(ctx context.Context, key string) error
- func (s *Snapshotter) ResetPool(ctx context.Context) error
- func (s *Snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error)
- func (s *Snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error)
- func (s *Snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error)
- func (s *Snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error)
- func (s *Snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound represents an error returned when object not found in meta store ErrNotFound = errors.New("not found") // ErrAlreadyExists represents an error returned when object can't be duplicated in meta store ErrAlreadyExists = errors.New("object already exists") )
Functions ¶
This section is empty.
Types ¶
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:"-"` }
Config represents device mapper configuration loaded from file. Size units can be specified in human-readable string format (like "32KIB", "32GB", "32Tb")
func LoadConfig ¶
LoadConfig reads devmapper configuration file from disk in TOML format
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 Creating // Created means that devices successfully created Created // Activating means that device is going to be activated Activating // Activated means that device successfully activated Activated // Suspending means that device is going to be suspended Suspending // Suspended means that device successfully suspended Suspended // Resuming means that device is going to be resumed from suspended state Resuming // Resumed means that device successfully resumed Resumed // Deactivating means that device is going to be deactivated Deactivating // Deactivated means that device successfully deactivated Deactivated // Removing means that device is going to be removed Removing // Removed means that device successfully removed but not yet deleted from meta store Removed // Faulty means that the device is errored and the snapshotter failed to rollback it Faulty )
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) 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) SuspendDevice ¶
func (p *PoolDevice) SuspendDevice(ctx context.Context, deviceName string) error
SuspendDevice flushes the outstanding IO and blocks the further IO
type PoolMetadata ¶
type PoolMetadata struct {
// contains filtered or unexported fields
}
PoolMetadata keeps device info for the given thin-pool device, it also responsible for generating next available device ids and tracking devmapper transaction numbers
func NewPoolMetadata ¶
func NewPoolMetadata(dbfile string) (*PoolMetadata, error)
NewPoolMetadata creates new or open 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) 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 it's 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 (https://godoc.org/github.com/containerd/containerd/snapshots#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) Close ¶
func (s *Snapshotter) Close() error
Close releases devmapper snapshotter resources. All subsequent Close calls will be ignored.
func (*Snapshotter) Commit ¶
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) 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) 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 ¶
Usage returns the resource usage of an active or committed snapshot excluding the usage of parent snapshots.