mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-13 13:46:46 +00:00
Merge pull request #320 from dgibson/cleanups
Clean up some unnecessary data structures
This commit is contained in:
commit
9d90906546
@ -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) {
|
||||
@ -238,7 +235,10 @@ func (q *qemu) setup(id string, hypervisorConfig *HypervisorConfig) error {
|
||||
|
||||
q.id = id
|
||||
q.config = *hypervisorConfig
|
||||
q.arch = newQemuArch(q.config)
|
||||
q.arch, err = newQemuArch(q.config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
initrdPath, err := q.config.InitrdAssetPath()
|
||||
if err != nil {
|
||||
@ -332,10 +332,7 @@ func (q *qemu) qmpSocketPath(id string) (string, error) {
|
||||
}
|
||||
|
||||
func (q *qemu) getQemuMachine() (govmmQemu.Machine, error) {
|
||||
machine, err := q.arch.machine()
|
||||
if err != nil {
|
||||
return govmmQemu.Machine{}, err
|
||||
}
|
||||
machine := q.arch.machine()
|
||||
|
||||
accelerators := q.config.MachineAccelerators
|
||||
if accelerators != "" {
|
||||
@ -1536,10 +1533,7 @@ func (q *qemu) hotplugAddCPUs(amount uint32) (uint32, error) {
|
||||
return 0, fmt.Errorf("failed to query hotpluggable CPUs: %v", err)
|
||||
}
|
||||
|
||||
machine, err := q.arch.machine()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to query machine type: %v", err)
|
||||
}
|
||||
machine := q.arch.machine()
|
||||
|
||||
var hotpluggedVCPUs uint32
|
||||
for _, hc := range hotpluggableVCPUs {
|
||||
@ -2169,7 +2163,10 @@ func (q *qemu) fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig,
|
||||
q.qmpMonitorCh.path = qp.QmpChannelpath
|
||||
q.qemuConfig.Ctx = ctx
|
||||
q.state = qp.State
|
||||
q.arch = newQemuArch(q.config)
|
||||
q.arch, err = newQemuArch(q.config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q.ctx = ctx
|
||||
q.nvdimmCount = qp.NvdimmCount
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
@ -77,18 +78,28 @@ func MaxQemuVCPUs() uint32 {
|
||||
return uint32(240)
|
||||
}
|
||||
|
||||
func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
||||
machineType := config.HypervisorMachineType
|
||||
if machineType == "" {
|
||||
machineType = defaultQemuMachineType
|
||||
}
|
||||
|
||||
var mp *govmmQemu.Machine
|
||||
for _, m := range supportedQemuMachines {
|
||||
if m.Type == machineType {
|
||||
mp = &m
|
||||
break
|
||||
}
|
||||
}
|
||||
if mp == nil {
|
||||
return nil, fmt.Errorf("unrecognised machinetype: %v", machineType)
|
||||
}
|
||||
|
||||
factory := false
|
||||
if config.BootToBeTemplate || config.BootFromTemplate {
|
||||
factory = true
|
||||
}
|
||||
|
||||
var qemuMachines = supportedQemuMachines
|
||||
if config.IOMMU {
|
||||
var q35QemuIOMMUOptions = "accel=kvm,kernel_irqchip=split"
|
||||
|
||||
@ -97,22 +108,16 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
kernelParams = append(kernelParams,
|
||||
Param{"iommu", "pt"})
|
||||
|
||||
for i, m := range qemuMachines {
|
||||
if m.Type == QemuQ35 {
|
||||
qemuMachines[i].Options = q35QemuIOMMUOptions
|
||||
}
|
||||
if mp.Type == QemuQ35 {
|
||||
mp.Options = q35QemuIOMMUOptions
|
||||
}
|
||||
} else {
|
||||
kernelParams = append(kernelParams,
|
||||
Param{"iommu", "off"})
|
||||
}
|
||||
|
||||
q := &qemuAmd64{
|
||||
qemuArchBase: qemuArchBase{
|
||||
machineType: machineType,
|
||||
qemuMachine: *mp,
|
||||
qemuExePath: qemuPaths[machineType],
|
||||
memoryOffset: config.MemOffset,
|
||||
qemuPaths: qemuPaths,
|
||||
supportedQemuMachines: qemuMachines,
|
||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||
kernelParamsDebug: kernelParamsDebug,
|
||||
kernelParams: kernelParams,
|
||||
@ -124,15 +129,15 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
|
||||
q.handleImagePath(config)
|
||||
|
||||
return q
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (q *qemuAmd64) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
|
||||
if q.machineType == QemuPC ||
|
||||
q.machineType == QemuQ35 ||
|
||||
q.machineType == QemuVirt {
|
||||
if q.qemuMachine.Type == QemuPC ||
|
||||
q.qemuMachine.Type == QemuQ35 ||
|
||||
q.qemuMachine.Type == QemuVirt {
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
}
|
||||
|
||||
@ -143,7 +148,7 @@ func (q *qemuAmd64) capabilities() types.Capabilities {
|
||||
}
|
||||
|
||||
func (q *qemuAmd64) bridges(number uint32) {
|
||||
q.Bridges = genericBridges(number, q.machineType)
|
||||
q.Bridges = genericBridges(number, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
func (q *qemuAmd64) cpuModel() string {
|
||||
@ -175,5 +180,5 @@ func (q *qemuAmd64) appendImage(devices []govmmQemu.Device, path string) ([]govm
|
||||
|
||||
// appendBridges appends to devices the given bridges
|
||||
func (q *qemuAmd64) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
|
||||
return genericAppendBridges(devices, q.Bridges, q.machineType)
|
||||
return genericAppendBridges(devices, q.Bridges, q.qemuMachine.Type)
|
||||
}
|
||||
|
@ -22,26 +22,36 @@ func qemuConfig(machineType string) HypervisorConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func newTestQemu(machineType string) qemuArch {
|
||||
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
|
||||
config := qemuConfig(machineType)
|
||||
return newQemuArch(config)
|
||||
arch, err := newQemuArch(config)
|
||||
assert.NoError(err)
|
||||
return arch
|
||||
}
|
||||
|
||||
func TestQemuAmd64BadMachineType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
config := qemuConfig("no-such-machine-type")
|
||||
_, err := newQemuArch(config)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestQemuAmd64Capabilities(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
amd64 := newTestQemu(QemuPC)
|
||||
amd64 := newTestQemu(assert, QemuPC)
|
||||
caps := amd64.capabilities()
|
||||
assert.True(caps.IsBlockDeviceHotplugSupported())
|
||||
|
||||
amd64 = newTestQemu(QemuQ35)
|
||||
amd64 = newTestQemu(assert, QemuQ35)
|
||||
caps = amd64.capabilities()
|
||||
assert.True(caps.IsBlockDeviceHotplugSupported())
|
||||
}
|
||||
|
||||
func TestQemuAmd64Bridges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
amd64 := newTestQemu(QemuPC)
|
||||
amd64 := newTestQemu(assert, QemuPC)
|
||||
len := 5
|
||||
|
||||
amd64.bridges(uint32(len))
|
||||
@ -55,7 +65,7 @@ func TestQemuAmd64Bridges(t *testing.T) {
|
||||
assert.NotNil(b.Devices)
|
||||
}
|
||||
|
||||
amd64 = newTestQemu(QemuQ35)
|
||||
amd64 = newTestQemu(assert, QemuQ35)
|
||||
amd64.bridges(uint32(len))
|
||||
bridges = amd64.getBridges()
|
||||
assert.Len(bridges, len)
|
||||
@ -66,16 +76,11 @@ func TestQemuAmd64Bridges(t *testing.T) {
|
||||
assert.Equal(id, b.ID)
|
||||
assert.NotNil(b.Devices)
|
||||
}
|
||||
|
||||
amd64 = newTestQemu(QemuQ35 + QemuPC)
|
||||
amd64.bridges(uint32(len))
|
||||
bridges = amd64.getBridges()
|
||||
assert.Nil(bridges)
|
||||
}
|
||||
|
||||
func TestQemuAmd64CPUModel(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
amd64 := newTestQemu(QemuPC)
|
||||
amd64 := newTestQemu(assert, QemuPC)
|
||||
|
||||
expectedOut := defaultCPUModel
|
||||
model := amd64.cpuModel()
|
||||
@ -97,7 +102,7 @@ func TestQemuAmd64CPUModel(t *testing.T) {
|
||||
|
||||
func TestQemuAmd64MemoryTopology(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
amd64 := newTestQemu(QemuPC)
|
||||
amd64 := newTestQemu(assert, QemuPC)
|
||||
memoryOffset := 1024
|
||||
|
||||
hostMem := uint64(100)
|
||||
@ -131,10 +136,9 @@ func TestQemuAmd64AppendImage(t *testing.T) {
|
||||
cfg := qemuConfig(QemuPC)
|
||||
cfg.ImagePath = f.Name()
|
||||
cfg.DisableImageNvdimm = false
|
||||
amd64 := newQemuArch(cfg)
|
||||
for _, m := range amd64.(*qemuAmd64).supportedQemuMachines {
|
||||
assert.Contains(m.Options, qemuNvdimmOption)
|
||||
}
|
||||
amd64, err := newQemuArch(cfg)
|
||||
assert.NoError(err)
|
||||
assert.Contains(amd64.machine().Options, qemuNvdimmOption)
|
||||
|
||||
expectedOut := []govmmQemu.Device{
|
||||
govmmQemu.Object{
|
||||
@ -155,10 +159,9 @@ func TestQemuAmd64AppendImage(t *testing.T) {
|
||||
assert.Equal(len(supportedQemuMachines), copy(supportedQemuMachines, machinesCopy))
|
||||
|
||||
cfg.DisableImageNvdimm = true
|
||||
amd64 = newQemuArch(cfg)
|
||||
for _, m := range amd64.(*qemuAmd64).supportedQemuMachines {
|
||||
assert.NotContains(m.Options, qemuNvdimmOption)
|
||||
}
|
||||
amd64, err = newQemuArch(cfg)
|
||||
assert.NoError(err)
|
||||
assert.NotContains(amd64.machine().Options, qemuNvdimmOption)
|
||||
|
||||
found := false
|
||||
devices, err = amd64.appendImage(nil, f.Name())
|
||||
@ -181,7 +184,7 @@ func TestQemuAmd64AppendBridges(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
// check PC
|
||||
amd64 := newTestQemu(QemuPC)
|
||||
amd64 := newTestQemu(assert, QemuPC)
|
||||
|
||||
amd64.bridges(1)
|
||||
bridges := amd64.getBridges()
|
||||
@ -204,7 +207,7 @@ func TestQemuAmd64AppendBridges(t *testing.T) {
|
||||
assert.Equal(expectedOut, devices)
|
||||
|
||||
// Check Q35
|
||||
amd64 = newTestQemu(QemuQ35)
|
||||
amd64 = newTestQemu(assert, QemuQ35)
|
||||
|
||||
amd64.bridges(1)
|
||||
bridges = amd64.getBridges()
|
||||
@ -233,11 +236,10 @@ func TestQemuAmd64WithInitrd(t *testing.T) {
|
||||
|
||||
cfg := qemuConfig(QemuPC)
|
||||
cfg.InitrdPath = "dummy-initrd"
|
||||
amd64 := newQemuArch(cfg)
|
||||
amd64, err := newQemuArch(cfg)
|
||||
assert.NoError(err)
|
||||
|
||||
for _, m := range amd64.(*qemuAmd64).supportedQemuMachines {
|
||||
assert.NotContains(m.Options, qemuNvdimmOption)
|
||||
}
|
||||
assert.NotContains(amd64.machine().Options, qemuNvdimmOption)
|
||||
}
|
||||
|
||||
func TestQemuAmd64Iommu(t *testing.T) {
|
||||
@ -245,13 +247,12 @@ func TestQemuAmd64Iommu(t *testing.T) {
|
||||
|
||||
config := qemuConfig(QemuQ35)
|
||||
config.IOMMU = true
|
||||
qemu := newQemuArch(config)
|
||||
qemu, err := newQemuArch(config)
|
||||
assert.NoError(err)
|
||||
|
||||
p := qemu.kernelParameters(false)
|
||||
assert.Contains(p, Param{"intel_iommu", "on"})
|
||||
|
||||
m, err := qemu.machine()
|
||||
|
||||
assert.NoError(err)
|
||||
m := qemu.machine()
|
||||
assert.Contains(m.Options, "kernel_irqchip=split")
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ type qemuArch interface {
|
||||
disableVhostNet()
|
||||
|
||||
// machine returns the machine type
|
||||
machine() (govmmQemu.Machine, error)
|
||||
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
|
||||
@ -136,15 +136,14 @@ type qemuArch interface {
|
||||
}
|
||||
|
||||
type qemuArchBase struct {
|
||||
machineType string
|
||||
qemuMachine govmmQemu.Machine
|
||||
qemuExePath string
|
||||
memoryOffset uint32
|
||||
nestedRun bool
|
||||
vhost bool
|
||||
disableNvdimm bool
|
||||
dax bool
|
||||
networkIndex int
|
||||
qemuPaths map[string]string
|
||||
supportedQemuMachines []govmmQemu.Machine
|
||||
kernelParamsNonDebug []Param
|
||||
kernelParamsDebug []Param
|
||||
kernelParams []Param
|
||||
@ -239,23 +238,12 @@ func (q *qemuArchBase) disableVhostNet() {
|
||||
q.vhost = false
|
||||
}
|
||||
|
||||
func (q *qemuArchBase) machine() (govmmQemu.Machine, error) {
|
||||
for _, m := range q.supportedQemuMachines {
|
||||
if m.Type == q.machineType {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
return govmmQemu.Machine{}, fmt.Errorf("unrecognised machine type: %v", q.machineType)
|
||||
func (q *qemuArchBase) machine() govmmQemu.Machine {
|
||||
return q.qemuMachine
|
||||
}
|
||||
|
||||
func (q *qemuArchBase) qemuPath() (string, error) {
|
||||
p, ok := q.qemuPaths[q.machineType]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Unknown machine type: %s", q.machineType)
|
||||
}
|
||||
|
||||
return p, nil
|
||||
func (q *qemuArchBase) qemuPath() string {
|
||||
return q.qemuExePath
|
||||
}
|
||||
|
||||
func (q *qemuArchBase) kernelParameters(debug bool) []Param {
|
||||
@ -681,12 +669,9 @@ func (q *qemuArchBase) handleImagePath(config HypervisorConfig) {
|
||||
if config.ImagePath != "" {
|
||||
kernelRootParams := commonVirtioblkKernelRootParams
|
||||
if !q.disableNvdimm {
|
||||
for i := range q.supportedQemuMachines {
|
||||
q.supportedQemuMachines[i].Options = strings.Join([]string{
|
||||
q.supportedQemuMachines[i].Options,
|
||||
qemuNvdimmOption,
|
||||
}, ",")
|
||||
}
|
||||
q.qemuMachine.Options = strings.Join([]string{
|
||||
q.qemuMachine.Options, qemuNvdimmOption,
|
||||
}, ",")
|
||||
if q.dax {
|
||||
kernelRootParams = commonNvdimmKernelRootParams
|
||||
} else {
|
||||
@ -767,13 +752,12 @@ func (q *qemuArchBase) addBridge(b types.Bridge) {
|
||||
|
||||
// appendPCIeRootPortDevice appends to devices the given pcie-root-port
|
||||
func (q *qemuArchBase) appendPCIeRootPortDevice(devices []govmmQemu.Device, number uint32) []govmmQemu.Device {
|
||||
return genericAppendPCIeRootPort(devices, number, q.machineType)
|
||||
|
||||
return genericAppendPCIeRootPort(devices, number, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
// appendIOMMU appends a virtual IOMMU device
|
||||
func (q *qemuArchBase) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
|
||||
switch q.machineType {
|
||||
switch q.qemuMachine.Type {
|
||||
case QemuQ35:
|
||||
iommu := govmmQemu.IommuDev{
|
||||
Intremap: true,
|
||||
@ -784,6 +768,6 @@ func (q *qemuArchBase) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Devi
|
||||
devices = append(devices, iommu)
|
||||
return devices, nil
|
||||
default:
|
||||
return devices, fmt.Errorf("Machine Type %s does not support vIOMMU", q.machineType)
|
||||
return devices, fmt.Errorf("Machine Type %s does not support vIOMMU", q.qemuMachine.Type)
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
qemuArchBaseMachineType = "pc"
|
||||
qemuArchBaseQemuPath = "/usr/bin/qemu-system-x86_64"
|
||||
)
|
||||
|
||||
var qemuArchBaseMachine = govmmQemu.Machine{
|
||||
Type: "pc",
|
||||
}
|
||||
|
||||
var qemuArchBaseQemuPaths = map[string]string{
|
||||
qemuArchBaseMachineType: qemuArchBaseQemuPath,
|
||||
qemuArchBaseMachine.Type: qemuArchBaseQemuPath,
|
||||
}
|
||||
|
||||
var qemuArchBaseKernelParamsNonDebug = []Param{
|
||||
@ -47,18 +50,11 @@ var qemuArchBaseKernelParams = []Param{
|
||||
{"rootfstype", "ext4"},
|
||||
}
|
||||
|
||||
var qemuArchBaseSupportedQemuMachines = []govmmQemu.Machine{
|
||||
{
|
||||
Type: qemuArchBaseMachineType,
|
||||
},
|
||||
}
|
||||
|
||||
func newQemuArchBase() *qemuArchBase {
|
||||
return &qemuArchBase{
|
||||
machineType: qemuArchBaseMachineType,
|
||||
qemuMachine: qemuArchBaseMachine,
|
||||
qemuExePath: qemuArchBaseQemuPaths[qemuArchBaseMachine.Type],
|
||||
nestedRun: false,
|
||||
qemuPaths: qemuArchBaseQemuPaths,
|
||||
supportedQemuMachines: qemuArchBaseSupportedQemuMachines,
|
||||
kernelParamsNonDebug: qemuArchBaseKernelParamsNonDebug,
|
||||
kernelParamsDebug: qemuArchBaseKernelParamsDebug,
|
||||
kernelParams: qemuArchBaseKernelParams,
|
||||
@ -85,36 +81,16 @@ func TestQemuArchBaseMachine(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
qemuArchBase := newQemuArchBase()
|
||||
|
||||
m, err := qemuArchBase.machine()
|
||||
assert.NoError(err)
|
||||
assert.Equal(m.Type, qemuArchBaseMachineType)
|
||||
|
||||
machines := []govmmQemu.Machine{
|
||||
{
|
||||
Type: "bad",
|
||||
},
|
||||
}
|
||||
qemuArchBase.supportedQemuMachines = machines
|
||||
m, err = qemuArchBase.machine()
|
||||
assert.Error(err)
|
||||
assert.Equal("", m.Type)
|
||||
m := qemuArchBase.machine()
|
||||
assert.Equal(m.Type, qemuArchBaseMachine.Type)
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -166,7 +142,7 @@ func TestQemuAddDeviceToBridge(t *testing.T) {
|
||||
|
||||
// addDeviceToBridge successfully
|
||||
q := newQemuArchBase()
|
||||
q.machineType = QemuPC
|
||||
q.qemuMachine.Type = QemuPC
|
||||
|
||||
q.bridges(1)
|
||||
for i := uint32(1); i <= types.PCIBridgeMaxCapacity; i++ {
|
||||
@ -181,7 +157,7 @@ func TestQemuAddDeviceToBridge(t *testing.T) {
|
||||
|
||||
// addDeviceToBridge fails cause q.Bridges == 0
|
||||
q = newQemuArchBase()
|
||||
q.machineType = QemuPCLite
|
||||
q.qemuMachine.Type = QemuPCLite
|
||||
q.bridges(0)
|
||||
_, _, err = q.addDeviceToBridge("qemu-bridge", types.PCI)
|
||||
if assert.Error(err) {
|
||||
@ -581,11 +557,11 @@ func TestQemuArchBaseAppendIOMMU(t *testing.T) {
|
||||
},
|
||||
}
|
||||
// Test IOMMU is not appended to PC machine type
|
||||
qemuArchBase.machineType = QemuPC
|
||||
qemuArchBase.qemuMachine.Type = QemuPC
|
||||
devices, err = qemuArchBase.appendIOMMU(devices)
|
||||
assert.Error(err)
|
||||
|
||||
qemuArchBase.machineType = QemuQ35
|
||||
qemuArchBase.qemuMachine.Type = QemuQ35
|
||||
devices, err = qemuArchBase.appendIOMMU(devices)
|
||||
assert.NoError(err)
|
||||
assert.Equal(expectedOut, devices)
|
||||
|
@ -30,21 +30,15 @@ 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"},
|
||||
{"iommu.passthrough", "0"},
|
||||
}
|
||||
|
||||
var supportedQemuMachines = []govmmQemu.Machine{
|
||||
{
|
||||
Type: QemuVirt,
|
||||
Options: defaultQemuMachineOptions,
|
||||
},
|
||||
var supportedQemuMachine = govmmQemu.Machine {
|
||||
Type: QemuVirt,
|
||||
Options: defaultQemuMachineOptions,
|
||||
}
|
||||
|
||||
// Logger returns a logrus logger appropriate for logging qemu-aarch64 messages
|
||||
@ -125,18 +119,21 @@ func MaxQemuVCPUs() uint32 {
|
||||
return uint32(runtime.NumCPU())
|
||||
}
|
||||
|
||||
func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
||||
machineType := config.HypervisorMachineType
|
||||
if machineType == "" {
|
||||
machineType = defaultQemuMachineType
|
||||
}
|
||||
|
||||
if machineType != defaultQemuMachineType {
|
||||
return nil, fmt.Errorf("unrecognised machinetype: %v", machineType)
|
||||
}
|
||||
|
||||
q := &qemuArm64{
|
||||
qemuArchBase{
|
||||
machineType: machineType,
|
||||
qemuMachine: supportedQemuMachine,
|
||||
qemuExePath: defaultQemuPath,
|
||||
memoryOffset: config.MemOffset,
|
||||
qemuPaths: qemuPaths,
|
||||
supportedQemuMachines: supportedQemuMachines,
|
||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||
kernelParamsDebug: kernelParamsDebug,
|
||||
kernelParams: kernelParams,
|
||||
@ -146,16 +143,16 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
|
||||
q.handleImagePath(config)
|
||||
|
||||
return q
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (q *qemuArm64) bridges(number uint32) {
|
||||
q.Bridges = genericBridges(number, q.machineType)
|
||||
q.Bridges = genericBridges(number, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
// appendBridges appends to devices the given bridges
|
||||
func (q *qemuArm64) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
|
||||
return genericAppendBridges(devices, q.Bridges, q.machineType)
|
||||
return genericAppendBridges(devices, q.Bridges, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
func (q *qemuArm64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
|
||||
|
@ -23,14 +23,16 @@ func qemuConfig(machineType string) HypervisorConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func newTestQemu(machineType string) qemuArch {
|
||||
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
|
||||
config := qemuConfig(machineType)
|
||||
return newQemuArch(config)
|
||||
arch, err := newQemuArch(config)
|
||||
assert.NoError(err)
|
||||
return arch
|
||||
}
|
||||
|
||||
func TestQemuArm64CPUModel(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
arm64 := newTestQemu(QemuVirt)
|
||||
arm64 := newTestQemu(assert, QemuVirt)
|
||||
|
||||
expectedOut := defaultCPUModel
|
||||
model := arm64.cpuModel()
|
||||
@ -39,7 +41,7 @@ func TestQemuArm64CPUModel(t *testing.T) {
|
||||
|
||||
func TestQemuArm64MemoryTopology(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
arm64 := newTestQemu(QemuVirt)
|
||||
arm64 := newTestQemu(assert, QemuVirt)
|
||||
|
||||
hostMem := uint64(4096)
|
||||
mem := uint64(1024)
|
||||
@ -107,7 +109,7 @@ func TestQemuArm64AppendBridges(t *testing.T) {
|
||||
var devices []govmmQemu.Device
|
||||
assert := assert.New(t)
|
||||
|
||||
arm64 := newTestQemu(QemuVirt)
|
||||
arm64 := newTestQemu(assert, QemuVirt)
|
||||
|
||||
arm64.bridges(1)
|
||||
bridges := arm64.getBridges()
|
||||
@ -150,9 +152,7 @@ func TestQemuArm64AppendImage(t *testing.T) {
|
||||
cfg := qemuConfig(QemuVirt)
|
||||
cfg.ImagePath = f.Name()
|
||||
arm64 := newQemuArch(cfg)
|
||||
for _, m := range arm64.(*qemuArm64).supportedQemuMachines {
|
||||
assert.Contains(m.Options, qemuNvdimmOption)
|
||||
}
|
||||
assert.Contains(m.machine().Options, qemuNvdimmOption)
|
||||
|
||||
expectedOut := []govmmQemu.Device{
|
||||
govmmQemu.Object{
|
||||
@ -180,7 +180,5 @@ func TestQemuArm64WithInitrd(t *testing.T) {
|
||||
cfg.InitrdPath = "dummy-initrd"
|
||||
arm64 := newQemuArch(cfg)
|
||||
|
||||
for _, m := range arm64.(*qemuArm64).supportedQemuMachines {
|
||||
assert.NotContains(m.Options, qemuNvdimmOption)
|
||||
}
|
||||
assert.NotContains(m.machine().Options, qemuNvdimmOption)
|
||||
}
|
||||
|
@ -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"},
|
||||
@ -40,11 +36,9 @@ var kernelParams = []Param{
|
||||
{"net.ifnames", "0"},
|
||||
}
|
||||
|
||||
var supportedQemuMachines = []govmmQemu.Machine{
|
||||
{
|
||||
Type: QemuPseries,
|
||||
Options: defaultQemuMachineOptions,
|
||||
},
|
||||
var supportedQemuMachine = govmmQemu.Machine {
|
||||
Type: QemuPseries,
|
||||
Options: defaultQemuMachineOptions,
|
||||
}
|
||||
|
||||
// Logger returns a logrus logger appropriate for logging qemu messages
|
||||
@ -57,18 +51,21 @@ func MaxQemuVCPUs() uint32 {
|
||||
return uint32(128)
|
||||
}
|
||||
|
||||
func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
||||
machineType := config.HypervisorMachineType
|
||||
if machineType == "" {
|
||||
machineType = defaultQemuMachineType
|
||||
}
|
||||
|
||||
if machineType != defaultQemuMachineType {
|
||||
return nil, fmt.Errorf("unrecognised machinetype: %v", machineType)
|
||||
}
|
||||
|
||||
q := &qemuPPC64le{
|
||||
qemuArchBase{
|
||||
machineType: machineType,
|
||||
qemuMachine: supportedQemuMachine,
|
||||
qemuExePath: defaultQemuPath,
|
||||
memoryOffset: config.MemOffset,
|
||||
qemuPaths: qemuPaths,
|
||||
supportedQemuMachines: supportedQemuMachines,
|
||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||
kernelParamsDebug: kernelParamsDebug,
|
||||
kernelParams: kernelParams,
|
||||
@ -79,14 +76,14 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
|
||||
q.memoryOffset = config.MemOffset
|
||||
|
||||
return q
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (q *qemuPPC64le) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
|
||||
// pseries machine type supports hotplugging drives
|
||||
if q.machineType == QemuPseries {
|
||||
if q.qemuMachine.Type == QemuPseries {
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
}
|
||||
|
||||
@ -97,7 +94,7 @@ func (q *qemuPPC64le) capabilities() types.Capabilities {
|
||||
}
|
||||
|
||||
func (q *qemuPPC64le) bridges(number uint32) {
|
||||
q.Bridges = genericBridges(number, q.machineType)
|
||||
q.Bridges = genericBridges(number, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
func (q *qemuPPC64le) cpuModel() string {
|
||||
@ -113,7 +110,7 @@ func (q *qemuPPC64le) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8)
|
||||
|
||||
// appendBridges appends to devices the given bridges
|
||||
func (q *qemuPPC64le) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
|
||||
return genericAppendBridges(devices, q.Bridges, q.machineType)
|
||||
return genericAppendBridges(devices, q.Bridges, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
func (q *qemuPPC64le) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
|
||||
|
@ -13,16 +13,18 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func newTestQemu(machineType string) qemuArch {
|
||||
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
|
||||
config := HypervisorConfig{
|
||||
HypervisorMachineType: machineType,
|
||||
}
|
||||
return newQemuArch(config)
|
||||
arch, err := newQemuArch(config)
|
||||
assert.NoError(err)
|
||||
return arch
|
||||
}
|
||||
|
||||
func TestQemuPPC64leCPUModel(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
ppc64le := newTestQemu(QemuPseries)
|
||||
ppc64le := newTestQemu(assert, QemuPseries)
|
||||
|
||||
expectedOut := defaultCPUModel
|
||||
model := ppc64le.cpuModel()
|
||||
@ -31,7 +33,7 @@ func TestQemuPPC64leCPUModel(t *testing.T) {
|
||||
|
||||
func TestQemuPPC64leMemoryTopology(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
ppc64le := newTestQemu(QemuPseries)
|
||||
ppc64le := newTestQemu(assert, QemuPseries)
|
||||
memoryOffset := 1024
|
||||
|
||||
hostMem := uint64(1024)
|
||||
|
@ -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"},
|
||||
@ -40,11 +36,9 @@ var kernelParams = []Param{
|
||||
|
||||
var ccwbridge = types.NewBridge(types.CCW, "", make(map[uint32]string, types.CCWBridgeMaxCapacity), 0)
|
||||
|
||||
var supportedQemuMachines = []govmmQemu.Machine{
|
||||
{
|
||||
Type: QemuCCWVirtio,
|
||||
Options: defaultQemuMachineOptions,
|
||||
},
|
||||
var supportedQemuMachine = govmmQemu.Machine {
|
||||
Type: QemuCCWVirtio,
|
||||
Options: defaultQemuMachineOptions,
|
||||
}
|
||||
|
||||
// MaxQemuVCPUs returns the maximum number of vCPUs supported
|
||||
@ -55,18 +49,21 @@ func MaxQemuVCPUs() uint32 {
|
||||
return uint32(248)
|
||||
}
|
||||
|
||||
func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
func newQemuArch(config HypervisorConfig) (qemuArch, error) {
|
||||
machineType := config.HypervisorMachineType
|
||||
if machineType == "" {
|
||||
machineType = defaultQemuMachineType
|
||||
}
|
||||
|
||||
if machineType != defaultQemuMachineType {
|
||||
return nil, fmt.Errorf("unrecognised machinetype: %v", machineType)
|
||||
}
|
||||
|
||||
q := &qemuS390x{
|
||||
qemuArchBase{
|
||||
machineType: machineType,
|
||||
qemuMachine: supportedQemuMachine,
|
||||
qemuExePath: defaultQemuPath,
|
||||
memoryOffset: config.MemOffset,
|
||||
qemuPaths: qemuPaths,
|
||||
supportedQemuMachines: supportedQemuMachines,
|
||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||
kernelParamsDebug: kernelParamsDebug,
|
||||
kernelParams: kernelParams,
|
||||
@ -81,11 +78,11 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
q.kernelParamsDebug = append(q.kernelParamsDebug, kernelParamsSystemdDebug...)
|
||||
}
|
||||
|
||||
return q
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (q *qemuS390x) bridges(number uint32) {
|
||||
q.Bridges = genericBridges(number, q.machineType)
|
||||
q.Bridges = genericBridges(number, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
// appendConsole appends a console to devices.
|
||||
@ -226,7 +223,7 @@ func (q *qemuS390x) append9PVolume(devices []govmmQemu.Device, volume types.Volu
|
||||
|
||||
// appendBridges appends to devices the given bridges
|
||||
func (q *qemuS390x) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
|
||||
return genericAppendBridges(devices, q.Bridges, q.machineType)
|
||||
return genericAppendBridges(devices, q.Bridges, q.qemuMachine.Type)
|
||||
}
|
||||
|
||||
func (q *qemuS390x) appendSCSIController(devices []govmmQemu.Device, enableIOThreads bool) ([]govmmQemu.Device, *govmmQemu.IOThread, error) {
|
||||
|
@ -14,16 +14,18 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func newTestQemu(machineType string) qemuArch {
|
||||
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
|
||||
config := HypervisorConfig{
|
||||
HypervisorMachineType: machineType,
|
||||
}
|
||||
return newQemuArch(config)
|
||||
arch, err := newQemuArch(config)
|
||||
assert.NoError(err)
|
||||
return arch
|
||||
}
|
||||
|
||||
func TestQemuS390xCPUModel(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s390x := newTestQemu(QemuCCWVirtio)
|
||||
s390x := newTestQemu(assert, QemuCCWVirtio)
|
||||
|
||||
expectedOut := defaultCPUModel
|
||||
model := s390x.cpuModel()
|
||||
@ -37,7 +39,7 @@ func TestQemuS390xCPUModel(t *testing.T) {
|
||||
|
||||
func TestQemuS390xMemoryTopology(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s390x := newTestQemu(QemuCCWVirtio)
|
||||
s390x := newTestQemu(assert, QemuCCWVirtio)
|
||||
|
||||
hostMem := uint64(1024)
|
||||
mem := uint64(120)
|
||||
|
@ -342,10 +342,11 @@ func TestQemuQemuPath(t *testing.T) {
|
||||
qemuConfig := newQemuConfig()
|
||||
qemuConfig.HypervisorPath = expectedPath
|
||||
qkvm := &qemuArchBase{
|
||||
machineType: "pc",
|
||||
qemuPaths: map[string]string{
|
||||
"pc": expectedPath,
|
||||
qemuMachine: govmmQemu.Machine{
|
||||
Type: "pc",
|
||||
Options: "",
|
||||
},
|
||||
qemuExePath: expectedPath,
|
||||
}
|
||||
|
||||
q := &qemu{
|
||||
@ -369,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.machineType = "rgb"
|
||||
q.arch = qkvm
|
||||
path, err = q.qemuPath()
|
||||
assert.Error(err)
|
||||
assert.Equal(path, "")
|
||||
}
|
||||
|
||||
func TestHotplugUnsupportedDeviceType(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user