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

Commit

Permalink
virtcontainers: Remove the hypervisor waitSandbox method
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Samuel Ortiz committed Jan 8, 2019
1 parent 763bf18 commit cf22f40
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 38 deletions.
16 changes: 6 additions & 10 deletions virtcontainers/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions virtcontainers/mock_hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 1 addition & 9 deletions virtcontainers/mock_hypervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions virtcontainers/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf22f40

Please sign in to comment.