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

Commit

Permalink
qemu: check guest status with qmp query-status
Browse files Browse the repository at this point in the history
When guest panics or stops with unexpected internal
error, qemu process might still be running but we can
find out such situation with qmp. Then monitor can still
report such failures to watchers.

Fixes: #1963
Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Aug 16, 2019
1 parent 5b50b34 commit 6c77d76
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
15 changes: 12 additions & 3 deletions virtcontainers/acrn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package virtcontainers

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand All @@ -16,13 +15,15 @@ import (
"syscall"
"time"

opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/kata-containers/runtime/virtcontainers/device/config"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
"github.com/kata-containers/runtime/virtcontainers/store"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"
opentracing "github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
)

// AcrnState keeps Acrn's state
Expand Down Expand Up @@ -648,3 +649,11 @@ func (a *acrn) load(s persistapi.HypervisorState) {
a.info.PID = s.Pid
a.state.UUID = s.UUID
}

func (a *acrn) check() error {
if err := syscall.Kill(a.pid(), syscall.Signal(0)); err != nil {
return errors.Wrapf(err, "failed to ping acrn process")
}

return nil
}
8 changes: 8 additions & 0 deletions virtcontainers/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,11 @@ func (fc *firecracker) save() (s persistapi.HypervisorState) {
func (fc *firecracker) load(s persistapi.HypervisorState) {
fc.info.PID = s.Pid
}

func (fc *firecracker) check() error {
if err := syscall.Kill(fc.pid(), syscall.Signal(0)); err != nil {
return errors.Wrapf(err, "failed to ping fc process")
}

return nil
}
1 change: 1 addition & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ type hypervisor interface {
pid() int
fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, store *store.VCStore, j []byte) error
toGrpc() ([]byte, error)
check() error

save() persistapi.HypervisorState
load(persistapi.HypervisorState)
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/mock_hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ func (m *mockHypervisor) save() (s persistapi.HypervisorState) {
}

func (m *mockHypervisor) load(s persistapi.HypervisorState) {}

func (m *mockHypervisor) check() error {
return nil
}
6 changes: 6 additions & 0 deletions virtcontainers/mock_hypervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ func TestMockHypervisorDisconnect(t *testing.T) {

m.disconnect()
}

func TestMockHypervisorCheck(t *testing.T) {
var m *mockHypervisor

assert.NoError(t, m.check())
}
3 changes: 1 addition & 2 deletions virtcontainers/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package virtcontainers

import (
"sync"
"syscall"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -127,7 +126,7 @@ func (m *monitor) watchAgent() {
}

func (m *monitor) watchHypervisor() error {
if err := syscall.Kill(m.sandbox.hypervisor.pid(), syscall.Signal(0)); err != nil {
if err := m.sandbox.hypervisor.check(); err != nil {
m.notify(errors.Wrapf(err, "failed to ping hypervisor process"))
return err
}
Expand Down
25 changes: 21 additions & 4 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math"
Expand All @@ -24,17 +23,17 @@ import (
"unsafe"

govmmQemu "github.com/intel/govmm/qemu"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"

"github.com/kata-containers/runtime/virtcontainers/device/config"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
"github.com/kata-containers/runtime/virtcontainers/store"
"github.com/kata-containers/runtime/virtcontainers/types"
"github.com/kata-containers/runtime/virtcontainers/utils"

"golang.org/x/sys/unix"
)

// romFile is the file name of the ROM that can be used for virtio-pci devices.
Expand Down Expand Up @@ -2015,3 +2014,21 @@ func (q *qemu) load(s persistapi.HypervisorState) {
})
}
}

func (q *qemu) check() error {
err := q.qmpSetup()
if err != nil {
return err
}

status, err := q.qmpMonitorCh.qmp.ExecuteQueryStatus(q.qmpMonitorCh.ctx)
if err != nil {
return err
}

if status.Status == "internal-error" || status.Status == "guest-panicked" {
return errors.Errorf("guest failure: %s", status.Status)
}

return nil
}

0 comments on commit 6c77d76

Please sign in to comment.