mirror of https://github.com/docker/docs.git
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:
parent
b125f2334c
commit
8f343ea65a
|
@ -10,6 +10,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ type DevInfo struct {
|
||||||
Size uint64 `json:"size"`
|
Size uint64 `json:"size"`
|
||||||
TransactionId uint64 `json:"transaction_id"`
|
TransactionId uint64 `json:"transaction_id"`
|
||||||
Initialized bool `json:"initialized"`
|
Initialized bool `json:"initialized"`
|
||||||
|
devices *DeviceSetDM `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetaData struct {
|
type MetaData struct {
|
||||||
|
@ -32,6 +34,7 @@ type MetaData struct {
|
||||||
type DeviceSetDM struct {
|
type DeviceSetDM struct {
|
||||||
initialized bool
|
initialized bool
|
||||||
root string
|
root string
|
||||||
|
devicePrefix string
|
||||||
MetaData
|
MetaData
|
||||||
TransactionId uint64
|
TransactionId uint64
|
||||||
NewTransactionId uint64
|
NewTransactionId uint64
|
||||||
|
@ -47,7 +50,7 @@ func (info *DevInfo) Name() string {
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
hash = "base"
|
hash = "base"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("docker-%s", hash)
|
return fmt.Sprintf("%s-%s", info.devices.devicePrefix, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *DevInfo) DevName() string {
|
func (info *DevInfo) DevName() string {
|
||||||
|
@ -63,7 +66,7 @@ func (devices *DeviceSetDM) jsonFile() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSetDM) getPoolName() string {
|
func (devices *DeviceSetDM) getPoolName() string {
|
||||||
return "docker-pool"
|
return fmt.Sprintf("%s-pool", devices.devicePrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSetDM) getPoolDevName() string {
|
func (devices *DeviceSetDM) getPoolDevName() string {
|
||||||
|
@ -446,6 +449,7 @@ func (devices *DeviceSetDM) registerDevice(id int, hash string, size uint64) (*D
|
||||||
Size: size,
|
Size: size,
|
||||||
TransactionId: transaction,
|
TransactionId: transaction,
|
||||||
Initialized: false,
|
Initialized: false,
|
||||||
|
devices: devices,
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.Devices[hash] = info
|
devices.Devices[hash] = info
|
||||||
|
@ -520,6 +524,7 @@ func (devices *DeviceSetDM) loadMetaData() error {
|
||||||
|
|
||||||
for hash, d := range devices.Devices {
|
for hash, d := range devices.Devices {
|
||||||
d.Hash = hash
|
d.Hash = hash
|
||||||
|
d.devices = devices
|
||||||
|
|
||||||
if d.DeviceId >= devices.nextFreeDevice {
|
if d.DeviceId >= devices.nextFreeDevice {
|
||||||
devices.nextFreeDevice = d.DeviceId + 1
|
devices.nextFreeDevice = d.DeviceId + 1
|
||||||
|
@ -873,7 +878,7 @@ func (devices *DeviceSetDM) SetInitialized(hash string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSetDM) ensureInit() error {
|
func (devices *DeviceSetDM) ensureInit() error {
|
||||||
if (!devices.initialized) {
|
if !devices.initialized {
|
||||||
devices.initialized = true
|
devices.initialized = true
|
||||||
err := devices.initDevmapper()
|
err := devices.initDevmapper()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -885,9 +890,16 @@ func (devices *DeviceSetDM) ensureInit() error {
|
||||||
|
|
||||||
func NewDeviceSetDM(root string) *DeviceSetDM {
|
func NewDeviceSetDM(root string) *DeviceSetDM {
|
||||||
SetDevDir("/dev")
|
SetDevDir("/dev")
|
||||||
|
|
||||||
|
base := filepath.Base(root)
|
||||||
|
if !strings.HasPrefix(base, "docker") {
|
||||||
|
base = "docker-" + base
|
||||||
|
}
|
||||||
|
|
||||||
devices := &DeviceSetDM{
|
devices := &DeviceSetDM{
|
||||||
initialized: false,
|
initialized: false,
|
||||||
root: root,
|
root: root,
|
||||||
|
devicePrefix: base,
|
||||||
}
|
}
|
||||||
devices.Devices = make(map[string]*DevInfo)
|
devices.Devices = make(map[string]*DevInfo)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue