@@ -84,6 +84,7 @@ type DeviceSet struct {
8484 metadataDevice string
8585 doBlkDiscard bool
8686 thinpBlockSize uint32
87+ thinPoolDevice string
8788}
8889
8990type DiskUsage struct {
@@ -150,7 +151,10 @@ func (devices *DeviceSet) oldMetadataFile() string {
150151}
151152
152153func (devices * DeviceSet ) getPoolName () string {
153- return devices .devicePrefix + "-pool"
154+ if devices .thinPoolDevice == "" {
155+ return devices .devicePrefix + "-pool"
156+ }
157+ return devices .thinPoolDevice
154158}
155159
156160func (devices * DeviceSet ) getPoolDevName () string {
@@ -411,7 +415,22 @@ func (devices *DeviceSet) setupBaseImage() error {
411415 }
412416 }
413417
414- log .Debugf ("Initializing base device-manager snapshot" )
418+ if devices .thinPoolDevice != "" && oldInfo == nil {
419+ _ , transactionId , dataUsed , _ , _ , _ , err := devices .poolStatus ()
420+ if err != nil {
421+ return err
422+ }
423+ if dataUsed != 0 {
424+ return fmt .Errorf ("Unable to take ownership of thin-pool (%s) that already has used data blocks" ,
425+ devices .thinPoolDevice )
426+ }
427+ if transactionId != 0 {
428+ return fmt .Errorf ("Unable to take ownership of thin-pool (%s) with non-zero transaction Id" ,
429+ devices .thinPoolDevice )
430+ }
431+ }
432+
433+ log .Debugf ("Initializing base device-mapper thin volume" )
415434
416435 id := devices .NextDeviceId
417436
@@ -430,7 +449,7 @@ func (devices *DeviceSet) setupBaseImage() error {
430449 return err
431450 }
432451
433- log .Debugf ("Creating filesystem on base device-manager snapshot " )
452+ log .Debugf ("Creating filesystem on base device-mapper thin volume " )
434453
435454 if err = devices .activateDeviceIfNeeded (info ); err != nil {
436455 return err
@@ -605,7 +624,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
605624 devices .devicePrefix = fmt .Sprintf ("docker-%d:%d-%d" , major (sysSt .Dev ), minor (sysSt .Dev ), sysSt .Ino )
606625 log .Debugf ("Generated prefix: %s" , devices .devicePrefix )
607626
608- // Check for the existence of the device <prefix> -pool
627+ // Check for the existence of the thin -pool device
609628 log .Debugf ("Checking for existence of the pool '%s'" , devices .getPoolName ())
610629 info , err := devicemapper .GetInfo (devices .getPoolName ())
611630 if info == nil {
@@ -624,7 +643,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
624643 createdLoopback := false
625644
626645 // If the pool doesn't exist, create it
627- if info .Exists == 0 {
646+ if info .Exists == 0 && devices . thinPoolDevice == "" {
628647 log .Debugf ("Pool doesn't exist. Creating it." )
629648
630649 var (
@@ -988,8 +1007,10 @@ func (devices *DeviceSet) Shutdown() error {
9881007 }
9891008
9901009 devices .Lock ()
991- if err := devices .deactivatePool (); err != nil {
992- log .Debugf ("Shutdown deactivate pool , error: %s" , err )
1010+ if devices .thinPoolDevice == "" {
1011+ if err := devices .deactivatePool (); err != nil {
1012+ log .Debugf ("Shutdown deactivate pool , error: %s" , err )
1013+ }
9931014 }
9941015
9951016 devices .saveDeviceSetMetaData ()
@@ -1275,6 +1296,8 @@ func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error
12751296 devices .metadataDevice = val
12761297 case "dm.datadev" :
12771298 devices .dataDevice = val
1299+ case "dm.thinpooldev" :
1300+ devices .thinPoolDevice = strings .TrimPrefix (val , "/dev/mapper/" )
12781301 case "dm.blkdiscard" :
12791302 foundBlkDiscard = true
12801303 devices .doBlkDiscard , err = strconv .ParseBool (val )
@@ -1294,7 +1317,7 @@ func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error
12941317 }
12951318
12961319 // By default, don't do blk discard hack on raw devices, its rarely useful and is expensive
1297- if ! foundBlkDiscard && devices .dataDevice != "" {
1320+ if ! foundBlkDiscard && ( devices .dataDevice != "" || devices . thinPoolDevice != "" ) {
12981321 devices .doBlkDiscard = false
12991322 }
13001323
0 commit comments