mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-01 09:42:45 +00:00
virtcontainers: Remove the hypervisor waitSandbox method
We always call waitSandbox after we start the VM (startSandbox), so let's simplify the hypervisor interface and integrate waiting for the VM into startSandbox. This makes startSandbox a blocking call, but that is practically the case today. Fixes: #1009 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
763bf18daa
commit
cf22f402d8
@ -335,7 +335,7 @@ func (fc *firecracker) fcStartVM() error {
|
||||
// startSandbox will start the hypervisor for the given sandbox.
|
||||
// In the context of firecracker, this will start the hypervisor,
|
||||
// for configuration, but not yet start the actual virtual machine
|
||||
func (fc *firecracker) startSandbox() error {
|
||||
func (fc *firecracker) startSandbox(timeout int) error {
|
||||
span, _ := fc.trace("startSandbox")
|
||||
defer span.Finish()
|
||||
|
||||
@ -375,7 +375,11 @@ func (fc *firecracker) startSandbox() error {
|
||||
}
|
||||
}
|
||||
|
||||
return fc.fcStartVM()
|
||||
if err := fc.fcStartVM(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return fc.waitVMM(timeout)
|
||||
}
|
||||
|
||||
func (fc *firecracker) createDiskPool() error {
|
||||
@ -411,14 +415,6 @@ func (fc *firecracker) createDiskPool() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// waitSandbox will wait for the Sandbox's VM to be up and running.
|
||||
func (fc *firecracker) waitSandbox(timeout int) error {
|
||||
span, _ := fc.trace("waitSandbox")
|
||||
defer span.Finish()
|
||||
|
||||
return fc.waitVMM(timeout)
|
||||
}
|
||||
|
||||
// stopSandbox will stop the Sandbox's VM.
|
||||
func (fc *firecracker) stopSandbox() (err error) {
|
||||
span, _ := fc.trace("stopSandbox")
|
||||
|
@ -591,8 +591,7 @@ func RunningOnVMM(cpuInfoPath string) (bool, error) {
|
||||
// The default hypervisor implementation is Qemu.
|
||||
type hypervisor interface {
|
||||
createSandbox(ctx context.Context, id string, hypervisorConfig *HypervisorConfig, storage resourceStorage) error
|
||||
startSandbox() error
|
||||
waitSandbox(timeout int) error
|
||||
startSandbox(timeout int) error
|
||||
stopSandbox() error
|
||||
pauseSandbox() error
|
||||
saveSandbox() error
|
||||
|
@ -30,11 +30,7 @@ func (m *mockHypervisor) createSandbox(ctx context.Context, id string, hyperviso
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) startSandbox() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) waitSandbox(timeout int) error {
|
||||
func (m *mockHypervisor) startSandbox(timeout int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -47,15 +47,7 @@ func TestMockHypervisorCreateSandbox(t *testing.T) {
|
||||
func TestMockHypervisorStartSandbox(t *testing.T) {
|
||||
var m *mockHypervisor
|
||||
|
||||
if err := m.startSandbox(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMockHypervisorWaitSandbox(t *testing.T) {
|
||||
var m *mockHypervisor
|
||||
|
||||
if err := m.waitSandbox(0); err != nil {
|
||||
if err := m.startSandbox(vmStartTimeout); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, hypervisorConfig *H
|
||||
}
|
||||
|
||||
// startSandbox will start the Sandbox's VM.
|
||||
func (q *qemu) startSandbox() error {
|
||||
func (q *qemu) startSandbox(timeout int) error {
|
||||
span, _ := q.trace("startSandbox")
|
||||
defer span.Finish()
|
||||
|
||||
@ -578,7 +578,7 @@ func (q *qemu) startSandbox() error {
|
||||
return fmt.Errorf("%s", strErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
return q.waitSandbox(timeout)
|
||||
}
|
||||
|
||||
// waitSandbox will wait for the Sandbox's VM to be up and running.
|
||||
|
@ -947,15 +947,11 @@ func (s *Sandbox) startVM() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return s.hypervisor.startSandbox()
|
||||
return s.hypervisor.startSandbox(vmStartTimeout)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.hypervisor.waitSandbox(vmStartTimeout); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// In case of vm factory, network interfaces are hotplugged
|
||||
// after vm is started.
|
||||
if s.factory != nil {
|
||||
|
@ -131,10 +131,7 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) {
|
||||
}
|
||||
|
||||
// 3. boot up guest vm
|
||||
if err = hypervisor.startSandbox(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = hypervisor.waitSandbox(vmStartTimeout); err != nil {
|
||||
if err = hypervisor.startSandbox(vmStartTimeout); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -211,7 +208,7 @@ func (v *VM) Resume() error {
|
||||
// Start kicks off a configured VM.
|
||||
func (v *VM) Start() error {
|
||||
v.logger().Info("start vm")
|
||||
return v.hypervisor.startSandbox()
|
||||
return v.hypervisor.startSandbox(vmStartTimeout)
|
||||
}
|
||||
|
||||
// Disconnect agent and proxy connections to a VM
|
||||
|
Loading…
Reference in New Issue
Block a user