libnet/ipam: get rid of superfluous closure
The two-phase commit dance serves no purpose with the current IPAM allocator implementation. There are no fallible operations between the call to aSpace.updatePoolDBOnAdd() and invoking the returned closure. Allocate the subnet in the address space immediately when called and get rid of the closure return. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
2f0e308c7d
commit
18ac200efe
2 changed files with 13 additions and 14 deletions
|
@ -89,8 +89,7 @@ retry:
|
|||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
insert, err := aSpace.updatePoolDBOnAdd(*k, nw, ipr, pdf)
|
||||
if err != nil {
|
||||
if err := aSpace.allocateSubnet(*k, nw, ipr, pdf); err != nil {
|
||||
if _, ok := err.(types.MaskableError); ok {
|
||||
logrus.Debugf("Retrying predefined pool search: %v", err)
|
||||
goto retry
|
||||
|
@ -98,7 +97,7 @@ retry:
|
|||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
return k.String(), nw, nil, insert()
|
||||
return k.String(), nw, nil, nil
|
||||
}
|
||||
|
||||
// ReleasePool releases the address pool identified by the passed id
|
||||
|
@ -114,7 +113,7 @@ func (a *Allocator) ReleasePool(poolID string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return aSpace.updatePoolDBOnRemoval(k)
|
||||
return aSpace.releaseSubnet(k)
|
||||
}
|
||||
|
||||
// Given the address space, returns the local or global PoolConfig based on whether the
|
||||
|
|
|
@ -78,29 +78,29 @@ func (p *PoolData) String() string {
|
|||
p.ParentKey.String(), p.Pool.String(), p.Range, p.RefCount)
|
||||
}
|
||||
|
||||
// updatePoolDBOnAdd returns a closure which will add the subnet k to the address space when executed.
|
||||
func (aSpace *addrSpace) updatePoolDBOnAdd(k SubnetKey, nw *net.IPNet, ipr *AddressRange, pdf bool) (func() error, error) {
|
||||
// allocateSubnet adds the subnet k to the address space.
|
||||
func (aSpace *addrSpace) allocateSubnet(k SubnetKey, nw *net.IPNet, ipr *AddressRange, pdf bool) error {
|
||||
aSpace.Lock()
|
||||
defer aSpace.Unlock()
|
||||
|
||||
// Check if already allocated
|
||||
if _, ok := aSpace.subnets[k]; ok {
|
||||
if pdf {
|
||||
return nil, types.InternalMaskableErrorf("predefined pool %s is already reserved", nw)
|
||||
return types.InternalMaskableErrorf("predefined pool %s is already reserved", nw)
|
||||
}
|
||||
// This means the same pool is already allocated. updatePoolDBOnAdd is called when there
|
||||
// This means the same pool is already allocated. allocateSubnet is called when there
|
||||
// is request for a pool/subpool. It should ensure there is no overlap with existing pools
|
||||
return nil, ipamapi.ErrPoolOverlap
|
||||
return ipamapi.ErrPoolOverlap
|
||||
}
|
||||
|
||||
// If master pool, check for overlap
|
||||
if ipr == nil {
|
||||
if aSpace.contains(k.AddressSpace, nw) {
|
||||
return nil, ipamapi.ErrPoolOverlap
|
||||
return ipamapi.ErrPoolOverlap
|
||||
}
|
||||
// This is a new master pool, add it along with corresponding bitmask
|
||||
aSpace.subnets[k] = &PoolData{Pool: nw, RefCount: 1}
|
||||
return func() error { return aSpace.alloc.insertBitMask(k, nw) }, nil
|
||||
return aSpace.alloc.insertBitMask(k, nw)
|
||||
}
|
||||
|
||||
// This is a new non-master pool (subPool)
|
||||
|
@ -116,15 +116,15 @@ func (aSpace *addrSpace) updatePoolDBOnAdd(k SubnetKey, nw *net.IPNet, ipr *Addr
|
|||
pp, ok := aSpace.subnets[p.ParentKey]
|
||||
if ok {
|
||||
aSpace.incRefCount(pp, 1)
|
||||
return func() error { return nil }, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parent pool does not exist, add it along with corresponding bitmask
|
||||
aSpace.subnets[p.ParentKey] = &PoolData{Pool: nw, RefCount: 1}
|
||||
return func() error { return aSpace.alloc.insertBitMask(p.ParentKey, nw) }, nil
|
||||
return aSpace.alloc.insertBitMask(p.ParentKey, nw)
|
||||
}
|
||||
|
||||
func (aSpace *addrSpace) updatePoolDBOnRemoval(k SubnetKey) error {
|
||||
func (aSpace *addrSpace) releaseSubnet(k SubnetKey) error {
|
||||
aSpace.Lock()
|
||||
defer aSpace.Unlock()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue