Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: drop deferred func for GetAndSetSandboxBlockIndex
Browse files Browse the repository at this point in the history
Fixes #2726

Signed-off-by: Ted Yu <[email protected]>
  • Loading branch information
tedyu committed Jun 5, 2020
1 parent 011ade5 commit 49ebaa8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 3 additions & 1 deletion virtcontainers/acrn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 49ebaa8

Please sign in to comment.