devmapper

package
v1.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

README

Devmapper snapshotter

Devmapper is a containerd snapshotter plugin that stores snapshots in ext4-formatted filesystem images in a devicemapper thin pool.

Setup

To make it work you need to prepare thin-pool in advance and update containerd's configuration file. This file is typically located at /etc/containerd/config.toml.

Here's minimal sample entry that can be made in the configuration file:

[plugins]
  ...
  [plugins.devmapper]
    pool_name = "containerd-pool"
    base_image_size = "128MB"
  ...

The following configuration flags are supported:

  • root_path - a directory where the metadata will be available (if empty default location for containerd plugins will be used)
  • pool_name - a name to use for the devicemapper thin pool. Pool name should be the same as in /dev/mapper/ directory
  • base_image_size - defines how much space to allocate when creating the base device

Pool name and base image size are required snapshotter parameters.

Run

Give it a try with the following commands:

ctr images pull --snapshotter devmapper docker.io/library/hello-world:latest
ctr run --snapshotter devmapper docker.io/library/hello-world:latest test

Requirements

The devicemapper snapshotter requires dmsetup (>= 1.02.110) command line tool to be installed and available on your computer. On Ubuntu, it can be installed with apt-get install dmsetup command.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

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
	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) 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 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

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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