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

Commit

Permalink
vc: Don't adjust block index on error
Browse files Browse the repository at this point in the history
Fixed `Sandbox::getAndSetSandboxBlockIndex() so that
it does not update `BlockIndex` if an error occurs.

Fixes #2244

Signed-off-by: Ted Yu <[email protected]>
  • Loading branch information
yutedz committed Dec 2, 2019
1 parent 09118fa commit c818711
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,14 +1605,20 @@ func (s *Sandbox) resumeSetStates() error {
// block device is assigned to a container in the sandbox.
func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
currentIndex := s.state.BlockIndex
var err error
defer func() {
if err != nil {
s.state.BlockIndex = currentIndex
}
}()

// Increment so that container gets incremented block index
s.state.BlockIndex++

if !s.supportNewStore() {
// experimental runtime use "persist.json" which doesn't need "state.json" anymore
// 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 -1, err
}
}
Expand All @@ -1623,12 +1629,19 @@ func (s *Sandbox) getAndSetSandboxBlockIndex() (int, error) {
// decrementSandboxBlockIndex decrements the current sandbox block index.
// This is used to recover from failure while adding a block device.
func (s *Sandbox) decrementSandboxBlockIndex() error {
var err error
original := s.state.BlockIndex
s.state.BlockIndex--
defer func() {
if err != nil {
s.state.BlockIndex = original
}
}()

if !s.supportNewStore() {
// experimental runtime use "persist.json" which doesn't need "state.json" anymore
// 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
}
}
Expand Down

0 comments on commit c818711

Please sign in to comment.