Skip to content

Commit

Permalink
virtiofs: stop sandbox when virtiofsd quits
Browse files Browse the repository at this point in the history
Commit 89e0dfa ("qemu: stop qemu process when virtiofsd quits")
stops sandbox when virtiofsd quits so that virtiofs mount inside guest
won't hang. But commit d5a3d0a ("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: kata-containers#2315
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
  • Loading branch information
eryugey committed Dec 4, 2019
1 parent 62cd080 commit abbb536
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit abbb536

Please sign in to comment.