mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
qemu: Add a QMP socket field to the Config structure
QMP sockets are used to send qemu specific commands to the running qemu process. The QMPSocket structure allows us to define the socket type we want, along with its name. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
171182709d
commit
5458de70ad
43
qemu.go
43
qemu.go
@ -29,10 +29,26 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
)
|
||||
|
||||
// QMPSocket represents a qemu QMP socket configuration.
|
||||
type QMPSocket struct {
|
||||
// Type is the socket type (e.g. "unix").
|
||||
Type string
|
||||
|
||||
// Name is the socket name.
|
||||
Name string
|
||||
|
||||
// Server tells if this is a server socket.
|
||||
Server bool
|
||||
|
||||
// NoWait tells if qemu should block waiting for a client to connect.
|
||||
NoWait bool
|
||||
}
|
||||
|
||||
// Config is the qemu configuration structure.
|
||||
// It allows for passing custom settings and parameters to the qemu API.
|
||||
type Config struct {
|
||||
@ -44,7 +60,7 @@ type Config struct {
|
||||
|
||||
// Name is the qemu guest name
|
||||
Name string
|
||||
|
||||
|
||||
// MachineType is the machine type to be used by qemu.
|
||||
MachineType string
|
||||
|
||||
@ -54,6 +70,9 @@ type Config struct {
|
||||
// CPUModel is the CPU model to be used by qemu.
|
||||
CPUModel string
|
||||
|
||||
// QMPSocket is the QMP socket description
|
||||
QMPSocket QMPSocket
|
||||
|
||||
// ExtraParams is a slice of options to pass to qemu.
|
||||
ExtraParams []string
|
||||
|
||||
@ -88,6 +107,26 @@ func appendCPUModel(params []string, config Config) []string {
|
||||
return params
|
||||
}
|
||||
|
||||
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, ""))
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
// LaunchQemu can be used to launch a new qemu instance.
|
||||
//
|
||||
// The Config parameter contains a set of qemu parameters and settings.
|
||||
@ -103,6 +142,8 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
|
||||
params = appendName(params, config)
|
||||
params = appendMachineParams(params, config)
|
||||
params = appendCPUModel(params, config)
|
||||
params = appendQMPSocket(params, config)
|
||||
|
||||
params = append(params, config.ExtraParams...)
|
||||
|
||||
return LaunchCustomQemu(config.Ctx, config.Path, params, config.FDs, logger)
|
||||
|
Loading…
Reference in New Issue
Block a user