Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #119 from devimc/topic/qemu/AddPmem
Browse files Browse the repository at this point in the history
qemu: add pmem flag to memory-backend-file
  • Loading branch information
Julio Montes committed Mar 4, 2020
2 parents 3700c55 + 5378725 commit e969afb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions qemu/qmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,9 @@ func (q *QMP) ExecHotplugMemory(ctx context.Context, qomtype, id, mempath string
// a NVDIMM driver with the device_add command.
// id is the id of the device to add. It must be a valid QMP identifier.
// mempath is the path of the device to add, e.g., /dev/rdb0. size is
// the data size of the device.
func (q *QMP) ExecuteNVDIMMDeviceAdd(ctx context.Context, id, mempath string, size int64) error {
// the data size of the device. pmem is to guarantee the persistence of QEMU writes
// to the vNVDIMM backend.
func (q *QMP) ExecuteNVDIMMDeviceAdd(ctx context.Context, id, mempath string, size int64, pmem *bool) error {
args := map[string]interface{}{
"qom-type": "memory-backend-file",
"id": "nvdimmbackmem" + id,
Expand All @@ -1439,6 +1440,14 @@ func (q *QMP) ExecuteNVDIMMDeviceAdd(ctx context.Context, id, mempath string, si
"share": true,
},
}

if q.version.Major > 4 || (q.version.Major == 4 && q.version.Minor >= 1) {
if pmem != nil {
props := args["props"].(map[string]interface{})
props["pmem"] = *pmem
}
}

err := q.executeCommand(ctx, "object-add", args, nil)
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion qemu/qmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,12 @@ func TestExecuteNVDIMMDeviceAdd(t *testing.T) {
cfg := QMPConfig{Logger: qmpTestLogger{}}
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
checkVersion(t, connectedCh)
err := q.ExecuteNVDIMMDeviceAdd(context.Background(), "nvdimm0", "/dev/rbd0", 1024)
q.version = &QMPVersion{
Major: 4,
Minor: 1,
}
pmem := true
err := q.ExecuteNVDIMMDeviceAdd(context.Background(), "nvdimm0", "/dev/rbd0", 1024, &pmem)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down

0 comments on commit e969afb

Please sign in to comment.