
On Thu, Jun 23, 2016 at 01:25:29PM +0100, Jaroslav Safka wrote:
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";
As Michael has pointed out - this is just insanity - you can't hardcode memory size like this.
+ + 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"); + } +
You need todo
+ if (VIR_DOMAIN_MEMORY_SOURCE_FILE == def->mem.source) { + optstr = qemuBuildMemoryBackendFileStr(def); + if (optstr) { + virCommandAddArg(cmd, "-object"); + virCommandAddArg(cmd, optstr); + VIR_FREE(optstr); + }
You're ignoring the error here - you must propagate the NULL error.
+ + // 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); + }
We already have code that runs when the guest has NUMA topology configured. This existing code must be adapted to honour the top level VIR_DOMAIN_MEMORY_ACCESS_* setting, vs the per-cell setting. This new code you're adding should only be used when a non-NUMA guest config is requested, and it should be using the -mem-path command line argument to set the file - not = creating a NUMA topology in a non-NUMA requested guest. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|