devmapper: Allocate new transaction Id using current transaction Id

Currently new transaction Id is created using allocateTransactionId()
function. This function takes NewTransactionId and bumps up by one 
to create NewTransactionId.

I think ideally we should be bumping up devices.TransactionId by 1
to come up with NewTransactionId. Because idea is that devices.TransactionId
contains the current pool transaction Id and to come up with a new
transaction Id bump it up by one.

Current code is not wrong as we are keeping NewTransactionId and
TransactionId in sync. But it will be more direct if we look at
devices.TransactionId to come up with NewTransactionId. That way
we don't have to even initialize NewTransactionId during startup
as first time somebody wants to do a transaction, it will be
allocated fresh.

So simplify the code a bit. No functionality change.
 
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
Vivek Goyal 2014-12-03 13:06:43 -05:00 committed by root
parent 6d347aeb69
commit 7b0a1b814b

View file

@ -200,7 +200,7 @@ func (devices *DeviceSet) ensureImage(name string, size int64) (string, error) {
}
func (devices *DeviceSet) allocateTransactionId() uint64 {
devices.NewTransactionId = devices.NewTransactionId + 1
devices.NewTransactionId = devices.TransactionId + 1
return devices.NewTransactionId
}
@ -398,7 +398,6 @@ func (devices *DeviceSet) initMetaData() error {
}
devices.TransactionId = transactionId
devices.NewTransactionId = devices.TransactionId
return nil
}