|
@@ -84,6 +84,7 @@ type DeviceSet struct {
|
|
|
metadataDevice string
|
|
|
doBlkDiscard bool
|
|
|
thinpBlockSize uint32
|
|
|
+ thinPoolDevice string
|
|
|
}
|
|
|
|
|
|
type DiskUsage struct {
|
|
@@ -150,7 +151,10 @@ func (devices *DeviceSet) oldMetadataFile() string {
|
|
|
}
|
|
|
|
|
|
func (devices *DeviceSet) getPoolName() string {
|
|
|
- return devices.devicePrefix + "-pool"
|
|
|
+ if devices.thinPoolDevice == "" {
|
|
|
+ return devices.devicePrefix + "-pool"
|
|
|
+ }
|
|
|
+ return devices.thinPoolDevice
|
|
|
}
|
|
|
|
|
|
func (devices *DeviceSet) getPoolDevName() string {
|
|
@@ -411,7 +415,22 @@ func (devices *DeviceSet) setupBaseImage() error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.Debugf("Initializing base device-manager snapshot")
|
|
|
+ if devices.thinPoolDevice != "" && oldInfo == nil {
|
|
|
+ _, transactionId, dataUsed, _, _, _, err := devices.poolStatus()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if dataUsed != 0 {
|
|
|
+ return fmt.Errorf("Unable to take ownership of thin-pool (%s) that already has used data blocks",
|
|
|
+ devices.thinPoolDevice)
|
|
|
+ }
|
|
|
+ if transactionId != 0 {
|
|
|
+ return fmt.Errorf("Unable to take ownership of thin-pool (%s) with non-zero transaction Id",
|
|
|
+ devices.thinPoolDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Debugf("Initializing base device-mapper thin volume")
|
|
|
|
|
|
id := devices.NextDeviceId
|
|
|
|
|
@@ -430,7 +449,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- log.Debugf("Creating filesystem on base device-manager snapshot")
|
|
|
+ log.Debugf("Creating filesystem on base device-mapper thin volume")
|
|
|
|
|
|
if err = devices.activateDeviceIfNeeded(info); err != nil {
|
|
|
return err
|
|
@@ -605,7 +624,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
|
|
devices.devicePrefix = fmt.Sprintf("docker-%d:%d-%d", major(sysSt.Dev), minor(sysSt.Dev), sysSt.Ino)
|
|
|
log.Debugf("Generated prefix: %s", devices.devicePrefix)
|
|
|
|
|
|
- // Check for the existence of the device <prefix>-pool
|
|
|
+ // Check for the existence of the thin-pool device
|
|
|
log.Debugf("Checking for existence of the pool '%s'", devices.getPoolName())
|
|
|
info, err := devicemapper.GetInfo(devices.getPoolName())
|
|
|
if info == nil {
|
|
@@ -624,7 +643,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
|
|
createdLoopback := false
|
|
|
|
|
|
// If the pool doesn't exist, create it
|
|
|
- if info.Exists == 0 {
|
|
|
+ if info.Exists == 0 && devices.thinPoolDevice == "" {
|
|
|
log.Debugf("Pool doesn't exist. Creating it.")
|
|
|
|
|
|
var (
|
|
@@ -988,8 +1007,10 @@ func (devices *DeviceSet) Shutdown() error {
|
|
|
}
|
|
|
|
|
|
devices.Lock()
|
|
|
- if err := devices.deactivatePool(); err != nil {
|
|
|
- log.Debugf("Shutdown deactivate pool , error: %s", err)
|
|
|
+ if devices.thinPoolDevice == "" {
|
|
|
+ if err := devices.deactivatePool(); err != nil {
|
|
|
+ log.Debugf("Shutdown deactivate pool , error: %s", err)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
devices.saveDeviceSetMetaData()
|
|
@@ -1275,6 +1296,8 @@ func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error
|
|
|
devices.metadataDevice = val
|
|
|
case "dm.datadev":
|
|
|
devices.dataDevice = val
|
|
|
+ case "dm.thinpooldev":
|
|
|
+ devices.thinPoolDevice = strings.TrimPrefix(val, "/dev/mapper/")
|
|
|
case "dm.blkdiscard":
|
|
|
foundBlkDiscard = true
|
|
|
devices.doBlkDiscard, err = strconv.ParseBool(val)
|
|
@@ -1294,7 +1317,7 @@ func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error
|
|
|
}
|
|
|
|
|
|
// By default, don't do blk discard hack on raw devices, its rarely useful and is expensive
|
|
|
- if !foundBlkDiscard && devices.dataDevice != "" {
|
|
|
+ if !foundBlkDiscard && (devices.dataDevice != "" || devices.thinPoolDevice != "") {
|
|
|
devices.doBlkDiscard = false
|
|
|
}
|
|
|
|