整個流程大致以下:java 建立 thinpoolweb // This is theprogrammatic example of "dmsetup create"docker funccreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSizeuint32) error {centos ...bash 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)app }學習 ...ui }spa 至關於執行下面的操做: # dmsetup create docker-8:1-696417-pool--table ‗0 419430400 thin-pool 7:1 7:0 128 32768 1 skip_block_zeroing‘ # dmsetup table docker-8:1-696417-pool 0 419430400thin-pool 7:1 7:0 128 32768 1 skip_block_zeroing 建立 BaseImage 實際上,thin-provisionedvolume 分兩步,首先是發送一個消息給 pool,建立一個 volume。而後激活 volume。只有 activated 的 volume,才能在 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) } 至關於執行下面的操做: #dmsetup message/dev/mapper/ docker-8:1-696417-pool 0 "create_thin 0" 能夠看到 base 的 device_id 爲 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) } 至關於執行下面的操做: #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 只有 activated 的 volume,才能在 dmsetup info 的輸出中看到。 Devicemapper 的基本操做 Driver的基本操做 ///清除 thin pool func (d *Driver)Cleanup() ///當加載新鏡像時,添加一個新 thin volume,id 爲 containerid 或 imageid func (d *Driver) Create(id, parent string) ///掛載 thin volume 到/var/lib/docker/devicemapper/mnt/$id 目錄下(docker start) func (d *Driver) Get(id, mountLabelstring) ///從/var/lib/docker/devicemapper/mnt/$id目錄 umount thinvolume(docker stop) func (d *Driver) Put(id string) ///刪除 volume(真正刪除) func (d *Driver)Remove(id string) Thinpool 的基本操做 ///在 thin pool 中建立一個新的 snapshot volume func (devices*DeviceSet) AddDevice(hash, baseHash string) ///刪除 thin volume(釋放空間,刪除(remove+delete)thin volume) func (devices *DeviceSet) DeleteDevice(hashstring) /// 將 thin volume 從 /var/lib/docker/devicemapper/mnt/$id umount, deactivate(remove )thinvolume(don't delete) func (devices*DeviceSet) UnmountDevice(hash string) ///activate thin volume ,而後 mount 到/var/lib/docker/devicemapper/mnt/$idfunc (devices *DeviceSet) MountDevice(hash, path, mountLabel string) ///thin pool 的統計信息(docker info) func (devices*DeviceSet) Status() *Status ///thin pool 初始化 funcNewDeviceSet(root string, doInit bool, options []string) Devmapper接口 devmapper/devmapper.go封裝了 OS 層的 thin volume 的基本操做。 ///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) 三者之間的調用關係以下: 查看 stop 的容器的文件系統 stop 的容器的 thin volume 都處於未激活(deactivate)狀態,咱們能夠將其激活(activate),而後查 看文件系統中的內容。 咱們建立一個容器,不啓動: # docker create --name="yy1" centos /bin/bash 93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9 metadata 下面新增兩個目錄: # ls metadata/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e993f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9 -init 咱們能夠查看 thin volume 的信息 #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} 咱們來嘗試手動掛載 thin volume,首先 activate thin volume: # dmsetup create 93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9 -init --table "0 41943040 thin 253:0 4" 而後就能夠掛載該 thin volume 了: # mount /dev/mapper/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init mnt/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init # lsmnt/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9 -init/ id lost+foundrootfs deactivate thinvolume # umountmnt/93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01ad89f8e9-init # dmsetup remove93f595ea79a0420cc263d054d3e63b5ad1e4cc3da128167984a6ac01 |
更多精彩內容請關注:http://bbs.superwu.cn
關注超人學院微信二維碼:
關注超人學院java免費學習交流羣: