1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-04-29 04:04:45 +00:00

qemu: Add QMPSocket specific type

Instead of open coding the QMP socket type, we now have a specific type
for it.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2016-09-16 18:56:19 +02:00
parent 2d736d7173
commit cc9cb33a5d
2 changed files with 35 additions and 16 deletions

49
qemu.go
View File

@ -391,10 +391,18 @@ func (rtc RTC) Valid() bool {
return true
}
// QMPSocketType is the type of socket used for QMP communication.
type QMPSocketType string
const (
// Unix socket for QMP.
Unix QMPSocketType = "unix"
)
// QMPSocket represents a qemu QMP socket configuration.
type QMPSocket struct {
// Type is the socket type (e.g. "unix").
Type string
Type QMPSocketType
// Name is the socket name.
Name string
@ -406,6 +414,15 @@ type QMPSocket struct {
NoWait bool
}
// Valid returns true if the QMPSocket structure is valid and complete.
func (qmp QMPSocket) Valid() bool {
if qmp.Type == "" || qmp.Name == "" {
return false
}
return true
}
// SMP is the multi processors configuration structure.
type SMP struct {
// CPUs is the number of VCPUs made available to qemu.
@ -545,22 +562,24 @@ func appendCPUModel(params []string, config Config) []string {
}
func appendQMPSocket(params []string, config Config) []string {
if config.QMPSocket.Type != "" && config.QMPSocket.Name != "" {
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")
}
}
params = append(params, "-qmp")
params = append(params, strings.Join(qmpParams, ""))
if config.QMPSocket.Valid() == false {
return nil
}
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")
}
}
params = append(params, "-qmp")
params = append(params, strings.Join(qmpParams, ""))
return params
}

View File

@ -259,7 +259,7 @@ func TestAppendQMPSocketServer(t *testing.T) {
func TestAppendQMPSocket(t *testing.T) {
qmp := QMPSocket{
Type: "unix",
Type: Unix,
Name: "cc-qmp",
Server: false,
}