virtcontainers: add qemu process rollback

If some errors occur after qemu process start, then we need to
rollback to kill qemu process

Fixes: #297

Signed-off-by: flyflypeng <jiangpengfei9@huawei.com>
This commit is contained in:
flyflypeng 2018-06-20 07:51:05 +08:00
parent c2651a85a8
commit 7103c4f14a
2 changed files with 27 additions and 4 deletions

View File

@ -64,6 +64,27 @@ func createSandboxFromConfig(sandboxConfig SandboxConfig, factory Factory) (*San
return nil, err 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 // Create Containers
if err = s.createContainers(); err != nil { if err = s.createContainers(); err != nil {
return nil, err return nil, err

View File

@ -971,10 +971,12 @@ func (s *Sandbox) startVM() error {
s.Logger().Info("VM started") s.Logger().Info("VM started")
// Once startVM is done, we want to guarantee return nil
// that the sandbox is manageable. For that we need }
// to start the sandbox inside the VM.
return s.agent.startSandbox(s) // stopVM: stop the sandbox's VM
func (s *Sandbox) stopVM() error {
return s.hypervisor.stopSandbox()
} }
func (s *Sandbox) addContainer(c *Container) error { func (s *Sandbox) addContainer(c *Container) error {