1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

devmapper: Base the device-mapper names on the root dir name

This means the default is "docker-*", but for tests we get separate
prefixes for each test.
This commit is contained in:
Alexander Larsson 2013-09-05 15:32:57 +02:00 committed by Victor Vieux
parent b125f2334c
commit 8f343ea65a

View file

@ -10,6 +10,7 @@ import (
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
)
@ -18,11 +19,12 @@ const defaultMetaDataLoopbackSize int64 = 2 * 1024 * 1024 * 1024
const defaultBaseFsSize uint64 = 10 * 1024 * 1024 * 1024
type DevInfo struct {
Hash string `json:"-"`
DeviceId int `json:"device_id"`
Size uint64 `json:"size"`
TransactionId uint64 `json:"transaction_id"`
Initialized bool `json:"initialized"`
Hash string `json:"-"`
DeviceId int `json:"device_id"`
Size uint64 `json:"size"`
TransactionId uint64 `json:"transaction_id"`
Initialized bool `json:"initialized"`
devices *DeviceSetDM `json:"-"`
}
type MetaData struct {
@ -31,7 +33,8 @@ type MetaData struct {
type DeviceSetDM struct {
initialized bool
root string
root string
devicePrefix string
MetaData
TransactionId uint64
NewTransactionId uint64
@ -47,7 +50,7 @@ func (info *DevInfo) Name() string {
if hash == "" {
hash = "base"
}
return fmt.Sprintf("docker-%s", hash)
return fmt.Sprintf("%s-%s", info.devices.devicePrefix, hash)
}
func (info *DevInfo) DevName() string {
@ -63,7 +66,7 @@ func (devices *DeviceSetDM) jsonFile() string {
}
func (devices *DeviceSetDM) getPoolName() string {
return "docker-pool"
return fmt.Sprintf("%s-pool", devices.devicePrefix)
}
func (devices *DeviceSetDM) getPoolDevName() string {
@ -446,6 +449,7 @@ func (devices *DeviceSetDM) registerDevice(id int, hash string, size uint64) (*D
Size: size,
TransactionId: transaction,
Initialized: false,
devices: devices,
}
devices.Devices[hash] = info
@ -520,6 +524,7 @@ func (devices *DeviceSetDM) loadMetaData() error {
for hash, d := range devices.Devices {
d.Hash = hash
d.devices = devices
if d.DeviceId >= devices.nextFreeDevice {
devices.nextFreeDevice = d.DeviceId + 1
@ -873,7 +878,7 @@ func (devices *DeviceSetDM) SetInitialized(hash string) error {
}
func (devices *DeviceSetDM) ensureInit() error {
if (!devices.initialized) {
if !devices.initialized {
devices.initialized = true
err := devices.initDevmapper()
if err != nil {
@ -885,9 +890,16 @@ func (devices *DeviceSetDM) ensureInit() error {
func NewDeviceSetDM(root string) *DeviceSetDM {
SetDevDir("/dev")
base := filepath.Base(root)
if !strings.HasPrefix(base, "docker") {
base = "docker-" + base
}
devices := &DeviceSetDM{
initialized: false,
root: root,
root: root,
devicePrefix: base,
}
devices.Devices = make(map[string]*DevInfo)