mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-17 15:38:00 +00:00
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:
parent
5dffffd432
commit
ea1d799f79
@ -199,10 +199,7 @@ func (q *qemu) qemuPath() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p == "" {
|
if p == "" {
|
||||||
p, err = q.arch.qemuPath()
|
p = q.arch.qemuPath()
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = os.Stat(p); os.IsNotExist(err) {
|
if _, err = os.Stat(p); os.IsNotExist(err) {
|
||||||
|
@ -116,8 +116,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
|||||||
q := &qemuAmd64{
|
q := &qemuAmd64{
|
||||||
qemuArchBase: qemuArchBase{
|
qemuArchBase: qemuArchBase{
|
||||||
qemuMachine: *mp,
|
qemuMachine: *mp,
|
||||||
|
qemuExePath: qemuPaths[machineType],
|
||||||
memoryOffset: config.MemOffset,
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
kernelParamsDebug: kernelParamsDebug,
|
kernelParamsDebug: kernelParamsDebug,
|
||||||
kernelParams: kernelParams,
|
kernelParams: kernelParams,
|
||||||
|
@ -41,7 +41,7 @@ type qemuArch interface {
|
|||||||
machine() govmmQemu.Machine
|
machine() govmmQemu.Machine
|
||||||
|
|
||||||
// qemuPath returns the path to the QEMU binary
|
// qemuPath returns the path to the QEMU binary
|
||||||
qemuPath() (string, error)
|
qemuPath() string
|
||||||
|
|
||||||
// kernelParameters returns the kernel parameters
|
// kernelParameters returns the kernel parameters
|
||||||
// if debug is true then kernel debug parameters are included
|
// if debug is true then kernel debug parameters are included
|
||||||
@ -137,13 +137,13 @@ type qemuArch interface {
|
|||||||
|
|
||||||
type qemuArchBase struct {
|
type qemuArchBase struct {
|
||||||
qemuMachine govmmQemu.Machine
|
qemuMachine govmmQemu.Machine
|
||||||
|
qemuExePath string
|
||||||
memoryOffset uint32
|
memoryOffset uint32
|
||||||
nestedRun bool
|
nestedRun bool
|
||||||
vhost bool
|
vhost bool
|
||||||
disableNvdimm bool
|
disableNvdimm bool
|
||||||
dax bool
|
dax bool
|
||||||
networkIndex int
|
networkIndex int
|
||||||
qemuPaths map[string]string
|
|
||||||
kernelParamsNonDebug []Param
|
kernelParamsNonDebug []Param
|
||||||
kernelParamsDebug []Param
|
kernelParamsDebug []Param
|
||||||
kernelParams []Param
|
kernelParams []Param
|
||||||
@ -242,13 +242,8 @@ func (q *qemuArchBase) machine() govmmQemu.Machine {
|
|||||||
return q.qemuMachine
|
return q.qemuMachine
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemuArchBase) qemuPath() (string, error) {
|
func (q *qemuArchBase) qemuPath() string {
|
||||||
p, ok := q.qemuPaths[q.qemuMachine.Type]
|
return q.qemuExePath
|
||||||
if !ok {
|
|
||||||
return "", fmt.Errorf("Unknown machine type: %s", q.qemuMachine.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
return p, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemuArchBase) kernelParameters(debug bool) []Param {
|
func (q *qemuArchBase) kernelParameters(debug bool) []Param {
|
||||||
|
@ -53,8 +53,8 @@ var qemuArchBaseKernelParams = []Param{
|
|||||||
func newQemuArchBase() *qemuArchBase {
|
func newQemuArchBase() *qemuArchBase {
|
||||||
return &qemuArchBase{
|
return &qemuArchBase{
|
||||||
qemuMachine: qemuArchBaseMachine,
|
qemuMachine: qemuArchBaseMachine,
|
||||||
|
qemuExePath: qemuArchBaseQemuPaths[qemuArchBaseMachine.Type],
|
||||||
nestedRun: false,
|
nestedRun: false,
|
||||||
qemuPaths: qemuArchBaseQemuPaths,
|
|
||||||
kernelParamsNonDebug: qemuArchBaseKernelParamsNonDebug,
|
kernelParamsNonDebug: qemuArchBaseKernelParamsNonDebug,
|
||||||
kernelParamsDebug: qemuArchBaseKernelParamsDebug,
|
kernelParamsDebug: qemuArchBaseKernelParamsDebug,
|
||||||
kernelParams: qemuArchBaseKernelParams,
|
kernelParams: qemuArchBaseKernelParams,
|
||||||
@ -89,17 +89,8 @@ func TestQemuArchBaseQemuPath(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
qemuArchBase := newQemuArchBase()
|
qemuArchBase := newQemuArchBase()
|
||||||
|
|
||||||
p, err := qemuArchBase.qemuPath()
|
p := qemuArchBase.qemuPath()
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(p, qemuArchBaseQemuPath)
|
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) {
|
func TestQemuArchBaseKernelParameters(t *testing.T) {
|
||||||
|
@ -30,10 +30,6 @@ const qmpMigrationWaitTimeout = 10 * time.Second
|
|||||||
|
|
||||||
var defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=" + getGuestGICVersion()
|
var defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=" + getGuestGICVersion()
|
||||||
|
|
||||||
var qemuPaths = map[string]string{
|
|
||||||
QemuVirt: defaultQemuPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
var kernelParams = []Param{
|
var kernelParams = []Param{
|
||||||
{"console", "hvc0"},
|
{"console", "hvc0"},
|
||||||
{"console", "hvc1"},
|
{"console", "hvc1"},
|
||||||
@ -136,8 +132,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
|||||||
q := &qemuArm64{
|
q := &qemuArm64{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
qemuMachine: supportedQemuMachine,
|
qemuMachine: supportedQemuMachine,
|
||||||
|
qemuExePath: defaultQemuPath,
|
||||||
memoryOffset: config.MemOffset,
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
kernelParamsDebug: kernelParamsDebug,
|
kernelParamsDebug: kernelParamsDebug,
|
||||||
kernelParams: kernelParams,
|
kernelParams: kernelParams,
|
||||||
|
@ -27,10 +27,6 @@ const defaultQemuMachineOptions = "accel=kvm,usb=off"
|
|||||||
|
|
||||||
const qmpMigrationWaitTimeout = 5 * time.Second
|
const qmpMigrationWaitTimeout = 5 * time.Second
|
||||||
|
|
||||||
var qemuPaths = map[string]string{
|
|
||||||
QemuPseries: defaultQemuPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
var kernelParams = []Param{
|
var kernelParams = []Param{
|
||||||
{"rcupdate.rcu_expedited", "1"},
|
{"rcupdate.rcu_expedited", "1"},
|
||||||
{"reboot", "k"},
|
{"reboot", "k"},
|
||||||
@ -68,8 +64,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
|||||||
q := &qemuPPC64le{
|
q := &qemuPPC64le{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
qemuMachine: supportedQemuMachine,
|
qemuMachine: supportedQemuMachine,
|
||||||
|
qemuExePath: defaultQemuPath,
|
||||||
memoryOffset: config.MemOffset,
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
kernelParamsDebug: kernelParamsDebug,
|
kernelParamsDebug: kernelParamsDebug,
|
||||||
kernelParams: kernelParams,
|
kernelParams: kernelParams,
|
||||||
|
@ -29,10 +29,6 @@ const virtioSerialCCW = "virtio-serial-ccw"
|
|||||||
|
|
||||||
const qmpMigrationWaitTimeout = 5 * time.Second
|
const qmpMigrationWaitTimeout = 5 * time.Second
|
||||||
|
|
||||||
var qemuPaths = map[string]string{
|
|
||||||
QemuCCWVirtio: defaultQemuPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify needed parameters
|
// Verify needed parameters
|
||||||
var kernelParams = []Param{
|
var kernelParams = []Param{
|
||||||
{"console", "ttysclp0"},
|
{"console", "ttysclp0"},
|
||||||
@ -66,8 +62,8 @@ func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
|||||||
q := &qemuS390x{
|
q := &qemuS390x{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
qemuMachine: supportedQemuMachine,
|
qemuMachine: supportedQemuMachine,
|
||||||
|
qemuExePath: defaultQemuPath,
|
||||||
memoryOffset: config.MemOffset,
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
kernelParamsDebug: kernelParamsDebug,
|
kernelParamsDebug: kernelParamsDebug,
|
||||||
kernelParams: kernelParams,
|
kernelParams: kernelParams,
|
||||||
|
@ -346,9 +346,7 @@ func TestQemuQemuPath(t *testing.T) {
|
|||||||
Type: "pc",
|
Type: "pc",
|
||||||
Options: "",
|
Options: "",
|
||||||
},
|
},
|
||||||
qemuPaths: map[string]string{
|
qemuExePath: expectedPath,
|
||||||
"pc": expectedPath,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
q := &qemu{
|
q := &qemu{
|
||||||
@ -372,13 +370,6 @@ func TestQemuQemuPath(t *testing.T) {
|
|||||||
path, err = q.qemuPath()
|
path, err = q.qemuPath()
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(path, expectedPath)
|
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) {
|
func TestHotplugUnsupportedDeviceType(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user