mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 11:44:38 +00:00
qemu: Add an Object slice field to the Config structure
The Object slice tells qemu which specific object to create. Qemu objects can represent memory backend files, random number generators, TLS credentials, etc... Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
8744dfe85e
commit
b973bc59fb
47
qemu.go
47
qemu.go
@ -56,6 +56,22 @@ type Device struct {
|
||||
CharDev string
|
||||
}
|
||||
|
||||
// Object is a qemu object representation.
|
||||
type Object struct {
|
||||
// Type is the qemu object type
|
||||
Type string
|
||||
|
||||
// ID is the user defined object ID.
|
||||
ID string
|
||||
|
||||
// MemPath is the object's memory path.
|
||||
// This is only relevant for memory objects
|
||||
MemPath string
|
||||
|
||||
// Size is the object size in bytes
|
||||
Size uint64
|
||||
}
|
||||
|
||||
// QMPSocket represents a qemu QMP socket configuration.
|
||||
type QMPSocket struct {
|
||||
// Type is the socket type (e.g. "unix").
|
||||
@ -98,6 +114,9 @@ type Config struct {
|
||||
// Devices is a list of devices for qemu to create.
|
||||
Devices []Device
|
||||
|
||||
// Objects is a list of objects for qemu to create.
|
||||
Objects []Object
|
||||
|
||||
// ExtraParams is a slice of options to pass to qemu.
|
||||
ExtraParams []string
|
||||
|
||||
@ -187,6 +206,33 @@ func appendDevices(params []string, config Config) []string {
|
||||
return params
|
||||
}
|
||||
|
||||
func appendObjects(params []string, config Config) []string {
|
||||
for _, o := range config.Objects {
|
||||
if o.Type != "" {
|
||||
var objectParams []string
|
||||
|
||||
objectParams = append(objectParams, o.Type)
|
||||
|
||||
if o.ID != "" {
|
||||
objectParams = append(objectParams, fmt.Sprintf(",id=%s", o.ID))
|
||||
}
|
||||
|
||||
if o.MemPath != "" {
|
||||
objectParams = append(objectParams, fmt.Sprintf(",mem-path=%s", o.MemPath))
|
||||
}
|
||||
|
||||
if o.Size > 0 {
|
||||
objectParams = append(objectParams, fmt.Sprintf(",size=%d", o.Size))
|
||||
}
|
||||
|
||||
params = append(params, "-object")
|
||||
params = append(params, strings.Join(objectParams, ""))
|
||||
}
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
// LaunchQemu can be used to launch a new qemu instance.
|
||||
//
|
||||
// The Config parameter contains a set of qemu parameters and settings.
|
||||
@ -204,6 +250,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
|
||||
params = appendCPUModel(params, config)
|
||||
params = appendQMPSocket(params, config)
|
||||
params = appendDevices(params, config)
|
||||
params = appendObjects(params, config)
|
||||
|
||||
params = append(params, config.ExtraParams...)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user