virtcontainers: drop deferred func for GetAndSetSandboxBlockIndex

Fixes #2726

Signed-off-by: Ted Yu <yuzhihong@gmail.com>
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Ted Yu 2020-06-05 02:54:59 -07:00 committed by Fabiano Fidêncio
parent 8e3bd358e5
commit 342bf3e949
2 changed files with 3 additions and 7 deletions

View File

@ -235,7 +235,9 @@ func (a *Acrn) appendImage(devices []Device, imagePath string) ([]Device, error)
if sandbox == nil && err != nil {
return nil, err
}
sandbox.GetAndSetSandboxBlockIndex()
if _, err = sandbox.GetAndSetSandboxBlockIndex(); err != nil {
return nil, err
}
devices, err = a.arch.appendImage(devices, imagePath)
if err != nil {

View File

@ -1606,7 +1606,6 @@ const maxBlockIndex = 65535
// the BlockIndexMap and marks it as used. This index is used to maintain the
// index at which a block device is assigned to a container in the sandbox.
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
var err error
currentIndex := -1
for i := 0; i < maxBlockIndex; i++ {
if _, ok := s.state.BlockIndexMap[i]; !ok {
@ -1618,11 +1617,6 @@ func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
return -1, errors.New("no available block index")
}
s.state.BlockIndexMap[currentIndex] = struct{}{}
defer func() {
if err != nil {
delete(s.state.BlockIndexMap, currentIndex)
}
}()
return currentIndex, nil
}