The majority of the code is prepared since virtio-pmem. The alias
for virtio-mem is new ("virtiomem"). And again, prealloc doesn't
make much sense - the whole point is to dynamically allocate
memory for guest and possibly return it to the host (e.g. if the
host is running low on memory) and this wouldn't happen with
prealloc.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_alias.c | 5 +-
src/qemu/qemu_command.c | 19 +++++--
...mory-hotplug-virtio-mem.x86_64-latest.args | 53 +++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
4 files changed, 74 insertions(+), 4 deletions(-)
create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 68d4a7b480..29c26f0b72 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -521,7 +521,10 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
idx = qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix);
break;
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO:
- prefix = "virtiopmem";
+ if (mem->s.virtio.pmem)
+ prefix = "virtiopmem";
+ else
+ prefix = "virtiomem";
idx = qemuDeviceMemoryGetAliasID(def, mem, true, prefix);
break;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1ee5110b44..a94b81ce15 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2975,9 +2975,14 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
nvdimmPmem = mem->s.nvdimm.pmem;
break;
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO:
+ pagesize = mem->s.virtio.pagesize;
+ needHugepage = !!pagesize;
+ useHugepage = !!pagesize;
+ nodemask = mem->s.virtio.sourceNodes;
nvdimmPath = mem->s.virtio.path;
- /* virtio-pmem doesn't need prealloc, it's very likely exposing a real
- * device and thus there's nothing to prealloc */
+ /* virtio-pmem doesn't need prealloc. Either it's pmem and thus very
+ * likely exposing a real device where is nothing to prealloc, OR it's
+ * virtio-mem where we want to unmap pages on the fly. */
allowPrealloc = false;
break;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
@@ -3305,7 +3310,10 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def,
break;
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO:
- device = "virtio-pmem-pci";
+ if (mem->s.virtio.pmem)
+ device = "virtio-pmem-pci";
+ else
+ device = "virtio-mem-pci";
case VIR_DOMAIN_MEMORY_MODEL_NONE:
case VIR_DOMAIN_MEMORY_MODEL_LAST:
@@ -3320,6 +3328,11 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def,
if (mem->labelsize)
virBufferAsprintf(&buf, "label-size=%llu,", mem->labelsize *
1024);
+ if (mem->blocksize) {
+ virBufferAsprintf(&buf, "block-size=%llu,", mem->blocksize *
1024);
+ virBufferAsprintf(&buf, "requested-size=%llu,",
mem->requestedsize * 1024);
+ }
+
if (virUUIDIsValid(mem->uuid)) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
new file mode 100644
index 0000000000..c12248518d
--- /dev/null
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
@@ -0,0 +1,53 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-i386 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine pc,accel=kvm,usb=off,dump-guest-core=off \
+-cpu qemu64 \
+-m size=2095104k,slots=16,maxmem=1099511627776k \
+-overcommit mem-lock=off \
+-smp 2,sockets=2,dies=1,cores=1,threads=1 \
+-object memory-backend-ram,id=ram-node0,size=2145386496 \
+-numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \
+-object memory-backend-ram,id=memvirtiomem0,size=1073741824 \
+-device virtio-mem-pci,node=0,block-size=2097152,requested-size=536870912,\
+memdev=memvirtiomem0,id=virtiomem0,bus=pci.0,addr=0x2 \
+-object memory-backend-file,id=memvirtiomem1,\
+mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,size=2147483648,\
+host-nodes=1-3,policy=bind \
+-device virtio-mem-pci,node=0,block-size=2097152,requested-size=1073741824,\
+memdev=memvirtiomem1,id=virtiomem1,bus=pci.0,addr=0x4 \
+-object memory-backend-file,id=memvirtiomem2,mem-path=/tmp/virtio_mem,\
+size=4294967296 \
+-device virtio-mem-pci,node=0,block-size=2097152,requested-size=536870912,\
+memdev=memvirtiomem2,id=virtiomem2,bus=pci.0,addr=0x5 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-blockdev
'{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}'
\
+-blockdev
'{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\
+"file":"libvirt-1-storage"}' \
+-device ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ide0-0-0,bootindex=1 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ba904149e8..86a039eddd 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -3013,6 +3013,7 @@ mymain(void)
DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-readonly");
DO_TEST_CAPS_ARCH_LATEST("memory-hotplug-nvdimm-ppc64",
"ppc64");
DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem");
+ DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem");
DO_TEST("machine-aeskeywrap-on-caps",
QEMU_CAPS_AES_KEY_WRAP,
--
2.26.2