[libvirt] [PATCH 0/2] memdev device: add share argument for type=file

This patch enables the possibility to run a qemu virtual machine with the share option for the memory-backend-file. The xml description looks like: <memdev type='file' share='on'> <name>ram0</name> <source mem-path='/hugetlbfs'/> <capacity unit='MiB'>1024</capacity> </memdev> This work is based on the previous work of Chen Fan[1]. We are aware of the existing conflict with the previous numa patches[2]. We are sharing this because it is a dependency for some use cases of the qemu vhost-user support(e.g. snabbswitch). [1] http://www.redhat.com/archives/libvir-list/2014-June/msg01195.html [2] http://www.redhat.com/archives/libvir-list/2014-June/msg00201.html Michele Paolino (2): Add share argument to memdev devices(type=file) Documentation and test for the share argument in memdev device docs/formatdomain.html.in | 7 +++++++ docs/schemas/domaincommon.rng | 3 +++ src/conf/domain_conf.c | 16 ++++++++++++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 3 +++ tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args | 2 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml | 2 +- 7 files changed, 32 insertions(+), 2 deletions(-) -- 1.9.3

Add the share option in the XML parser and in the memdev domain structure. Signed-off-by: Michele Paolino <m.paolino@virtualopensystems.com> --- src/conf/domain_conf.c | 16 ++++++++++++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 3 +++ 3 files changed, 20 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 465a223..e73b6f5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9250,6 +9250,13 @@ virDomainMemDevDefParseXML(xmlNodePtr node, goto error; } + if ((tmp = virXMLPropString(node, "share")) != NULL) { + if (STREQ(tmp, "on")) + def->share = true; + VIR_FREE(tmp); + } + if ((tmp = virXMLPropString(node, "merge")) != NULL) { if (STREQ(tmp, "yes")) def->merge = true; @@ -9297,6 +9304,13 @@ virDomainMemDevDefParseXML(xmlNodePtr node, goto error; } + if (def->type == VIR_DOMAIN_MEMDEV_RAM && def->share) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("The share argument should be not specified when " + "memory device type is 'ram'")); + goto error; + } + def->hostnodes = virXPathString("string(./source/@host-nodes)", ctxt); policy = virXPathString("string(./source/@policy)", ctxt); @@ -16434,6 +16448,8 @@ virDomainMemDevDefFormat(virBufferPtr buf, } virBufferAsprintf(buf, "<memdev type='%s'", type); + if (def->type == VIR_DOMAIN_MEMDEV_FILE && def->share) + virBufferAddLit(buf, " share='on'"); if (def->merge) virBufferAddLit(buf, " merge='yes'"); if (def->dump) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 06e6781..eb5bad7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1508,6 +1508,7 @@ struct _virDomainMemDevDef { unsigned long long capacity; /* bytes */ + bool share; bool merge; bool dump; bool prealloc; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index db6717f..25e5b3c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4631,6 +4631,9 @@ qemuBuildMemObjectStr(virDomainMemDevDefPtr dev, if (dev->type == VIR_DOMAIN_MEMDEV_FILE && dev->mempath) virBufferAsprintf(&buf, ",mem-path=%s", dev->mempath); + if (dev->type == VIR_DOMAIN_MEMDEV_FILE && dev->share) + virBufferAsprintf(&buf, ",share=on"); + if (dev->hostnodes) virBufferAsprintf(&buf, ",host-nodes=%s", dev->hostnodes); -- 1.9.3

This patch adds documentation and test for the memdev device (type=file) share option. Signed-off-by: Michele Paolino <m.paolino@virtualopensystems.com> --- docs/formatdomain.html.in | 7 +++++++ docs/schemas/domaincommon.rng | 3 +++ tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args | 2 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 0bc0139..3f8bbee 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5307,6 +5307,13 @@ qemu-kvm -net nic,model=? /dev/null The optional prealloc attribute enables memory preallocation. </p> </dd> + <dt><code>share</code></dt> + <dd> + <p> + The optional share attribute enables the share option for the backend + memory-backed-file(type = 'file'). + </p> + </dd> <dt><code>source</code></dt> <dd>The source element describes the device as seen from the host. the optional <code>mem-path</code> element is required when specified type = 'file'. diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 709d13e..af51eee 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3157,6 +3157,9 @@ </choice> </attribute> <optional> + <attribute name='share'> + <value>on</value> + </attribute> <attribute name='merge'> <value>yes</value> </attribute> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args index 3a1cd94..6c92194 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args @@ -1,7 +1,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ /usr/bin/qemu -S -M pc \ -m 214 \ --object memory-backend-file,id=ram0,size=109568K,merge=yes,dump=yes,prealloc=yes,mem-path=/hugepages,\ +-object memory-backend-file,id=ram0,size=109568K,merge=yes,dump=yes,prealloc=yes,mem-path=/hugepages,share=on,\ host-nodes=0,policy=bind \ -object memory-backend-file,id=ram1,size=109568K,mem-path=/hugepages,host-nodes=0,policy=bind \ -smp 16 -numa node,nodeid=0,cpus=0-7,memdev=ram0 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml index 03e3a28..d30ee80 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml @@ -21,7 +21,7 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu</emulator> - <memdev type='file' merge='yes' dump='yes' prealloc='yes'> + <memdev type='file' share='on' merge='yes' dump='yes' prealloc='yes'> <name>ram0</name> <capacity unit='KiB'>109550</capacity> <source mem-path='/hugepages' host-nodes='0' policy='bind'/> -- 1.9.3

On Fri, Jun 27, 2014 at 10:53:10PM +0200, Michele Paolino wrote:
This patch enables the possibility to run a qemu virtual machine with the share option for the memory-backend-file. The xml description looks like:
<memdev type='file' share='on'> <name>ram0</name> <source mem-path='/hugetlbfs'/> <capacity unit='MiB'>1024</capacity> </memdev>
This work is based on the previous work of Chen Fan[1]. We are aware of the existing conflict with the previous numa patches[2]. We are sharing this because it is a dependency for some use cases of the qemu vhost-user support(e.g. snabbswitch).
There is one important thing left out. What qemu uses as a memdev should not be exposed as such (a device) in the XML, that way the definition makes sense only for people aware of how qemu works, but we are trying to keep the XML as hypervisor-independent as possible. Of course only where applicable, many places must have hypervisor-dependent structures, but I don't think memory device is one of these exceptions. All the options that qemu aspose as memdev options should be abstracted in the XML. For example3, we already have an element in the XML that says "use hugepages as a backing for memory" and that element should be used for that. I just skimmed the patches a bit, but it looks like none of the series works with that information or changes the behaviour based on that. Martin
[1] http://www.redhat.com/archives/libvir-list/2014-June/msg01195.html [2] http://www.redhat.com/archives/libvir-list/2014-June/msg00201.html
Michele Paolino (2): Add share argument to memdev devices(type=file) Documentation and test for the share argument in memdev device
docs/formatdomain.html.in | 7 +++++++ docs/schemas/domaincommon.rng | 3 +++ src/conf/domain_conf.c | 16 ++++++++++++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 3 +++ tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.args | 2 +- tests/qemuxml2argvdata/qemuxml2argv-cpu-numa4.xml | 2 +- 7 files changed, 32 insertions(+), 2 deletions(-)
-- 1.9.3

On Mon, Jun 30, 2014 at 10:39:05AM +0200, Martin Kletzander wrote:
On Fri, Jun 27, 2014 at 10:53:10PM +0200, Michele Paolino wrote:
This patch enables the possibility to run a qemu virtual machine with the share option for the memory-backend-file. The xml description looks like:
<memdev type='file' share='on'> <name>ram0</name> <source mem-path='/hugetlbfs'/> <capacity unit='MiB'>1024</capacity> </memdev>
This work is based on the previous work of Chen Fan[1]. We are aware of the existing conflict with the previous numa patches[2]. We are sharing this because it is a dependency for some use cases of the qemu vhost-user support(e.g. snabbswitch).
There is one important thing left out. What qemu uses as a memdev should not be exposed as such (a device) in the XML, that way the definition makes sense only for people aware of how qemu works, but we are trying to keep the XML as hypervisor-independent as possible. Of course only where applicable, many places must have hypervisor-dependent structures, but I don't think memory device is one of these exceptions. All the options that qemu aspose as memdev options should be abstracted in the XML. For example3, we already have an element in the XML that says "use hugepages as a backing for memory" and that element should be used for that. I just skimmed the patches a bit, but it looks like none of the series works with that information or changes the behaviour based on that.
Agreed, we really don't want to expose memdev as a user visible device, since it really isn't a guest device - this is entirely host-side config information. 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 :|
participants (3)
-
Daniel P. Berrange
-
Martin Kletzander
-
Michele Paolino