qemu: add options for the machine type

certain machines types need to have options to enable or disable features
For example the machine type virt in certain hosts must have the gic version
(gic-version=3 or gic-version=host) to start without problems

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2018-02-12 08:14:02 -06:00
parent 065d1d2517
commit 693d9548dc
2 changed files with 16 additions and 2 deletions

View File

@ -43,6 +43,10 @@ type Machine struct {
// Acceleration are the machine acceleration options to be used by qemu.
Acceleration string
// Options are options for the machine type
// For example gic-version=host and usb=off
Options string
}
// Device is the qemu device interface.
@ -1240,6 +1244,10 @@ func (config *Config) appendMachine() {
machineParams = append(machineParams, fmt.Sprintf(",accel=%s", config.Machine.Acceleration))
}
if config.Machine.Options != "" {
machineParams = append(machineParams, fmt.Sprintf(",%s", config.Machine.Options))
}
config.qemuParams = append(config.qemuParams, "-machine")
config.qemuParams = append(config.qemuParams, strings.Join(machineParams, ""))
}

View File

@ -75,14 +75,20 @@ func testAppend(structure interface{}, expected string, t *testing.T) {
}
}
var machineString = "-machine pc-lite,accel=kvm,kernel_irqchip,nvdimm"
func TestAppendMachine(t *testing.T) {
machineString := "-machine pc-lite,accel=kvm,kernel_irqchip,nvdimm"
machine := Machine{
Type: "pc-lite",
Acceleration: "kvm,kernel_irqchip,nvdimm",
}
testAppend(machine, machineString, t)
machineString = "-machine pc-lite,accel=kvm,kernel_irqchip,nvdimm,gic-version=host,usb=off"
machine = Machine{
Type: "pc-lite",
Acceleration: "kvm,kernel_irqchip,nvdimm",
Options: "gic-version=host,usb=off",
}
testAppend(machine, machineString, t)
}