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

Commit

Permalink
monitor: watch hypervisor
Browse files Browse the repository at this point in the history
When hypervisor process is dead, notify watchers and mark agent dead.

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Jul 23, 2019
1 parent 67c401c commit 262484d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ type agent interface {
// copyFile copies file from host to container's rootfs
copyFile(src, dst string) error

// markDead tell agent that the guest is dead
markDead()

// cleanup removes all on disk information generated by the agent
cleanup(id string)
}
6 changes: 6 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,12 @@ func (k *kataAgent) copyFile(src, dst string) error {
return nil
}

func (k *kataAgent) markDead() {
k.Logger().Infof("mark agent dead")
k.dead = true
k.disconnect()
}

func (k *kataAgent) cleanup(id string) {
path := k.getSharePath(id)
k.Logger().WithField("path", path).Infof("cleanup agent")
Expand Down
19 changes: 17 additions & 2 deletions virtcontainers/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ package virtcontainers

import (
"sync"
"syscall"
"time"

"github.com/pkg/errors"
)

const defaultCheckInterval = 10 * time.Second
const defaultCheckInterval = 1 * time.Second

type monitor struct {
sync.Mutex
Expand Down Expand Up @@ -52,6 +55,7 @@ func (m *monitor) newWatcher() (chan error, error) {
m.wg.Done()
return
case <-tick.C:
m.watchHypervisor()
m.watchAgent()
}
}
Expand All @@ -62,6 +66,8 @@ func (m *monitor) newWatcher() (chan error, error) {
}

func (m *monitor) notify(err error) {
m.sandbox.agent.markDead()

m.Lock()
defer m.Unlock()

Expand Down Expand Up @@ -115,6 +121,15 @@ func (m *monitor) stop() {
func (m *monitor) watchAgent() {
err := m.sandbox.agent.check()
if err != nil {
m.notify(err)
// TODO: define and export error types
m.notify(errors.Wrapf(err, "failed to ping agent"))
}
}

func (m *monitor) watchHypervisor() error {
if err := syscall.Kill(m.sandbox.hypervisor.pid(), syscall.Signal(0)); err != nil {
m.notify(errors.Wrapf(err, "failed to ping hypervisor process"))
return err
}
return nil
}
3 changes: 3 additions & 0 deletions virtcontainers/noop_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,8 @@ func (n *noopAgent) copyFile(src, dst string) error {
return nil
}

func (n *noopAgent) markDead() {
}

func (n *noopAgent) cleanup(id string) {
}

0 comments on commit 262484d

Please sign in to comment.