Add conversion from xml to argv for subelements source,access and allocation of <memoryBacking> This change introduces support for preallocated shared file descriptor based memory backing. It allows vhost-user to be used without hugepages. Configured by these elements: <memoryBacking> <source type="file|anonymous"/> <access Mode="shared|private"/> <allocation mode="immediate|ondemand"/> </memoryBacking> --- src/qemu/qemu_command.c | 56 ++++++++++++++++++++++ src/qemu/qemu_command.h | 4 ++ .../qemuxml2argv-memorybacking-set.args | 6 ++- tests/qemuxml2argvtest.c | 3 ++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6944129..321e71f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9328,6 +9328,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (qemuBuildNVRAMCommandLine(cmd, def, qemuCaps) < 0) goto error; + if (qemuBuildMemoryBackendCommandLine(cmd, def, qemuCaps) < 0) + goto error; + if (snapshot) virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL); @@ -9592,3 +9595,56 @@ qemuBuildChrDeviceStr(char **deviceStr, return ret; } + +static char * +qemuBuildMemoryBackendFileStr(const virDomainDef *def) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + const char template[] = "memory-backend-file,id=mem,size=1024M,mem-path=/var/lib/libvirt/qemu"; + + if (VIR_DOMAIN_MEMORY_ACCESS_SHARED == def->mem.access) { + // add ",share=on" to -object memory-backend-file + virBufferAsprintf(&buf, "%s,share=on", template); + } else { + virBufferAsprintf(&buf, "%s", template); + } + + + if (virBufferCheckError(&buf) < 0) + goto error; + + return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; +} + + +int +qemuBuildMemoryBackendCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps __attribute__((unused))) +{ + char *optstr = NULL; + + if (VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE == def->mem.allocation) { + // add '-mem-prealloc' + virCommandAddArg(cmd, "-mem-prealloc"); + } + + if (VIR_DOMAIN_MEMORY_SOURCE_FILE == def->mem.source) { + optstr = qemuBuildMemoryBackendFileStr(def); + if (optstr) { + virCommandAddArg(cmd, "-object"); + virCommandAddArg(cmd, optstr); + VIR_FREE(optstr); + } + + // add '-object memory-backend-file,id=mem,size=1024M,mem-path=/var/lib/libvirt/qemu' + // add '-numa node,memdev=mem' + virCommandAddArgList(cmd, "-numa", "node,memdev=mem", NULL); + } + + return 0; +} diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 9ff4edb..f95d0ea 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -175,5 +175,9 @@ bool qemuCheckCCWS390AddressSupport(const virDomainDef *def, virDomainDeviceInfo info, virQEMUCapsPtr qemuCaps, const char *devicename); +int +qemuBuildMemoryBackendCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps); #endif /* __QEMU_COMMAND_H__*/ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.args b/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.args index bb702dc..626fb21 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.args @@ -19,4 +19,8 @@ QEMU_AUDIO_DRV=none \ -usb \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ --device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-mem-prealloc \ +-object memory-backend-file,id=mem,size=1024M,mem-path=/var/lib/libvirt/qemu,\ +share=on \ +-numa node,memdev=mem diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a4b8bf4..401b455 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2024,6 +2024,9 @@ mymain(void) DO_TEST("acpi-table", NONE); + DO_TEST("memorybacking-unset", NONE); + DO_TEST("memorybacking-set", NONE); + qemuTestDriverFree(&driver); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -- 2.1.0 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list