mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-02 17:34:18 +00:00
Merge pull request #2245 from tedyu/block-index-update
vc: Sandbox#getAndSetSandboxBlockIndex shouldn't alter BlockIndex in case of error
This commit is contained in:
@@ -1683,6 +1683,12 @@ func (s *Sandbox) resumeSetStates() error {
|
|||||||
// block device is assigned to a container in the sandbox.
|
// block device is assigned to a container in the sandbox.
|
||||||
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
|
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
|
||||||
currentIndex := s.state.BlockIndex
|
currentIndex := s.state.BlockIndex
|
||||||
|
var err error
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
s.state.BlockIndex = currentIndex
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Increment so that container gets incremented block index
|
// Increment so that container gets incremented block index
|
||||||
s.state.BlockIndex++
|
s.state.BlockIndex++
|
||||||
@@ -1701,12 +1707,19 @@ func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
|
|||||||
// decrementSandboxBlockIndex decrements the current sandbox block index.
|
// decrementSandboxBlockIndex decrements the current sandbox block index.
|
||||||
// This is used to recover from failure while adding a block device.
|
// This is used to recover from failure while adding a block device.
|
||||||
func (s *Sandbox) decrementSandboxBlockIndex() error {
|
func (s *Sandbox) decrementSandboxBlockIndex() error {
|
||||||
|
var err error
|
||||||
|
original := s.state.BlockIndex
|
||||||
s.state.BlockIndex--
|
s.state.BlockIndex--
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
s.state.BlockIndex = original
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if !s.supportNewStore() {
|
if !s.supportNewStore() {
|
||||||
// experimental runtime use "persist.json" which doesn't need "state.json" anymore
|
// experimental runtime use "persist.json" which doesn't need "state.json" anymore
|
||||||
// update on-disk state
|
// update on-disk state
|
||||||
if err := s.store.Store(store.State, s.state); err != nil {
|
if err = s.store.Store(store.State, s.state); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user