mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
QEMU: do not require nvdimm machine option with initrd
Do not add the "nvdimm" machine option to QEMU when the config specifies a initrd file. For arm64, this allows using a vanilla QEMU, where "virt" machine does not support the "nvdimm" option. Fixes: #2088 Signed-off-by: Marco Vedovati <mvedovati@suse.com>
This commit is contained in:
parent
d3f480dc4c
commit
8b843c5229
@ -7,6 +7,7 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
@ -25,7 +26,9 @@ const defaultQemuPath = "/usr/bin/qemu-system-x86_64"
|
|||||||
|
|
||||||
const defaultQemuMachineType = QemuPC
|
const defaultQemuMachineType = QemuPC
|
||||||
|
|
||||||
const defaultQemuMachineOptions = "accel=kvm,kernel_irqchip,nvdimm"
|
const qemuNvdimmOption = "nvdimm"
|
||||||
|
|
||||||
|
const defaultQemuMachineOptions = "accel=kvm,kernel_irqchip"
|
||||||
|
|
||||||
const qmpMigrationWaitTimeout = 5 * time.Second
|
const qmpMigrationWaitTimeout = 5 * time.Second
|
||||||
|
|
||||||
@ -103,6 +106,15 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
vmFactory: factory,
|
vmFactory: factory,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.ImagePath != "" {
|
||||||
|
for i := range q.supportedQemuMachines {
|
||||||
|
q.supportedQemuMachines[i].Options = strings.Join([]string{
|
||||||
|
q.supportedQemuMachines[i].Options,
|
||||||
|
qemuNvdimmOption,
|
||||||
|
}, ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
q.handleImagePath(config)
|
q.handleImagePath(config)
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
@ -16,10 +16,14 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestQemu(machineType string) qemuArch {
|
func qemuConfig(machineType string) HypervisorConfig {
|
||||||
config := HypervisorConfig{
|
return HypervisorConfig{
|
||||||
HypervisorMachineType: machineType,
|
HypervisorMachineType: machineType,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestQemu(machineType string) qemuArch {
|
||||||
|
config := qemuConfig(machineType)
|
||||||
return newQemuArch(config)
|
return newQemuArch(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +116,6 @@ func TestQemuAmd64MemoryTopology(t *testing.T) {
|
|||||||
func TestQemuAmd64AppendImage(t *testing.T) {
|
func TestQemuAmd64AppendImage(t *testing.T) {
|
||||||
var devices []govmmQemu.Device
|
var devices []govmmQemu.Device
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
amd64 := newTestQemu(QemuPC)
|
|
||||||
|
|
||||||
f, err := ioutil.TempFile("", "img")
|
f, err := ioutil.TempFile("", "img")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@ -122,6 +125,17 @@ func TestQemuAmd64AppendImage(t *testing.T) {
|
|||||||
imageStat, err := f.Stat()
|
imageStat, err := f.Stat()
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// save default supportedQemuMachines options
|
||||||
|
machinesCopy := make([]govmmQemu.Machine, len(supportedQemuMachines))
|
||||||
|
assert.Equal(len(supportedQemuMachines), copy(machinesCopy, supportedQemuMachines))
|
||||||
|
|
||||||
|
cfg := qemuConfig(QemuPC)
|
||||||
|
cfg.ImagePath = f.Name()
|
||||||
|
amd64 := newQemuArch(cfg)
|
||||||
|
for _, m := range amd64.(*qemuAmd64).supportedQemuMachines {
|
||||||
|
assert.Contains(m.Options, qemuNvdimmOption)
|
||||||
|
}
|
||||||
|
|
||||||
expectedOut := []govmmQemu.Device{
|
expectedOut := []govmmQemu.Device{
|
||||||
govmmQemu.Object{
|
govmmQemu.Object{
|
||||||
Driver: govmmQemu.NVDIMM,
|
Driver: govmmQemu.NVDIMM,
|
||||||
@ -135,8 +149,10 @@ func TestQemuAmd64AppendImage(t *testing.T) {
|
|||||||
|
|
||||||
devices, err = amd64.appendImage(devices, f.Name())
|
devices, err = amd64.appendImage(devices, f.Name())
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
assert.Equal(expectedOut, devices)
|
assert.Equal(expectedOut, devices)
|
||||||
|
|
||||||
|
// restore default supportedQemuMachines options
|
||||||
|
assert.Equal(len(supportedQemuMachines), copy(supportedQemuMachines, machinesCopy))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQemuAmd64AppendBridges(t *testing.T) {
|
func TestQemuAmd64AppendBridges(t *testing.T) {
|
||||||
@ -190,3 +206,15 @@ func TestQemuAmd64AppendBridges(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(expectedOut, devices)
|
assert.Equal(expectedOut, devices)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQemuAmd64WithInitrd(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
cfg := qemuConfig(QemuPC)
|
||||||
|
cfg.InitrdPath = "dummy-initrd"
|
||||||
|
amd64 := newQemuArch(cfg)
|
||||||
|
|
||||||
|
for _, m := range amd64.(*qemuAmd64).supportedQemuMachines {
|
||||||
|
assert.NotContains(m.Options, qemuNvdimmOption)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,9 +26,11 @@ const defaultQemuPath = "/usr/bin/qemu-system-aarch64"
|
|||||||
|
|
||||||
const defaultQemuMachineType = QemuVirt
|
const defaultQemuMachineType = QemuVirt
|
||||||
|
|
||||||
|
const qemuNvdimmOption = "nvdimm"
|
||||||
|
|
||||||
const qmpMigrationWaitTimeout = 10 * time.Second
|
const qmpMigrationWaitTimeout = 10 * time.Second
|
||||||
|
|
||||||
var defaultQemuMachineOptions = "usb=off,accel=kvm,nvdimm,gic-version=" + getGuestGICVersion()
|
var defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=" + getGuestGICVersion()
|
||||||
|
|
||||||
var qemuPaths = map[string]string{
|
var qemuPaths = map[string]string{
|
||||||
QemuVirt: defaultQemuPath,
|
QemuVirt: defaultQemuPath,
|
||||||
@ -153,6 +155,12 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.ImagePath != "" {
|
if config.ImagePath != "" {
|
||||||
|
for i := range q.supportedQemuMachines {
|
||||||
|
q.supportedQemuMachines[i].Options = strings.Join([]string{
|
||||||
|
q.supportedQemuMachines[i].Options,
|
||||||
|
qemuNvdimmOption,
|
||||||
|
}, ",")
|
||||||
|
}
|
||||||
q.kernelParams = append(q.kernelParams, kernelRootParams...)
|
q.kernelParams = append(q.kernelParams, kernelRootParams...)
|
||||||
q.kernelParamsNonDebug = append(q.kernelParamsNonDebug, kernelParamsSystemdNonDebug...)
|
q.kernelParamsNonDebug = append(q.kernelParamsNonDebug, kernelParamsSystemdNonDebug...)
|
||||||
q.kernelParamsDebug = append(q.kernelParamsDebug, kernelParamsSystemdDebug...)
|
q.kernelParamsDebug = append(q.kernelParamsDebug, kernelParamsSystemdDebug...)
|
||||||
|
@ -17,10 +17,14 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestQemu(machineType string) qemuArch {
|
func qemuConfig(machineType string) HypervisorConfig {
|
||||||
config := HypervisorConfig{
|
return HypervisorConfig{
|
||||||
HypervisorMachineType: machineType,
|
HypervisorMachineType: machineType,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestQemu(machineType string) qemuArch {
|
||||||
|
config := qemuConfig(machineType)
|
||||||
return newQemuArch(config)
|
return newQemuArch(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +134,6 @@ func TestQemuArm64AppendBridges(t *testing.T) {
|
|||||||
func TestQemuArm64AppendImage(t *testing.T) {
|
func TestQemuArm64AppendImage(t *testing.T) {
|
||||||
var devices []govmmQemu.Device
|
var devices []govmmQemu.Device
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
arm64 := newTestQemu(QemuVirt)
|
|
||||||
|
|
||||||
f, err := ioutil.TempFile("", "img")
|
f, err := ioutil.TempFile("", "img")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@ -140,6 +143,17 @@ func TestQemuArm64AppendImage(t *testing.T) {
|
|||||||
imageStat, err := f.Stat()
|
imageStat, err := f.Stat()
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// save default supportedQemuMachines options
|
||||||
|
machinesCopy := make([]govmmQemu.Machine, len(supportedQemuMachines))
|
||||||
|
assert.Equal(len(supportedQemuMachines), copy(machinesCopy, supportedQemuMachines))
|
||||||
|
|
||||||
|
cfg := qemuConfig(QemuVirt)
|
||||||
|
cfg.ImagePath = f.Name()
|
||||||
|
arm64 := newQemuArch(cfg)
|
||||||
|
for _, m := range arm64.(*qemuArm64).supportedQemuMachines {
|
||||||
|
assert.Contains(m.Options, qemuNvdimmOption)
|
||||||
|
}
|
||||||
|
|
||||||
expectedOut := []govmmQemu.Device{
|
expectedOut := []govmmQemu.Device{
|
||||||
govmmQemu.Object{
|
govmmQemu.Object{
|
||||||
Driver: govmmQemu.NVDIMM,
|
Driver: govmmQemu.NVDIMM,
|
||||||
@ -153,6 +167,20 @@ func TestQemuArm64AppendImage(t *testing.T) {
|
|||||||
|
|
||||||
devices, err = arm64.appendImage(devices, f.Name())
|
devices, err = arm64.appendImage(devices, f.Name())
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
assert.Equal(expectedOut, devices)
|
assert.Equal(expectedOut, devices)
|
||||||
|
|
||||||
|
// restore default supportedQemuMachines options
|
||||||
|
assert.Equal(len(supportedQemuMachines), copy(supportedQemuMachines, machinesCopy))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQemuArm64WithInitrd(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
cfg := qemuConfig(QemuVirt)
|
||||||
|
cfg.InitrdPath = "dummy-initrd"
|
||||||
|
arm64 := newQemuArch(cfg)
|
||||||
|
|
||||||
|
for _, m := range arm64.(*qemuArm64).supportedQemuMachines {
|
||||||
|
assert.NotContains(m.Options, qemuNvdimmOption)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user