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:
parent
2d736d7173
commit
cc9cb33a5d
49
qemu.go
49
qemu.go
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user