qemu: Support creating multiple QMP sockets

The QMP socket implementation does not support multiple clients sending
and receiving QMP commands. As a consequence we need to be able to
create multiple QMP sockets from the qemu package, so that at least we
can support a fixed number of QMP clients.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2016-10-11 14:32:41 +02:00
parent 992b861ec5
commit 6fe338d604
2 changed files with 52 additions and 27 deletions

38
qemu.go
View File

@ -695,8 +695,8 @@ type Config struct {
// Machine // Machine
Machine Machine Machine Machine
// QMPSocket is the QMP socket description. // QMPSockets is a slice of QMP socket description.
QMPSocket QMPSocket QMPSockets []QMPSocket
// Devices is a list of devices for qemu to create and drive. // Devices is a list of devices for qemu to create and drive.
Devices []Device Devices []Device
@ -777,24 +777,24 @@ func (config *Config) appendCPUModel() {
} }
} }
func (config *Config) appendQMPSocket() { func (config *Config) appendQMPSockets() {
if config.QMPSocket.Valid() == false { for _, q := range config.QMPSockets {
return if q.Valid() == false {
} continue
var qmpParams []string
qmpParams = append(qmpParams, fmt.Sprintf("%s:", config.QMPSocket.Type))
qmpParams = append(qmpParams, fmt.Sprintf("%s", config.QMPSocket.Name))
if config.QMPSocket.Server == true {
qmpParams = append(qmpParams, ",server")
if config.QMPSocket.NoWait == true {
qmpParams = append(qmpParams, ",nowait")
} }
}
config.qemuParams = append(config.qemuParams, "-qmp") qmpParams := append([]string{}, fmt.Sprintf("%s:", q.Type))
config.qemuParams = append(config.qemuParams, strings.Join(qmpParams, "")) qmpParams = append(qmpParams, fmt.Sprintf("%s", q.Name))
if q.Server == true {
qmpParams = append(qmpParams, ",server")
if q.NoWait == true {
qmpParams = append(qmpParams, ",nowait")
}
}
config.qemuParams = append(config.qemuParams, "-qmp")
config.qemuParams = append(config.qemuParams, strings.Join(qmpParams, ""))
}
} }
func (config *Config) appendDevices() { func (config *Config) appendDevices() {
@ -935,7 +935,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
config.appendUUID() config.appendUUID()
config.appendMachine() config.appendMachine()
config.appendCPUModel() config.appendCPUModel()
config.appendQMPSocket() config.appendQMPSockets()
config.appendMemory() config.appendMemory()
config.appendCPUs() config.appendCPUs()
config.appendDevices() config.appendDevices()

View File

@ -54,8 +54,12 @@ func testAppend(structure interface{}, expected string, t *testing.T) {
config.appendCPUs() config.appendCPUs()
case QMPSocket: case QMPSocket:
config.QMPSocket = s config.QMPSockets = []QMPSocket{s}
config.appendQMPSocket() config.appendQMPSockets()
case []QMPSocket:
config.QMPSockets = s
config.appendQMPSockets()
case RTC: case RTC:
config.RTC = s config.RTC = s
@ -232,10 +236,10 @@ func TestAppendCPUs(t *testing.T) {
testAppend(smp, cpusString, t) testAppend(smp, cpusString, t)
} }
var qmpSocketServerString = "-qmp unix:cc-qmp,server,nowait" var qmpSingleSocketServerString = "-qmp unix:cc-qmp,server,nowait"
var qmpSocketString = "-qmp unix:cc-qmp" var qmpSingleSocketString = "-qmp unix:cc-qmp"
func TestAppendQMPSocketServer(t *testing.T) { func TestAppendSingleQMPSocketServer(t *testing.T) {
qmp := QMPSocket{ qmp := QMPSocket{
Type: "unix", Type: "unix",
Name: "cc-qmp", Name: "cc-qmp",
@ -243,17 +247,38 @@ func TestAppendQMPSocketServer(t *testing.T) {
NoWait: true, NoWait: true,
} }
testAppend(qmp, qmpSocketServerString, t) testAppend(qmp, qmpSingleSocketServerString, t)
} }
func TestAppendQMPSocket(t *testing.T) { func TestAppendSingleQMPSocket(t *testing.T) {
qmp := QMPSocket{ qmp := QMPSocket{
Type: Unix, Type: Unix,
Name: "cc-qmp", Name: "cc-qmp",
Server: false, Server: false,
} }
testAppend(qmp, qmpSocketString, t) testAppend(qmp, qmpSingleSocketString, t)
}
var qmpSocketServerString = "-qmp unix:cc-qmp-1,server,nowait -qmp unix:cc-qmp-2,server,nowait"
func TestAppendQMPSocketServer(t *testing.T) {
qmp := []QMPSocket{
{
Type: "unix",
Name: "cc-qmp-1",
Server: true,
NoWait: true,
},
{
Type: "unix",
Name: "cc-qmp-2",
Server: true,
NoWait: true,
},
}
testAppend(qmp, qmpSocketServerString, t)
} }
var qemuString = "-name cc-qemu -cpu host -uuid " + testutil.AgentUUID var qemuString = "-name cc-qemu -cpu host -uuid " + testutil.AgentUUID