mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +00:00
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:
parent
c2651a85a8
commit
7103c4f14a
@ -64,6 +64,27 @@ func createSandboxFromConfig(sandboxConfig SandboxConfig, factory Factory) (*San
|
||||
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
|
||||
|
@ -971,10 +971,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 {
|
||||
|
Loading…
Reference in New Issue
Block a user