mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 08:47:56 +00:00
monitor: watch hypervisor
When hypervisor process is dead, notify watchers and mark agent dead. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
67c401c059
commit
262484de68
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
@ -52,6 +55,7 @@ func (m *monitor) newWatcher() (chan error, error) {
|
||||
m.wg.Done()
|
||||
return
|
||||
case <-tick.C:
|
||||
m.watchHypervisor()
|
||||
m.watchAgent()
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
@ -228,5 +228,8 @@ func (n *noopAgent) copyFile(src, dst string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *noopAgent) markDead() {
|
||||
}
|
||||
|
||||
func (n *noopAgent) cleanup(id string) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user