The overall process is as follows:
650) this.width=650; "id=" aimg_1027 "src=" http://bbs.superwu.cn/data/attachment/forum/201506/05/ 152157z0b6rx7x68hidhdz.jpg "class=" Zoom "width=" "style=" border:none; "/>
Create Thinpool
This is theprogrammatic example of "Dmsetup create"
Funccreatepool (poolname string, datafile, Metadatafile *os. File, PoolBlockSizeuint32) error {
...
Params: = FMT. Sprintf ("%s%s%d 32768 1skip_block_zeroing", Metadatafile.name (), Datafile.name (), poolblocksize)
If Err: = task. AddTarget (0, size/512, "Thin-pool", params); Err! = Nil {return FMT. Errorf ("Can ' t addtarget%s", err)
}
...
}
is equivalent to performing the following actions:
# Dmsetup Create docker-8:1-696417-pool--table 0 419430400 thin-pool 7:1 7:0 1 32768 '
# Dmsetup Table Docker-8:1-696417-pool
0 419430400thin-pool 7:1 7:0 32768 1 skip_block_zeroing
Create baseimage
In fact, Thin-provisionedvolume in two steps, the first is to send a message to the pool and create a volume. Then activate
Volume Only activated volume can be seen in the output of Dmsetup info. (1) Creating a newthinly-provisioned volume
Funccreatedevice (poolname string, deviceId *int) error {
...
If err: =task. Setmessage (FMT. Sprintf ("Create_thin%d", *deviceid)); Err! = nil{return FMT. Errorf ("Can ' t set message%s", err)
}
is equivalent to performing the following actions:
#dmsetup message/dev/mapper/docker-8:1-696417-pool 0 "Create_thin 0"
|
# hexdump-c/var/lib/docker/devicemapper/metadata/base |
|
|
00000000 &NBSP, |
7b |
|
  
[] | TD width= "Style=" PADDING:4PX; >
  
5f 69 3a |
|
  
|{" device_id ": 0," | |
|
00000010 &NBSP, |
|
7a + |
|
3a |
  
34 |
  
|size ": 2147483648| |
|
00000020 |
30 |
2c 22 74 72 |
61 |
6e |
73 |
61 63 74 69 |
6f 6e 5f 69 |
|, "transaction_i| |
|
00000030 |
64 |
22 |
3a 31 |
2c |
22 |
69 |
6e |
69 74 69 61 |
6c |
69 |
7a 65 |
|d ": 1," initialize| |
|
00000040 |
64 |
22 |
3a 74 |
72 |
75 65 |
7d |
|
|
|
|
|d ": true}| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You can see that base's device_id is 0.
(2) activatedthinly-provisioned volumes
Funcactivatedevice (poolname string, name string, deviceId int, size UInt64) error {
...
Params: =fmt. Sprintf ("%s%d", poolname, DeviceId)
If Err: = task. AddTarget (0, size/512, "thin", params); Err! = Nil {return FMT. Errorf ("Can ' t addtarget%s", err)
}
is equivalent to performing the following actions:
#dmsetup createdocker-8:1-696417-base--table "0 41943040 thin/dev/mapper/docker-8:1-696417-pool 0"
#dmsetup table docker-8:1-696417-base 0 41943040 thin 253:0 0
Only activated volume can be seen in the output of Dmsetup info. Basic operation of Devicemapper
Driver The basic Operation
/// Clear Thin Pool
Func (d *driver) Cleanup ()
When loading a new image, add a new thin volume,id to Containerid or imageID func (d *driver) Create (ID, parent string)
Mount thin volume to/var/lib/docker/devicemapper/mnt/$id directory (Docker start) func (d *driver) Get (ID, mountlabelstring)
From/var/lib/docker/devicemapper/mnt/$id directory Umount thinvolume (Docker stop) func (d *driver) Put (ID string)
/// Delete Volume ( true Delete )
Func (d *driver) Remove (ID string)
Thinpool The basic Operation
/// in the Thin Pool to create a new Snapshot Volume
Func (Devices*deviceset) AddDevice (hash, basehash string)
Delete Thin volume (free space, delete (remove+delete) thin volume) func (Devices *deviceset) Deletedevice (hashstring)
Thin volume from/var/lib/docker/devicemapper/mnt/$id umount, deactivate (remove) Thinvolume (don ' t delete)
Func (Devices*deviceset) Unmountdevice (hash string)
Activate thin volume, then mount to/var/lib/docker/devicemapper/mnt/$idfunc (Devices *deviceset) mountdevice (hash, path , Mountlabel String)
///thin Pool the statistical information (Docker info)
Func (Devices*deviceset) Status () *status
///thin Pool Initialize
Funcnewdeviceset (Root string, doinit bool, options []string)
Devmapper Interface
Devmapper/devmapper.go encapsulates the OS layer of Thin Volume the basic operation.
Dmsetup suspend
Funcsuspenddevice (name string)
Dmsetup Resume
Funcresumedevice (name string)
Messagecreate_thin
Funccreatedevice (poolname string, deviceId *int)
Message Delete
Funcdeletedevice (poolname string, deviceId int)
Dmsetup Remove
Funcremovedevice (name string)
Dmsetup Create
Funcactivatedevice (poolname string, name string, deviceId int, size UInt64)
Message ' Create_snap '
Funccreatesnapdevice (poolname string, DeviceId *int, baseName string, Basedeviceidint)
The call relationships between the three are as follows:
650) this.width=650; "id=" aimg_1028 "src=" http://bbs.superwu.cn/data/attachment/forum/201506/05/ 152157iu095b5c8t2pf05b.jpg "class=" Zoom "width=" "style=" border:none; "/>
View the file system of the Stop container
The thin volume of the Stop container is in an inactive (deactivate) state, and we can activate it (activate) and view the contents of the file system.
We create a container that does not start:
# Docker Create--name= "Yy1" Centos/bin/bash 93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9
Metadata two new directories are added below:
# ls metadata/ 93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e993f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01a D89f8e9-init
we can view Thin Volume of information
#cat metadata/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9{"device_id": 5, "size": 21474836480 , "transaction_id": 8, "initialized": false}
# catmetadata/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init{"device_id": 4, "size" : 21474836480, "transaction_id": 7, "initialized": false}
Let's try to mount the thin volume manually, first activate thin volume:
#
Dmsetup
Create
93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init
--table "0
41943040 Thin 253:0 4 "
Then you can mount the thin volume:
#
Mount
/dev/mapper/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init mnt/ 93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init
# lsmnt/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init/id Lost+foundrootfs
Deactivate Thinvolume
# Umountmnt/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init
# Dmsetup REMOVE93F595EA79A0420CC263D054D3E63B5AD1E4CC3DA128167984A6AC01
|