Skip to content

Commit

Permalink
qemu: Add QMPSocket specific type
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Samuel Ortiz committed Sep 16, 2016
1 parent 2d736d7 commit cc9cb33
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 33 additions & 14 deletions qemu.go
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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")
}
}
if config.QMPSocket.Valid() == false {
return nil
}

var qmpParams []string

params = append(params, "-qmp")
params = append(params, strings.Join(qmpParams, ""))
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
}

Expand Down
2 changes: 1 addition & 1 deletion qemu_test.go
Expand Up @@ -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,
}
Expand Down

0 comments on commit cc9cb33

Please sign in to comment.