qemu: Only one element of qemuPaths map is relevant

The qemuPaths field in qemuArchBase maps from machine type to the default
qemu path.  But, by the time we construct it, we already know the machine
type, so that entry ends up being the only one we care about.

So, collapse the map into a single path.  As a bonus, the qemuPath()
method can no longer fail.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2020-06-20 20:04:49 +10:00
parent 5dffffd432
commit ea1d799f79
8 changed files with 12 additions and 50 deletions

View File

@ -199,10 +199,7 @@ func (q *qemu) qemuPath() (string, error) {
}
if p == "" {
p, err = q.arch.qemuPath()
if err != nil {
return "", err
}
p = q.arch.qemuPath()
}
if _, err = os.Stat(p); os.IsNotExist(err) {

View File

@ -116,8 +116,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
q := &qemuAmd64{
qemuArchBase: qemuArchBase{
qemuMachine: *mp,
qemuExePath: qemuPaths[machineType],
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
kernelParamsNonDebug: kernelParamsNonDebug,
kernelParamsDebug: kernelParamsDebug,
kernelParams: kernelParams,

View File

@ -41,7 +41,7 @@ type qemuArch interface {
machine() govmmQemu.Machine
// qemuPath returns the path to the QEMU binary
qemuPath() (string, error)
qemuPath() string
// kernelParameters returns the kernel parameters
// if debug is true then kernel debug parameters are included
@ -137,13 +137,13 @@ type qemuArch interface {
type qemuArchBase struct {
qemuMachine govmmQemu.Machine
qemuExePath string
memoryOffset uint32
nestedRun bool
vhost bool
disableNvdimm bool
dax bool
networkIndex int
qemuPaths map[string]string
kernelParamsNonDebug []Param
kernelParamsDebug []Param
kernelParams []Param
@ -242,13 +242,8 @@ func (q *qemuArchBase) machine() govmmQemu.Machine {
return q.qemuMachine
}
func (q *qemuArchBase) qemuPath() (string, error) {
p, ok := q.qemuPaths[q.qemuMachine.Type]
if !ok {
return "", fmt.Errorf("Unknown machine type: %s", q.qemuMachine.Type)
}
return p, nil
func (q *qemuArchBase) qemuPath() string {
return q.qemuExePath
}
func (q *qemuArchBase) kernelParameters(debug bool) []Param {

View File

@ -53,8 +53,8 @@ var qemuArchBaseKernelParams = []Param{
func newQemuArchBase() *qemuArchBase {
return &qemuArchBase{
qemuMachine: qemuArchBaseMachine,
qemuExePath: qemuArchBaseQemuPaths[qemuArchBaseMachine.Type],
nestedRun: false,
qemuPaths: qemuArchBaseQemuPaths,
kernelParamsNonDebug: qemuArchBaseKernelParamsNonDebug,
kernelParamsDebug: qemuArchBaseKernelParamsDebug,
kernelParams: qemuArchBaseKernelParams,
@ -89,17 +89,8 @@ func TestQemuArchBaseQemuPath(t *testing.T) {
assert := assert.New(t)
qemuArchBase := newQemuArchBase()
p, err := qemuArchBase.qemuPath()
assert.NoError(err)
p := qemuArchBase.qemuPath()
assert.Equal(p, qemuArchBaseQemuPath)
paths := map[string]string{
"bad": qemuArchBaseQemuPath,
}
qemuArchBase.qemuPaths = paths
p, err = qemuArchBase.qemuPath()
assert.Error(err)
assert.Equal("", p)
}
func TestQemuArchBaseKernelParameters(t *testing.T) {

View File

@ -30,10 +30,6 @@ const qmpMigrationWaitTimeout = 10 * time.Second
var defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=" + getGuestGICVersion()
var qemuPaths = map[string]string{
QemuVirt: defaultQemuPath,
}
var kernelParams = []Param{
{"console", "hvc0"},
{"console", "hvc1"},
@ -136,8 +132,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
q := &qemuArm64{
qemuArchBase{
qemuMachine: supportedQemuMachine,
qemuExePath: defaultQemuPath,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
kernelParamsNonDebug: kernelParamsNonDebug,
kernelParamsDebug: kernelParamsDebug,
kernelParams: kernelParams,

View File

@ -27,10 +27,6 @@ const defaultQemuMachineOptions = "accel=kvm,usb=off"
const qmpMigrationWaitTimeout = 5 * time.Second
var qemuPaths = map[string]string{
QemuPseries: defaultQemuPath,
}
var kernelParams = []Param{
{"rcupdate.rcu_expedited", "1"},
{"reboot", "k"},
@ -68,8 +64,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
q := &qemuPPC64le{
qemuArchBase{
qemuMachine: supportedQemuMachine,
qemuExePath: defaultQemuPath,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
kernelParamsNonDebug: kernelParamsNonDebug,
kernelParamsDebug: kernelParamsDebug,
kernelParams: kernelParams,

View File

@ -29,10 +29,6 @@ const virtioSerialCCW = "virtio-serial-ccw"
const qmpMigrationWaitTimeout = 5 * time.Second
var qemuPaths = map[string]string{
QemuCCWVirtio: defaultQemuPath,
}
// Verify needed parameters
var kernelParams = []Param{
{"console", "ttysclp0"},
@ -66,8 +62,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
q := &qemuS390x{
qemuArchBase{
qemuMachine: supportedQemuMachine,
qemuExePath: defaultQemuPath,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
kernelParamsNonDebug: kernelParamsNonDebug,
kernelParamsDebug: kernelParamsDebug,
kernelParams: kernelParams,

View File

@ -346,9 +346,7 @@ func TestQemuQemuPath(t *testing.T) {
Type: "pc",
Options: "",
},
qemuPaths: map[string]string{
"pc": expectedPath,
},
qemuExePath: expectedPath,
}
q := &qemu{
@ -372,13 +370,6 @@ func TestQemuQemuPath(t *testing.T) {
path, err = q.qemuPath()
assert.NoError(err)
assert.Equal(path, expectedPath)
// bad machine type, arch should fail
qkvm.qemuMachine.Type = "rgb"
q.arch = qkvm
path, err = q.qemuPath()
assert.Error(err)
assert.Equal(path, "")
}
func TestHotplugUnsupportedDeviceType(t *testing.T) {