mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-31 23:36:12 +00:00
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:
parent
8e3bd358e5
commit
342bf3e949
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user