README ¶
devicemapper - a storage backend based on Device Mapper
Theory of operation
The device mapper graphdriver uses the device mapper thin provisioning
module (dm-thinp) to implement CoW snapshots. The preferred model is
to have a thin pool reserved outside of Docker and passed to the
daemon via the --storage-opt dm.thinpooldev
option. Alternatively,
the device mapper graphdriver can setup a block device to handle this
for you via the --storage-opt dm.directlvm_device
option.
As a fallback if no thin pool is provided, loopback files will be
created. Loopback is very slow, but can be used without any
pre-configuration of storage. It is strongly recommended that you do
not use loopback in production. Ensure your Docker daemon has a
--storage-opt dm.thinpooldev
argument provided.
In loopback, a thin pool is created at /var/lib/docker/devicemapper
(devicemapper graph location) based on two block devices, one for
data and one for metadata. By default these block devices are created
automatically by using loopback mounts of automatically created sparse
files.
The default loopback files used are
/var/lib/docker/devicemapper/devicemapper/data
and
/var/lib/docker/devicemapper/devicemapper/metadata
. Additional metadata
required to map from docker entities to the corresponding devicemapper
volumes is stored in the /var/lib/docker/devicemapper/devicemapper/json
file (encoded as Json).
In order to support multiple devicemapper graphs on a system, the thin
pool will be named something like: docker-0:33-19478248-pool
, where
the 0:33
part is the minor/major device nr and 19478248
is the
inode number of the /var/lib/docker/devicemapper
directory.
On the thin pool, docker automatically creates a base thin device,
called something like docker-0:33-19478248-base
of a fixed
size. This is automatically formatted with an empty filesystem on
creation. This device is the base of all docker images and
containers. All base images are snapshots of this device and those
images are then in turn used as snapshots for other images and
eventually containers.
Information on docker info
As of docker-1.4.1, docker info
when using the devicemapper
storage driver
will display something like:
$ sudo docker info
[...]
Storage Driver: devicemapper
Pool Name: docker-253:1-17538953-pool
Pool Blocksize: 65.54 kB
Base Device Size: 107.4 GB
Data file: /dev/loop4
Metadata file: /dev/loop4
Data Space Used: 2.536 GB
Data Space Total: 107.4 GB
Data Space Available: 104.8 GB
Metadata Space Used: 7.93 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.14 GB
Udev Sync Supported: true
Data loop file: /home/docker/devicemapper/devicemapper/data
Metadata loop file: /home/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.82-git (2013-10-04)
[...]
status items
Each item in the indented section under Storage Driver: devicemapper
are
status information about the driver.
Pool Name
name of the devicemapper pool for this driver.Pool Blocksize
tells the blocksize the thin pool was initialized with. This only changes on creation.Base Device Size
tells the maximum size of a container and imageData file
blockdevice file used for the devicemapper dataMetadata file
blockdevice file used for the devicemapper metadataData Space Used
tells how much ofData file
is currently usedData Space Total
tells max size theData file
Data Space Available
tells how much free space there is in theData file
. If you are using a loop device this will report the actual space available to the loop device on the underlying filesystem.Metadata Space Used
tells how much ofMetadata file
is currently usedMetadata Space Total
tells max size theMetadata file
Metadata Space Available
tells how much free space there is in theMetadata file
. If you are using a loop device this will report the actual space available to the loop device on the underlying filesystem.Udev Sync Supported
tells whether devicemapper is able to sync with Udev. Should betrue
.Data loop file
file attached toData file
, if loopback device is usedMetadata loop file
file attached toMetadata file
, if loopback device is usedLibrary Version
from the libdevmapper used
About the devicemapper options
The devicemapper backend supports some options that you can specify
when starting the docker daemon using the --storage-opt
flags.
This uses the dm
prefix and would be used something like dockerd --storage-opt dm.foo=bar
.
These options are currently documented both in the man
page and in the online
documentation.
If you add an options, update both the man
page and the documentation.
Documentation ¶
Index ¶
- func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error)
- func ProbeFsType(device string) (string, error)
- type DevStatus
- type DeviceSet
- func (devices *DeviceSet) AddDevice(hash, baseHash string, storageOpt map[string]string) error
- func (devices *DeviceSet) DataDevicePath() string
- func (devices *DeviceSet) DeleteDevice(hash string, syncDelete bool) error
- func (devices *DeviceSet) GetDeviceStatus(hash string) (*DevStatus, error)
- func (devices *DeviceSet) HasDevice(hash string) bool
- func (devices *DeviceSet) List() []string
- func (devices *DeviceSet) MetadataDevicePath() string
- func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error
- func (devices *DeviceSet) ResizePool(size int64) error
- func (devices *DeviceSet) Shutdown(home string) error
- func (devices *DeviceSet) Status() *Status
- func (devices *DeviceSet) UnmountDevice(hash, mountPath string) error
- type DiskUsage
- type Driver
- func (d *Driver) Cleanup() error
- func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error
- func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error
- func (d *Driver) Exists(id string) bool
- func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error)
- func (d *Driver) GetMetadata(id string) (map[string]string, error)
- func (d *Driver) Put(id string) error
- func (d *Driver) Remove(id string) error
- func (d *Driver) Status() [][2]string
- func (d *Driver) String() string
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error)
Init creates a driver with the given home and the set of options.
func ProbeFsType ¶
ProbeFsType returns the filesystem name for the given device id.
Types ¶
type DevStatus ¶
type DevStatus struct { // DeviceID is the id of the device. DeviceID int // Size is the size of the filesystem. Size uint64 // TransactionID is a unique integer per device set used to identify an operation on the file system, this number is incremental. TransactionID uint64 // SizeInSectors indicates the size of the sectors allocated. SizeInSectors uint64 // MappedSectors indicates number of mapped sectors. MappedSectors uint64 // HighestMappedSector is the pointer to the highest mapped sector. HighestMappedSector uint64 }
DevStatus returns information about device mounted containing its id, size and sector information.
type DeviceSet ¶
type DeviceSet struct { sync.Mutex `json:"-"` // Protects all fields of DeviceSet and serializes calls into libdevmapper TransactionID uint64 `json:"-"` NextDeviceID int `json:"next_device_id"` BaseDeviceUUID string // save UUID of base device BaseDeviceFilesystem string // save filesystem of base device // contains filtered or unexported fields }
DeviceSet holds information about list of devices
func NewDeviceSet ¶
func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps []idtools.IDMap) (*DeviceSet, error)
NewDeviceSet creates the device set based on the options provided.
func (*DeviceSet) DataDevicePath ¶
DataDevicePath returns the path to the data storage for this deviceset, regardless of loopback or block device
func (*DeviceSet) DeleteDevice ¶
DeleteDevice will return success if device has been marked for deferred removal. If one wants to override that and want DeleteDevice() to fail if device was busy and could not be deleted, set syncDelete=true.
func (*DeviceSet) GetDeviceStatus ¶
GetDeviceStatus provides size, mapped sectors
func (*DeviceSet) MetadataDevicePath ¶
MetadataDevicePath returns the path to the metadata storage for this deviceset, regardless of loopback or block device
func (*DeviceSet) MountDevice ¶
MountDevice mounts the device if not already mounted.
func (*DeviceSet) ResizePool ¶
ResizePool increases the size of the pool.
func (*DeviceSet) UnmountDevice ¶
UnmountDevice unmounts the device and removes it from hash.
type DiskUsage ¶
type DiskUsage struct { // Used bytes on the disk. Used uint64 // Total bytes on the disk. Total uint64 // Available bytes on the disk. Available uint64 }
DiskUsage contains information about disk usage and is used when reporting Status of a device.
type Driver ¶
type Driver struct { *DeviceSet // contains filtered or unexported fields }
Driver contains the device set mounted and the home directory
func (*Driver) Create ¶
func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error
Create adds a device with a given id and the parent.
func (*Driver) CreateReadWrite ¶ added in v1.13.1
func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error
CreateReadWrite creates a layer that is writable for use as a container file system.
func (*Driver) Get ¶
func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error)
Get mounts a device with given id into the root filesystem
func (*Driver) GetMetadata ¶ added in v1.13.1
GetMetadata returns a map of information about the device.
func (*Driver) Remove ¶
Remove removes a device with a given id, unmounts the filesystem, and removes the mount point.
type Status ¶
type Status struct { // PoolName is the name of the data pool. PoolName string // DataFile is the actual block device for data. DataFile string // DataLoopback loopback file, if used. DataLoopback string // MetadataFile is the actual block device for metadata. MetadataFile string // MetadataLoopback is the loopback file, if used. MetadataLoopback string // Data is the disk used for data. Data DiskUsage // Metadata is the disk used for meta data. Metadata DiskUsage // BaseDeviceSize is base size of container and image BaseDeviceSize uint64 // BaseDeviceFS is backing filesystem. BaseDeviceFS string // SectorSize size of the vector. SectorSize uint64 // UdevSyncSupported is true if sync is supported. UdevSyncSupported bool // DeferredRemoveEnabled is true then the device is not unmounted. DeferredRemoveEnabled bool // True if deferred deletion is enabled. This is different from // deferred removal. "removal" means that device mapper device is // deactivated. Thin device is still in thin pool and can be activated // again. But "deletion" means that thin device will be deleted from // thin pool and it can't be activated again. DeferredDeleteEnabled bool DeferredDeletedDeviceCount uint MinFreeSpace uint64 }
Status returns the information about the device.