mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +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 copies file from host to container's rootfs
|
||||||
copyFile(src, dst string) error
|
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 removes all on disk information generated by the agent
|
||||||
cleanup(id string)
|
cleanup(id string)
|
||||||
}
|
}
|
||||||
|
@ -2069,6 +2069,12 @@ func (k *kataAgent) copyFile(src, dst string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k *kataAgent) markDead() {
|
||||||
|
k.Logger().Infof("mark agent dead")
|
||||||
|
k.dead = true
|
||||||
|
k.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
func (k *kataAgent) cleanup(id string) {
|
func (k *kataAgent) cleanup(id string) {
|
||||||
path := k.getSharePath(id)
|
path := k.getSharePath(id)
|
||||||
k.Logger().WithField("path", path).Infof("cleanup agent")
|
k.Logger().WithField("path", path).Infof("cleanup agent")
|
||||||
|
@ -7,10 +7,13 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultCheckInterval = 10 * time.Second
|
const defaultCheckInterval = 1 * time.Second
|
||||||
|
|
||||||
type monitor struct {
|
type monitor struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@ -52,6 +55,7 @@ func (m *monitor) newWatcher() (chan error, error) {
|
|||||||
m.wg.Done()
|
m.wg.Done()
|
||||||
return
|
return
|
||||||
case <-tick.C:
|
case <-tick.C:
|
||||||
|
m.watchHypervisor()
|
||||||
m.watchAgent()
|
m.watchAgent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,6 +66,8 @@ func (m *monitor) newWatcher() (chan error, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *monitor) notify(err error) {
|
func (m *monitor) notify(err error) {
|
||||||
|
m.sandbox.agent.markDead()
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
@ -115,6 +121,15 @@ func (m *monitor) stop() {
|
|||||||
func (m *monitor) watchAgent() {
|
func (m *monitor) watchAgent() {
|
||||||
err := m.sandbox.agent.check()
|
err := m.sandbox.agent.check()
|
||||||
if err != nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *noopAgent) markDead() {
|
||||||
|
}
|
||||||
|
|
||||||
func (n *noopAgent) cleanup(id string) {
|
func (n *noopAgent) cleanup(id string) {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user