From 342bf3e94912c856db706ff8e8afe9f00a1dbf9d Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Fri, 5 Jun 2020 02:54:59 -0700 Subject: [PATCH] virtcontainers: drop deferred func for GetAndSetSandboxBlockIndex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2726 Signed-off-by: Ted Yu Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/acrn.go | 4 +++- src/runtime/virtcontainers/sandbox.go | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/runtime/virtcontainers/acrn.go b/src/runtime/virtcontainers/acrn.go index e186089629..b7582a1b05 100644 --- a/src/runtime/virtcontainers/acrn.go +++ b/src/runtime/virtcontainers/acrn.go @@ -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 { diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index a01a360d39..0a78a11188 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -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 }