зеркало из https://github.com/microsoft/docker.git
devmapper: Construct initial device Id map from device meta files
When docker starts, build a used/free Device Id map from the per device meta files we already have. These meta files have the data which device Ids are in use. Parse these files and mark device as used in the map. Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
Родитель
4d39e056aa
Коммит
39dc7829de
|
@ -303,6 +303,65 @@ func (devices *DeviceSet) lookupDevice(hash string) (*DevInfo, error) {
|
|||
return info, nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) deviceFileWalkFunction(path string, finfo os.FileInfo) error {
|
||||
|
||||
// Skip some of the meta files which are not device files.
|
||||
if strings.HasSuffix(finfo.Name(), ".migrated") {
|
||||
log.Debugf("Skipping file %s", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
if finfo.Name() == deviceSetMetaFile {
|
||||
log.Debugf("Skipping file %s", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("Loading data for file %s", path)
|
||||
|
||||
hash := finfo.Name()
|
||||
if hash == "base" {
|
||||
hash = ""
|
||||
}
|
||||
|
||||
dinfo := devices.loadMetadata(hash)
|
||||
if dinfo == nil {
|
||||
return fmt.Errorf("Error loading device metadata file %s", hash)
|
||||
}
|
||||
|
||||
if dinfo.DeviceId > MaxDeviceId {
|
||||
log.Errorf("Warning: Ignoring Invalid DeviceId=%d", dinfo.DeviceId)
|
||||
return nil
|
||||
}
|
||||
|
||||
devices.Lock()
|
||||
devices.markDeviceIdUsed(dinfo.DeviceId)
|
||||
devices.Unlock()
|
||||
|
||||
log.Debugf("Added deviceId=%d to DeviceIdMap", dinfo.DeviceId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) constructDeviceIdMap() error {
|
||||
log.Debugf("[deviceset] constructDeviceIdMap()")
|
||||
defer log.Debugf("[deviceset] constructDeviceIdMap() END")
|
||||
|
||||
var scan = func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
log.Debugf("Can't walk the file %s", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip any directories
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return devices.deviceFileWalkFunction(path, info)
|
||||
}
|
||||
|
||||
return filepath.Walk(devices.metadataDir(), scan)
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) unregisterDevice(id int, hash string) error {
|
||||
log.Debugf("unregisterDevice(%v, %v)", id, hash)
|
||||
info := &DevInfo{
|
||||
|
@ -429,6 +488,10 @@ func (devices *DeviceSet) initMetaData() error {
|
|||
}
|
||||
|
||||
devices.TransactionId = transactionId
|
||||
|
||||
if err := devices.constructDeviceIdMap(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче