From d0aae80f5556aefa661b22d8ed980f5ea3535914 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Mon, 6 May 2019 14:20:52 +0800 Subject: [PATCH 1/2] qemu: print virtiofsd logs when debug is on To help trace virtiofsd issues. Signed-off-by: Peng Tao --- virtcontainers/qemu.go | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 1217dfc32b..2d0ffe418f 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -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 @@ -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 { From 89e0dfae111e0365fdcbf7a65ecafa60580ee8b0 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Mon, 6 May 2019 18:01:05 +0800 Subject: [PATCH 2/2] qemu: stop qemu process when virtiofsd quits If virtiofsd fails to initialize and stops unexpected, qemu might hang forever. We just stop the qemu process. Resource cleanup will be done by others. Fixes: #1690 Signed-off-by: Peng Tao --- virtcontainers/qemu.go | 1 + 1 file changed, 1 insertion(+) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 2d0ffe418f..9edafcb08c 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -645,6 +645,7 @@ func (q *qemu) startSandbox(timeout int) error { } } q.Logger().Info("virtiofsd quits") + q.stopSandbox() }() timeoutDuration := time.Duration(timeout) * time.Second select {