mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-10 12:22:36 +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 {
|
if sandbox == nil && err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sandbox.GetAndSetSandboxBlockIndex()
|
if _, err = sandbox.GetAndSetSandboxBlockIndex(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
devices, err = a.arch.appendImage(devices, imagePath)
|
devices, err = a.arch.appendImage(devices, imagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1606,7 +1606,6 @@ const maxBlockIndex = 65535
|
|||||||
// the BlockIndexMap and marks it as used. This index is used to maintain the
|
// 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.
|
// index at which a block device is assigned to a container in the sandbox.
|
||||||
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
|
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
|
||||||
var err error
|
|
||||||
currentIndex := -1
|
currentIndex := -1
|
||||||
for i := 0; i < maxBlockIndex; i++ {
|
for i := 0; i < maxBlockIndex; i++ {
|
||||||
if _, ok := s.state.BlockIndexMap[i]; !ok {
|
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")
|
return -1, errors.New("no available block index")
|
||||||
}
|
}
|
||||||
s.state.BlockIndexMap[currentIndex] = struct{}{}
|
s.state.BlockIndexMap[currentIndex] = struct{}{}
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
delete(s.state.BlockIndexMap, currentIndex)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return currentIndex, nil
|
return currentIndex, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user