qemu: Add a Filesystem Devices slice field to the Config structure

Each Filesystem device should have a corresponding "virtio-9p-pci"
Device driver. They represent a filesystem to be exported through 9pfs.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2016-09-12 18:18:30 +02:00
parent 518ba627b1
commit 73e2d53c9a

47
qemu.go
View File

@ -72,6 +72,22 @@ type Object struct {
Size uint64
}
// FSDevice represents a qemu filesystem configuration.
type FSDevice struct {
// Type is the filesystem device type (e.g. "local")
Type string
// ID is the filesystem identifier.
// It should match an existing Device ID.
ID string
// Path is the host root path for this filesystem.
Path string
// SecurityModel is the security model for this filesystem device.
SecurityModel string
}
// QMPSocket represents a qemu QMP socket configuration.
type QMPSocket struct {
// Type is the socket type (e.g. "unix").
@ -126,6 +142,9 @@ type Config struct {
// Objects is a list of objects for qemu to create.
Objects []Object
// FilesystemDevices is a list of filesystem devices.
FilesystemDevices []FSDevice
// Kernel is the guest kernel configuration.
Kernel Kernel
@ -245,6 +264,33 @@ func appendObjects(params []string, config Config) []string {
return params
}
func appendFilesystemDevices(params []string, config Config) []string {
for _, f := range config.FilesystemDevices {
if f.Type != "" {
var fsParams []string
fsParams = append(fsParams, fmt.Sprintf("%s", f.Type))
if f.ID != "" {
fsParams = append(fsParams, fmt.Sprintf(",id=%s", f.ID))
}
if f.Path != "" {
fsParams = append(fsParams, fmt.Sprintf(",path=%s", f.Path))
}
if f.SecurityModel != "" {
fsParams = append(fsParams, fmt.Sprintf(",security-model=%s", f.SecurityModel))
}
params = append(params, "-fsdev")
params = append(params, strings.Join(fsParams, ""))
}
}
return params
}
func appendKernel(params []string, config Config) []string {
if config.Kernel.Path != "" {
params = append(params, "-kernel")
@ -276,6 +322,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
params = appendCPUModel(params, config)
params = appendQMPSocket(params, config)
params = appendDevices(params, config)
params = appendFilesystemDevices(params, config)
params = appendObjects(params, config)
params = appendKernel(params, config)