Skip to content

Commit

Permalink
qemu: print virtiofsd logs when debug is on
Browse files Browse the repository at this point in the history
To help trace virtiofsd issues.

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed May 17, 2019
1 parent 90539ac commit d0aae80
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,16 @@ func (q *qemu) startSandbox(timeout int) error {
// connection with QEMU closes. Therefore we do not keep track
// of this child process after returning from this function.
sourcePath := filepath.Join(kataHostSharedDir, q.id)
cmd := exec.Command(q.config.VirtioFSDaemon,
"-o", "vhost_user_socket="+sockPath,
"-o", "source="+sourcePath,
"-o", "cache="+q.config.VirtioFSCache)
args := []string{
"-o", "vhost_user_socket=" + sockPath,
"-o", "source=" + sourcePath,
"-o", "cache=" + q.config.VirtioFSCache}
if q.config.Debug {
args = append(args, "-d")
} else {
args = append(args, "-f")
}
cmd := exec.Command(q.config.VirtioFSDaemon, args...)
stderr, err := cmd.StderrPipe()
if err != nil {
return err
Expand All @@ -621,16 +627,24 @@ func (q *qemu) startSandbox(timeout int) error {
timeStart := time.Now()
go func() {
scanner := bufio.NewScanner(stderr)
var sent bool
for scanner.Scan() {
if strings.Contains(scanner.Text(), "Waiting for vhost-user socket connection...") {
if q.config.Debug {
q.Logger().WithField("source", "virtiofsd").Debug(scanner.Text())
}
if !sent && strings.Contains(scanner.Text(), "Waiting for vhost-user socket connection...") {
sockReady <- nil
return
sent = true
}
}
if err := scanner.Err(); err != nil {
sockReady <- err
if !sent {
if err := scanner.Err(); err != nil {
sockReady <- err
} else {
sockReady <- fmt.Errorf("virtiofsd did not announce socket connection")
}
}
sockReady <- fmt.Errorf("virtiofsd did not announce socket connection")
q.Logger().Info("virtiofsd quits")
}()
timeoutDuration := time.Duration(timeout) * time.Second
select {
Expand Down

0 comments on commit d0aae80

Please sign in to comment.