Skip to content

Commit

Permalink
qemu/arm: remove nvdimm/"ReadOnly" option on arm64
Browse files Browse the repository at this point in the history
There is a new "ReadOnly" option added to nvdimm device in qemu
and now added to kata. However, qemu used for arm64 is a little
old and has no this feature. Here we remove this feature for arm.

Fixes: #2320
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
  • Loading branch information
jongwu committed Jul 27, 2021
1 parent 1fbfd99 commit 77604de
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/runtime/virtcontainers/qemu_arm64.go
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"time"
"os"

govmmQemu "github.com/kata-containers/govmm/qemu"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
Expand Down Expand Up @@ -100,6 +101,35 @@ func (q *qemuArm64) appendImage(ctx context.Context, devices []govmmQemu.Device,
return q.appendBlockImage(ctx, devices, path)
}

// There is no nvdimm/readonly feature in qemu 5.1 which is used by arm64 for now,
// so we temporarily add this specific implementation for arm64 here until
// the qemu used by arm64 is capable for that feature
func (q *qemuArm64) appendNvdimmImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
imageFile, err := os.Open(path)
if err != nil {
return nil, err
}
defer imageFile.Close()

imageStat, err := imageFile.Stat()
if err != nil {
return nil, err
}

object := govmmQemu.Object{
Driver: govmmQemu.NVDIMM,
Type: govmmQemu.MemoryBackendFile,
DeviceID: "nv0",
ID: "mem0",
MemPath: path,
Size: (uint64)(imageStat.Size()),
}

devices = append(devices, object)

return devices, nil
}

func (q *qemuArm64) setIgnoreSharedMemoryMigrationCaps(_ context.Context, _ *govmmQemu.QMP) error {
// x-ignore-shared not support in arm64 for now
return nil
Expand Down
35 changes: 34 additions & 1 deletion src/runtime/virtcontainers/qemu_arm64_test.go
Expand Up @@ -126,10 +126,43 @@ func TestQemuArm64AppendImage(t *testing.T) {
assert.NoError(err)
assert.Equal(expectedOut, devices)

// restore default supportedQemuMachines options
//restore default supportedQemuMachines options
assert.Equal(len(supportedQemuMachines), copy(supportedQemuMachines, machinesCopy))
}

func TestQemuArm64AppendNvdimmImage(t *testing.T) {
var devices []govmmQemu.Device
assert := assert.New(t)

f, err := ioutil.TempFile("", "img")
assert.NoError(err)
defer func() { _ = f.Close() }()
defer func() { _ = os.Remove(f.Name()) }()

imageStat, err := f.Stat()
assert.NoError(err)

cfg := qemuConfig(QemuVirt)
cfg.ImagePath = f.Name()
arm64, err := newQemuArch(cfg)
assert.NoError(err)

expectedOut := []govmmQemu.Device{
govmmQemu.Object{
Driver: govmmQemu.NVDIMM,
Type: govmmQemu.MemoryBackendFile,
DeviceID: "nv0",
ID: "mem0",
MemPath: f.Name(),
Size: (uint64)(imageStat.Size()),
},
}

devices, err = arm64.appendNvdimmImage(devices, f.Name())
assert.NoError(err)
assert.Equal(expectedOut, devices)
}

func TestQemuArm64WithInitrd(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit 77604de

Please sign in to comment.