mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
govmm: Optionally start QMP with a pre-configured connection
When QEMU is launched daemonized, we have the guarantee that the QMP socket is available. In order to launch a non-daemonized QEMU, the QMP connection should be created before QEMU is started in order to avoid a race. Introduce a variant of QMPStart() that can use such an existing connection. Signed-off-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
parent
856d4b7361
commit
219bb8e7d0
@ -702,6 +702,16 @@ func QMPStart(ctx context.Context, socket string, cfg QMPConfig, disconnectedCh
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return QMPStartWithConn(ctx, conn, cfg, disconnectedCh)
|
||||
}
|
||||
|
||||
// Same as QMPStart but with a pre-established connection
|
||||
func QMPStartWithConn(ctx context.Context, conn net.Conn, cfg QMPConfig, disconnectedCh chan struct{}) (*QMP, *QMPVersion, error) {
|
||||
if conn == nil {
|
||||
close(disconnectedCh)
|
||||
return nil, nil, fmt.Errorf("invalid connection")
|
||||
}
|
||||
|
||||
connectedCh := make(chan *QMPVersion)
|
||||
|
||||
q := startQMPLoop(conn, cfg, connectedCh, disconnectedCh)
|
||||
|
@ -273,6 +273,22 @@ func TestQMPStartBadPath(t *testing.T) {
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
// Checks that a call to QMPStartWithConn with a nil connection exits gracefully.
|
||||
//
|
||||
// We call QMPStartWithConn with a nil connection.
|
||||
//
|
||||
// An error should be returned and the disconnected channel should be closed.
|
||||
func TestQMPStartWithConnNil(t *testing.T) {
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
disconnectedCh := make(chan struct{})
|
||||
q, _, err := QMPStartWithConn(context.Background(), nil, cfg, disconnectedCh)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error")
|
||||
q.Shutdown()
|
||||
}
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
// Checks that the qmp_capabilities command is correctly sent.
|
||||
//
|
||||
// We start a QMPLoop, send the qmp_capabilities command and stop the
|
||||
|
Loading…
Reference in New Issue
Block a user