mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-02 02:02:24 +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.
|
// startSandbox will start the hypervisor for the given sandbox.
|
||||||
// In the context of firecracker, this will start the hypervisor,
|
// In the context of firecracker, this will start the hypervisor,
|
||||||
// for configuration, but not yet start the actual virtual machine
|
// 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")
|
span, _ := fc.trace("startSandbox")
|
||||||
defer span.Finish()
|
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 {
|
func (fc *firecracker) createDiskPool() error {
|
||||||
@ -411,14 +415,6 @@ func (fc *firecracker) createDiskPool() error {
|
|||||||
return nil
|
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.
|
// stopSandbox will stop the Sandbox's VM.
|
||||||
func (fc *firecracker) stopSandbox() (err error) {
|
func (fc *firecracker) stopSandbox() (err error) {
|
||||||
span, _ := fc.trace("stopSandbox")
|
span, _ := fc.trace("stopSandbox")
|
||||||
|
@ -591,8 +591,7 @@ func RunningOnVMM(cpuInfoPath string) (bool, error) {
|
|||||||
// The default hypervisor implementation is Qemu.
|
// The default hypervisor implementation is Qemu.
|
||||||
type hypervisor interface {
|
type hypervisor interface {
|
||||||
createSandbox(ctx context.Context, id string, hypervisorConfig *HypervisorConfig, storage resourceStorage) error
|
createSandbox(ctx context.Context, id string, hypervisorConfig *HypervisorConfig, storage resourceStorage) error
|
||||||
startSandbox() error
|
startSandbox(timeout int) error
|
||||||
waitSandbox(timeout int) error
|
|
||||||
stopSandbox() error
|
stopSandbox() error
|
||||||
pauseSandbox() error
|
pauseSandbox() error
|
||||||
saveSandbox() error
|
saveSandbox() error
|
||||||
|
@ -30,11 +30,7 @@ func (m *mockHypervisor) createSandbox(ctx context.Context, id string, hyperviso
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockHypervisor) startSandbox() error {
|
func (m *mockHypervisor) startSandbox(timeout int) error {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockHypervisor) waitSandbox(timeout int) error {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +47,7 @@ func TestMockHypervisorCreateSandbox(t *testing.T) {
|
|||||||
func TestMockHypervisorStartSandbox(t *testing.T) {
|
func TestMockHypervisorStartSandbox(t *testing.T) {
|
||||||
var m *mockHypervisor
|
var m *mockHypervisor
|
||||||
|
|
||||||
if err := m.startSandbox(); err != nil {
|
if err := m.startSandbox(vmStartTimeout); err != nil {
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMockHypervisorWaitSandbox(t *testing.T) {
|
|
||||||
var m *mockHypervisor
|
|
||||||
|
|
||||||
if err := m.waitSandbox(0); err != nil {
|
|
||||||
t.Fatal(err)
|
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.
|
// startSandbox will start the Sandbox's VM.
|
||||||
func (q *qemu) startSandbox() error {
|
func (q *qemu) startSandbox(timeout int) error {
|
||||||
span, _ := q.trace("startSandbox")
|
span, _ := q.trace("startSandbox")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
@ -578,7 +578,7 @@ func (q *qemu) startSandbox() error {
|
|||||||
return fmt.Errorf("%s", strErr)
|
return fmt.Errorf("%s", strErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return q.waitSandbox(timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitSandbox will wait for the Sandbox's VM to be up and running.
|
// 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 nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.hypervisor.startSandbox()
|
return s.hypervisor.startSandbox(vmStartTimeout)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.hypervisor.waitSandbox(vmStartTimeout); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// In case of vm factory, network interfaces are hotplugged
|
// In case of vm factory, network interfaces are hotplugged
|
||||||
// after vm is started.
|
// after vm is started.
|
||||||
if s.factory != nil {
|
if s.factory != nil {
|
||||||
|
@ -131,10 +131,7 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. boot up guest vm
|
// 3. boot up guest vm
|
||||||
if err = hypervisor.startSandbox(); err != nil {
|
if err = hypervisor.startSandbox(vmStartTimeout); err != nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err = hypervisor.waitSandbox(vmStartTimeout); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +208,7 @@ func (v *VM) Resume() error {
|
|||||||
// Start kicks off a configured VM.
|
// Start kicks off a configured VM.
|
||||||
func (v *VM) Start() error {
|
func (v *VM) Start() error {
|
||||||
v.logger().Info("start vm")
|
v.logger().Info("start vm")
|
||||||
return v.hypervisor.startSandbox()
|
return v.hypervisor.startSandbox(vmStartTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnect agent and proxy connections to a VM
|
// Disconnect agent and proxy connections to a VM
|
||||||
|
Loading…
Reference in New Issue
Block a user