devmapper: Move pool id query and migration of old data in separate function
Right now initMetaData() first queries the pool for current transaciton Id and then it migrates the old metafile. Move pool transaction Id query and file migration in separate functions for better code reuse and organization. Given we have removed device transaction Id dependency from saveMetaData(), we don't have to query pool transaction Id before migrating files. Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
parent
0db6cc85ed
commit
824a87f7ef
1 changed files with 16 additions and 12 deletions
|
@ -352,19 +352,8 @@ func (devices *DeviceSet) createFilesystem(info *DevInfo) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) initMetaData() error {
|
||||
_, _, _, params, err := devicemapper.GetStatus(devices.getPoolName())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := fmt.Sscanf(params, "%d", &devices.TransactionId); err != nil {
|
||||
return err
|
||||
}
|
||||
devices.NewTransactionId = devices.TransactionId
|
||||
|
||||
func (devices *DeviceSet) migrateOldMetaData() error {
|
||||
// Migrate old metadatafile
|
||||
|
||||
jsonData, err := ioutil.ReadFile(devices.oldMetadataFile())
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
|
@ -390,6 +379,21 @@ func (devices *DeviceSet) initMetaData() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) initMetaData() error {
|
||||
if err := devices.migrateOldMetaData(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, transactionId, _, _, _, _, err := devices.poolStatus()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices.TransactionId = transactionId
|
||||
devices.NewTransactionId = devices.TransactionId
|
||||
return nil
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) loadMetadata(hash string) *DevInfo {
|
||||
info := &DevInfo{Hash: hash, devices: devices}
|
||||
|
||||
|
|
Loading…
Reference in a new issue