devmapper: Remove transaction Id update from saveMetaData()
Right now saveMetaData() is kind of little overloaded function. It is supposed to save file metadata to disk. But in addition if user has bumped up NewTransactionId before calling saveMetaData(), then it will also update the transaction ID in pool. Keep saveMetaData() simple and let it just save the file. Any update of pool transaction ID is done inline in the code which needs it. Also create an helper function updatePoolTransactionId() to update pool transaction Id. Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
parent
004d8b9b33
commit
0db6cc85ed
1 changed files with 19 additions and 7 deletions
|
@ -204,6 +204,16 @@ func (devices *DeviceSet) allocateTransactionId() uint64 {
|
|||
return devices.NewTransactionId
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) updatePoolTransactionId() error {
|
||||
if devices.NewTransactionId != devices.TransactionId {
|
||||
if err := devicemapper.SetTransactionId(devices.getPoolDevName(), devices.TransactionId, devices.NewTransactionId); err != nil {
|
||||
return fmt.Errorf("Error setting devmapper transaction ID: %s", err)
|
||||
}
|
||||
devices.TransactionId = devices.NewTransactionId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) removeMetadata(info *DevInfo) error {
|
||||
if err := os.RemoveAll(devices.metadataFile(info)); err != nil {
|
||||
return fmt.Errorf("Error removing metadata file %s: %s", devices.metadataFile(info), err)
|
||||
|
@ -246,13 +256,6 @@ func (devices *DeviceSet) saveMetadata(info *DevInfo) error {
|
|||
if err := devices.writeMetaFile(jsonData, devices.metadataFile(info)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if devices.NewTransactionId != devices.TransactionId {
|
||||
if err = devicemapper.SetTransactionId(devices.getPoolDevName(), devices.TransactionId, devices.NewTransactionId); err != nil {
|
||||
return fmt.Errorf("Error setting devmapper transition ID: %s", err)
|
||||
}
|
||||
devices.TransactionId = devices.NewTransactionId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -294,6 +297,15 @@ func (devices *DeviceSet) registerDevice(id int, hash string, size uint64) (*Dev
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if err := devices.updatePoolTransactionId(); err != nil {
|
||||
// Remove unused device
|
||||
devices.devicesLock.Lock()
|
||||
delete(devices.Devices, hash)
|
||||
devices.devicesLock.Unlock()
|
||||
devices.removeMetadata(info)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue