From abbb536cc40a0a6cda49027899f4cbed6bd312a5 Mon Sep 17 00:00:00 2001 From: Eryu Guan Date: Wed, 4 Dec 2019 12:47:04 +0800 Subject: [PATCH] virtiofs: stop sandbox when virtiofsd quits Commit 89e0dfae111e ("qemu: stop qemu process when virtiofsd quits") stops sandbox when virtiofsd quits so that virtiofs mount inside guest won't hang. But commit d5a3d0a61c70 ("virtiofs: use virtiofsd --fd=FDNUM") deleted this monitor logic. Add the Scanner back to monitor virtiofsd's stderr and stop sandbox if Scanner returns error. Note that we don't monitor the virtiofsd process itself is because virtiofsd may be live-upgraded (when available) and the original process may quit, but virtiofs service is still running. Fixes: #2315 Signed-off-by: Eryu Guan --- virtcontainers/qemu.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index b23168fe59..b4ea97520d 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -655,12 +655,28 @@ func (q *qemu) setupVirtiofsd() (err error) { const sockFd = 3 // Cmd.ExtraFiles[] fds are numbered starting from 3 cmd := exec.Command(q.config.VirtioFSDaemon, q.virtiofsdArgs(sockFd)...) cmd.ExtraFiles = append(cmd.ExtraFiles, fd) + stderr, err := cmd.StderrPipe() + if err != nil { + return err + } err = cmd.Start() if err == nil { q.state.VirtiofsdPid = cmd.Process.Pid } fd.Close() + + // Monitor virtiofsd's stderr and stop sandbox if virtiofsd quits + go func() { + scanner := bufio.NewScanner(stderr) + for scanner.Scan() { + q.Logger().WithField("source", "virtiofsd").Info(scanner.Text()) + } + q.Logger().Info("virtiofsd quits") + // Wait to release resources of virtiofsd process + cmd.Process.Wait() + q.stopSandbox() + }() return err }