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

Commit

Permalink
virtcontainers: add qemu process rollback
Browse files Browse the repository at this point in the history
If some errors occur after qemu process start, then we need to
rollback to kill qemu process

Fixes: #297

Signed-off-by: flyflypeng <[email protected]>
  • Loading branch information
flyflypeng authored and Eric Ernst committed Aug 23, 2018
1 parent bd5c8fe commit 01906ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ func createSandboxFromConfig(sandboxConfig SandboxConfig) (*Sandbox, error) {
return nil, err
}

// rollback to stop VM if error occurs
defer func() {
if err != nil {
s.stopVM()
}
}()

// Once startVM is done, we want to guarantee
// that the sandbox is manageable. For that we need
// to start the sandbox inside the VM.
if err = s.agent.startSandbox(s); err != nil {
return nil, err
}

// rollback to stop sandbox in VM
defer func() {
if err != nil {
s.agent.stopSandbox(s)
}
}()

// Create Containers
if err := s.createContainers(); err != nil {
return nil, err
Expand Down
10 changes: 6 additions & 4 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,12 @@ func (s *Sandbox) startVM() error {

s.Logger().Info("VM started")

// Once startVM is done, we want to guarantee
// that the sandbox is manageable. For that we need
// to start the sandbox inside the VM.
return s.agent.startSandbox(s)
return nil
}

// stopVM: stop the sandbox's VM
func (s *Sandbox) stopVM() error {
return s.hypervisor.stopSandbox()
}

func (s *Sandbox) addContainer(c *Container) error {
Expand Down

0 comments on commit 01906ee

Please sign in to comment.