Skip to content

Commit

Permalink
vsock: Waiting event of vsock running before use it when use_vsock en…
Browse files Browse the repository at this point in the history
…abled

If `kata-runtime` connect vsock device in guest but the device is not start
ready, the 'connect' will block and timeout after 2 sencond. This will cause
the boot is slower 2 second when use vsock than serial.
So we should wait 'VSOCK_RUNNING' QMP event before connect to avoid this case.

Fixes: kata-containers#1917

Signed-off-by: Ning Bo <ning.bo9@zte.com.cn>
  • Loading branch information
NingBo committed Aug 2, 2019
1 parent 3255640 commit 82841e1
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

[[constraint]]
name = "github.com/intel/govmm"
revision = "e0505242c0670f1a522f5b2d827e4a7e4062a14d"
revision = "aa341b005e9371b26d6ab95bcccb67eb5f48ee33"

[[constraint]]
name = "github.com/kata-containers/agent"
Expand Down
36 changes: 36 additions & 0 deletions vendor/github.com/intel/govmm/qemu/qmp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,13 @@ func (q *qemu) waitSandbox(timeout int) error {
return fmt.Errorf("Invalid timeout %ds", timeout)
}

cfg := govmmQemu.QMPConfig{Logger: newQMPLogger()}
eventCh := make(chan govmmQemu.QMPEvent)
cfg := govmmQemu.QMPConfig{
EventCh: eventCh,
Logger: newQMPLogger(),
// response of qmp.ExecuteQMPCapabilities bigger than default 64k in bufio.NewScanner()
MaxCapacity: 512 * 1024,
}

var qmp *govmmQemu.QMP
var disconnectCh chan struct{}
Expand Down Expand Up @@ -825,6 +831,35 @@ func (q *qemu) waitSandbox(timeout int) error {
return err
}

if !q.config.UseVSock {
return nil
}

schemaInfo, err := q.qmpMonitorCh.qmp.ExecQueryQmpSchema(q.qmpMonitorCh.ctx)
if err != nil {
q.Logger().Error(err)
return err
}

wait := false
for _, schema := range schemaInfo {
if schema.MetaType == "event" && schema.Name == "VSOCK_RUNNING" {
wait = true
}
}

if !wait {
return nil
}

q.Logger().Info("waiting event of vsock running")
for {
ev := <-eventCh
if ev.Name == "VSOCK_RUNNING" && ev.Data["running"] == true {
break
}
}

return nil
}

Expand Down

0 comments on commit 82841e1

Please sign in to comment.