[libvirt] [PATCH v4 0/6] Newer ivshmem models

v4: - Incorporated John's review v3: - https://www.redhat.com/archives/libvir-list/2016-September/msg01232.html Martin Kletzander (6): conf, qemu: Add support for shmem model conf, qemu: Add newer shmem models qemu: Add capabilities for ivshmem-{plain,doorbell} qemu: Save various defaults for shmem qemu: Support newer ivshmem device variants qemu: Add support for hot/cold-(un)plug of shmem devices docs/formatdomain.html.in | 12 + docs/schemas/domaincommon.rng | 11 + src/conf/domain_conf.c | 46 +++- src/conf/domain_conf.h | 10 + src/libvirt_private.syms | 2 + src/qemu/qemu_capabilities.c | 5 + src/qemu/qemu_capabilities.h | 4 + src/qemu/qemu_command.c | 111 ++++++++- src/qemu/qemu_command.h | 10 + src/qemu/qemu_domain.c | 54 +++++ src/qemu/qemu_driver.c | 39 +++- src/qemu/qemu_hotplug.c | 248 ++++++++++++++++++++- src/qemu/qemu_hotplug.h | 6 + .../caps_2.6.0-gicv2.aarch64.xml | 2 + .../caps_2.6.0-gicv3.aarch64.xml | 2 + tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml | 2 + tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml | 2 + tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml | 2 + tests/qemuhotplugtest.c | 21 ++ .../qemuhotplug-ivshmem-doorbell-detach.xml | 7 + .../qemuhotplug-ivshmem-doorbell.xml | 4 + .../qemuhotplug-ivshmem-plain-detach.xml | 6 + .../qemuhotplug-ivshmem-plain.xml | 3 + ...muhotplug-base-live+ivshmem-doorbell-detach.xml | 1 + .../qemuhotplug-base-live+ivshmem-doorbell.xml | 65 ++++++ .../qemuhotplug-base-live+ivshmem-plain-detach.xml | 1 + .../qemuhotplug-base-live+ivshmem-plain.xml | 58 +++++ .../qemuxml2argv-shmem-plain-doorbell.args | 43 ++++ ...m.xml => qemuxml2argv-shmem-plain-doorbell.xml} | 16 +- tests/qemuxml2argvdata/qemuxml2argv-shmem.args | 2 +- tests/qemuxml2argvdata/qemuxml2argv-shmem.xml | 2 + tests/qemuxml2argvtest.c | 3 + ...xml => qemuxml2xmlout-shmem-plain-doorbell.xml} | 18 +- tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 9 + tests/qemuxml2xmltest.c | 1 + 35 files changed, 798 insertions(+), 30 deletions(-) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args copy tests/qemuxml2argvdata/{qemuxml2argv-shmem.xml => qemuxml2argv-shmem-plain-doorbell.xml} (80%) copy tests/qemuxml2xmloutdata/{qemuxml2xmlout-shmem.xml => qemuxml2xmlout-shmem-plain-doorbell.xml} (82%) -- 2.10.1

Just the default one now, new ones will be added in following commits. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- docs/formatdomain.html.in | 8 +++++ docs/schemas/domaincommon.rng | 9 +++++ src/conf/domain_conf.c | 44 +++++++++++++++++------ src/conf/domain_conf.h | 8 +++++ src/libvirt_private.syms | 2 ++ src/qemu/qemu_command.c | 11 +++++- tests/qemuxml2argvdata/qemuxml2argv-shmem.xml | 2 ++ tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 8 +++++ 8 files changed, 80 insertions(+), 12 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index c70377ba4847..10a692de2553 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -6829,6 +6829,7 @@ qemu-kvm -net nic,model=? /dev/null <size unit='M'>4</size> </shmem> <shmem name='shmem_server'> + <model type='ivshmem'/> <size unit='M'>2</size> <server path='/tmp/socket-shmem'/> <msi vectors='32' ioeventfd='on'/> @@ -6843,6 +6844,13 @@ qemu-kvm -net nic,model=? /dev/null The <code>shmem</code> element has one mandatory attribute, <code>name</code> to identify the shared memory. </dd> + <dt><code>model</code></dt> + <dd> + Attribute <code>type</code> of the optional element <code>model</code> + specifies the model of the underlying device providing the + <code>shmem</code> device. Currently the only supported model is + <code>ivshmem</code>. + </dd> <dt><code>size</code></dt> <dd> The optional <code>size</code> element specifies the size of the shared diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index dba9187aa716..99e0eb6cb448 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3592,6 +3592,15 @@ <attribute name="name"/> <interleave> <optional> + <element name="model"> + <attribute name="type"> + <choice> + <value>ivshmem</value> + </choice> + </attribute> + </element> + </optional> + <optional> <element name="size"> <ref name="scaledInteger"/> </element> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 03506cbec142..108a48ee974e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -844,6 +844,9 @@ VIR_ENUM_IMPL(virDomainBlockJob, VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, VIR_ENUM_IMPL(virDomainMemoryModel, VIR_DOMAIN_MEMORY_MODEL_LAST, "", "dimm") +VIR_ENUM_IMPL(virDomainShmemModel, VIR_DOMAIN_SHMEM_MODEL_LAST, + "ivshmem") + static virClassPtr virDomainObjClass; static virClassPtr virDomainXMLOptionClass; static void virDomainObjDispose(void *obj); @@ -12351,6 +12354,20 @@ virDomainShmemDefParseXML(xmlNodePtr node, ctxt->node = node; + tmp = virXPathString("string(./model/@type)", ctxt); + if (tmp) { + /* If there's none, we will automatically have the first one + * (as default). Unfortunately this has to be done for + * compatibility reasons. */ + if ((def->model = virDomainShmemModelTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Unknown shmem model type '%s'"), tmp); + goto cleanup; + } + + VIR_FREE(tmp); + } + if (!(def->name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("shmem element must contain 'name' attribute")); @@ -14939,6 +14956,9 @@ virDomainShmemDefEquals(virDomainShmemDefPtr src, if (src->size != dst->size) return false; + if (src->model != dst->model) + return false; + if (src->server.enabled != dst->server.enabled) return false; @@ -18927,6 +18947,15 @@ virDomainShmemDefCheckABIStability(virDomainShmemDefPtr src, return false; } + if (src->model != dst->model) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target shared memory model '%s' does not match " + "source model '%s'"), + virDomainShmemModelTypeToString(dst->model), + virDomainShmemModelTypeToString(src->model)); + return false; + } + if (src->size != dst->size) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target shared memory size '%llu' does not match " @@ -21980,20 +22009,13 @@ virDomainShmemDefFormat(virBufferPtr buf, virDomainShmemDefPtr def, unsigned int flags) { - virBufferEscapeString(buf, "<shmem name='%s'", def->name); - - if (!def->size && - !def->server.enabled && - !def->msi.enabled && - !virDomainDeviceInfoNeedsFormat(&def->info, flags)) { - virBufferAddLit(buf, "/>\n"); - return 0; - } else { - virBufferAddLit(buf, ">\n"); - } + virBufferEscapeString(buf, "<shmem name='%s'>\n", def->name); virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "<model type='%s'/>\n", + virDomainShmemModelTypeToString(def->model)); + if (def->size) virBufferAsprintf(buf, "<size unit='M'>%llu</size>\n", def->size >> 20); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 24aa79cdc9e4..d2a9289e077d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1562,9 +1562,16 @@ struct _virDomainNVRAMDef { virDomainDeviceInfo info; }; +typedef enum { + VIR_DOMAIN_SHMEM_MODEL_IVSHMEM, + + VIR_DOMAIN_SHMEM_MODEL_LAST +} virDomainShmemModel; + struct _virDomainShmemDef { char *name; unsigned long long size; + int model; /* enum virDomainShmemModel */ struct { bool enabled; virDomainChrSourceDef chr; @@ -3084,6 +3091,7 @@ VIR_ENUM_DECL(virDomainTPMBackend) VIR_ENUM_DECL(virDomainMemoryModel) VIR_ENUM_DECL(virDomainMemoryBackingModel) VIR_ENUM_DECL(virDomainIOMMUModel) +VIR_ENUM_DECL(virDomainShmemModel) /* from libvirt.h */ VIR_ENUM_DECL(virDomainState) VIR_ENUM_DECL(virDomainNostateReason) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b4210f4ea864..6ad9511aaec8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -472,6 +472,8 @@ virDomainShmemDefFind; virDomainShmemDefFree; virDomainShmemDefInsert; virDomainShmemDefRemove; +virDomainShmemModelTypeFromString; +virDomainShmemModelTypeToString; virDomainShutdownReasonTypeFromString; virDomainShutdownReasonTypeToString; virDomainShutoffReasonTypeFromString; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 405e1184afb4..f05f2fd1c5c4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8499,7 +8499,16 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager, return -1; } - if (!(devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps))) + switch ((virDomainShmemModel)shmem->model) { + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: + devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps); + break; + + case VIR_DOMAIN_SHMEM_MODEL_LAST: + break; + } + + if (!devstr) return -1; virCommandAddArgList(cmd, "-device", devstr, NULL); VIR_FREE(devstr); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml b/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml index 5bc49044894c..b56e9e187895 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml @@ -28,6 +28,7 @@ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </shmem> <shmem name='shmem3'> + <model type='ivshmem'/> <size unit='M'>512</size> <server/> </shmem> @@ -41,6 +42,7 @@ <msi ioeventfd='off'/> </shmem> <shmem name='shmem6'> + <model type='ivshmem'/> <size unit='M'>4096</size> <server path='/tmp/shmem6-sock'/> <msi vectors='16'/> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml index 1197f361e3c4..5602913648bc 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml @@ -22,39 +22,47 @@ <input type='keyboard' bus='ps2'/> <memballoon model='none'/> <shmem name='shmem0'> + <model type='ivshmem'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </shmem> <shmem name='shmem1'> + <model type='ivshmem'/> <size unit='M'>128</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </shmem> <shmem name='shmem2'> + <model type='ivshmem'/> <size unit='M'>256</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </shmem> <shmem name='shmem3'> + <model type='ivshmem'/> <size unit='M'>512</size> <server/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </shmem> <shmem name='shmem4'> + <model type='ivshmem'/> <size unit='M'>1024</size> <server path='/tmp/shmem4-sock'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </shmem> <shmem name='shmem5'> + <model type='ivshmem'/> <size unit='M'>2048</size> <server path='/tmp/shmem5-sock'/> <msi ioeventfd='off'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> </shmem> <shmem name='shmem6'> + <model type='ivshmem'/> <size unit='M'>4096</size> <server path='/tmp/shmem6-sock'/> <msi vectors='16'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> </shmem> <shmem name='shmem7'> + <model type='ivshmem'/> <size unit='M'>8192</size> <server path='/tmp/shmem7-sock'/> <msi vectors='32' ioeventfd='on'/> -- 2.10.1

On Wed, Oct 26, 2016 at 12:51:32 +0200, Martin Kletzander wrote:
Just the default one now, new ones will be added in following commits.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- docs/formatdomain.html.in | 8 +++++ docs/schemas/domaincommon.rng | 9 +++++ src/conf/domain_conf.c | 44 +++++++++++++++++------ src/conf/domain_conf.h | 8 +++++ src/libvirt_private.syms | 2 ++ src/qemu/qemu_command.c | 11 +++++- tests/qemuxml2argvdata/qemuxml2argv-shmem.xml | 2 ++ tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 8 +++++ 8 files changed, 80 insertions(+), 12 deletions(-)
ACK

The old ivshmem is deprecated in QEMU, so let's use the better ivshmem-{plain,doorbell} variants instead. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- docs/formatdomain.html.in | 10 +++++++--- docs/schemas/domaincommon.rng | 2 ++ src/conf/domain_conf.c | 4 +++- src/conf/domain_conf.h | 2 ++ src/qemu/qemu_command.c | 7 +++++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 10a692de2553..11b3330cee87 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -6826,10 +6826,11 @@ qemu-kvm -net nic,model=? /dev/null ... <devices> <shmem name='my_shmem0'> + <model type='ivshmem-plain'/> <size unit='M'>4</size> </shmem> <shmem name='shmem_server'> - <model type='ivshmem'/> + <model type='ivshmem-doorbell'/> <size unit='M'>2</size> <server path='/tmp/socket-shmem'/> <msi vectors='32' ioeventfd='on'/> @@ -6848,8 +6849,11 @@ qemu-kvm -net nic,model=? /dev/null <dd> Attribute <code>type</code> of the optional element <code>model</code> specifies the model of the underlying device providing the - <code>shmem</code> device. Currently the only supported model is - <code>ivshmem</code>. + <code>shmem</code> device. The models currently supported are + <code>ivshmem</code> (supports both server and server-less shmem, but is + deprecated by newer QEMU in favour of the -plain and -doorbell variants), + <code>ivshmem-plain</code> (only for server-less shmem) and + <code>ivshmem-doorbell</code> (only for shmem with the server). </dd> <dt><code>size</code></dt> <dd> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 99e0eb6cb448..19d45fd6eae3 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3596,6 +3596,8 @@ <attribute name="type"> <choice> <value>ivshmem</value> + <value>ivshmem-plain</value> + <value>ivshmem-doorbell</value> </choice> </attribute> </element> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 108a48ee974e..a233c0c4208a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -845,7 +845,9 @@ VIR_ENUM_IMPL(virDomainMemoryModel, VIR_DOMAIN_MEMORY_MODEL_LAST, "", "dimm") VIR_ENUM_IMPL(virDomainShmemModel, VIR_DOMAIN_SHMEM_MODEL_LAST, - "ivshmem") + "ivshmem", + "ivshmem-plain", + "ivshmem-doorbell") static virClassPtr virDomainObjClass; static virClassPtr virDomainXMLOptionClass; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d2a9289e077d..541b6003c87e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1564,6 +1564,8 @@ struct _virDomainNVRAMDef { typedef enum { VIR_DOMAIN_SHMEM_MODEL_IVSHMEM, + VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN, + VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL, VIR_DOMAIN_SHMEM_MODEL_LAST } virDomainShmemModel; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f05f2fd1c5c4..558122b4cf7e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8504,6 +8504,13 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager, devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps); break; + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("%s device is not supported with this QEMU binary"), + virDomainShmemModelTypeToString(shmem->model)); + break; + case VIR_DOMAIN_SHMEM_MODEL_LAST: break; } -- 2.10.1

On Wed, Oct 26, 2016 at 12:51:33 +0200, Martin Kletzander wrote:
The old ivshmem is deprecated in QEMU, so let's use the better ivshmem-{plain,doorbell} variants instead.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- docs/formatdomain.html.in | 10 +++++++--- docs/schemas/domaincommon.rng | 2 ++ src/conf/domain_conf.c | 4 +++- src/conf/domain_conf.h | 2 ++ src/qemu/qemu_command.c | 7 +++++++ 5 files changed, 21 insertions(+), 4 deletions(-)
ACK although it looks like you meant to add stuff from the following commit.

On Wed, Nov 02, 2016 at 10:45:36AM +0100, Peter Krempa wrote:
On Wed, Oct 26, 2016 at 12:51:33 +0200, Martin Kletzander wrote:
The old ivshmem is deprecated in QEMU, so let's use the better ivshmem-{plain,doorbell} variants instead.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- docs/formatdomain.html.in | 10 +++++++--- docs/schemas/domaincommon.rng | 2 ++ src/conf/domain_conf.c | 4 +++- src/conf/domain_conf.h | 2 ++ src/qemu/qemu_command.c | 7 +++++++ 5 files changed, 21 insertions(+), 4 deletions(-)
ACK although it looks like you meant to add stuff from the following commit.
AAAaaargh, I'll move it _again_... You're right, but if I hadn't had to move it the first time... Anyway, I'll do that. Thanks.
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, Nov 02, 2016 at 12:10:21 +0100, Martin Kletzander wrote:
On Wed, Nov 02, 2016 at 10:45:36AM +0100, Peter Krempa wrote:
On Wed, Oct 26, 2016 at 12:51:33 +0200, Martin Kletzander wrote:
The old ivshmem is deprecated in QEMU, so let's use the better ivshmem-{plain,doorbell} variants instead.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- docs/formatdomain.html.in | 10 +++++++--- docs/schemas/domaincommon.rng | 2 ++ src/conf/domain_conf.c | 4 +++- src/conf/domain_conf.h | 2 ++ src/qemu/qemu_command.c | 7 +++++++ 5 files changed, 21 insertions(+), 4 deletions(-)
ACK although it looks like you meant to add stuff from the following commit.
AAAaaargh, I'll move it _again_... You're right, but if I hadn't had to move it the first time... Anyway, I'll do that. Thanks.
Well, and why did you move it the first time? :) Anyways, if you move the XML-XML test part here, and the XML-ARGV part to the patch where it's actually added then ACK to everything.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_capabilities.c | 5 ++ src/qemu/qemu_capabilities.h | 4 ++ .../caps_2.6.0-gicv2.aarch64.xml | 2 + .../caps_2.6.0-gicv3.aarch64.xml | 2 + tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml | 2 + tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml | 2 + tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml | 2 + .../qemuxml2argv-shmem-plain-doorbell.args | 43 ++++++++++++++ .../qemuxml2argv-shmem-plain-doorbell.xml | 58 +++++++++++++++++++ .../qemuxml2xmlout-shmem-plain-doorbell.xml | 67 ++++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 11 files changed, 188 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 7a8202ad507d..cd2abf758357 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -347,6 +347,9 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "machine-iommu", "virtio-vga", "drive-iotune-max-length", + "ivshmem-plain", + + "ivshmem-doorbell", /* 240 */ ); @@ -1588,6 +1591,8 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { "pxb-pcie", QEMU_CAPS_DEVICE_PXB_PCIE }, { "tls-creds-x509", QEMU_CAPS_OBJECT_TLS_CREDS_X509 }, { "intel-iommu", QEMU_CAPS_DEVICE_INTEL_IOMMU }, + { "ivshmem-plain", QEMU_CAPS_DEVICE_IVSHMEM_PLAIN }, + { "ivshmem-doorbell", QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBalloon[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 6e7a8550a2a5..983ea758744e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -381,6 +381,10 @@ typedef enum { QEMU_CAPS_MACHINE_IOMMU, /* -machine iommu=on */ QEMU_CAPS_DEVICE_VIRTIO_VGA, /* -device virtio-vga */ QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH, /* -drive bps_max_length = and friends */ + QEMU_CAPS_DEVICE_IVSHMEM_PLAIN, /* -device ivshmem-plain */ + + /* 240 */ + QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL, /* -device ivshmem-doorbell */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml b/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml index 5c6a70998c43..4f1a58b450a8 100644 --- a/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml @@ -159,6 +159,8 @@ <flag name='smm'/> <flag name='virtio-pci-disable-legacy'/> <flag name='drive-iotune-max-length'/> + <flag name='ivshmem-plain'/> + <flag name='ivshmem-doorbell'/> <version>2005094</version> <kvmVersion>0</kvmVersion> <package></package> diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml b/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml index 6ba97be87458..0fa333a5fd1d 100644 --- a/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml @@ -159,6 +159,8 @@ <flag name='smm'/> <flag name='virtio-pci-disable-legacy'/> <flag name='drive-iotune-max-length'/> + <flag name='ivshmem-plain'/> + <flag name='ivshmem-doorbell'/> <version>2005094</version> <kvmVersion>0</kvmVersion> <package></package> diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml b/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml index 9174f58cdfd4..7b3b61c70d3e 100644 --- a/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml +++ b/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml @@ -154,6 +154,8 @@ <flag name='virtio-pci-disable-legacy'/> <flag name='virtio-vga'/> <flag name='drive-iotune-max-length'/> + <flag name='ivshmem-plain'/> + <flag name='ivshmem-doorbell'/> <version>2005094</version> <kvmVersion>0</kvmVersion> <package></package> diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml index 1c309dfadc4c..74b5402899b7 100644 --- a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml @@ -193,6 +193,8 @@ <flag name='machine-iommu'/> <flag name='virtio-vga'/> <flag name='drive-iotune-max-length'/> + <flag name='ivshmem-plain'/> + <flag name='ivshmem-doorbell'/> <version>2006000</version> <kvmVersion>0</kvmVersion> <package></package> diff --git a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml index 2f168da53456..05dfcadb6ae2 100644 --- a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml @@ -194,6 +194,8 @@ <flag name='query-hotpluggable-cpus'/> <flag name='virtio-vga'/> <flag name='drive-iotune-max-length'/> + <flag name='ivshmem-plain'/> + <flag name='ivshmem-doorbell'/> <version>2007000</version> <kvmVersion>0</kvmVersion> <package> (v2.7.0)</package> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args new file mode 100644 index 000000000000..7abc7f8c4be5 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args @@ -0,0 +1,43 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-object memory-backend-file,id=shmmem-shmem0,mem-path=/dev/shm/shmem0,\ +size=4194304 \ +-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,bus=pci.0,addr=0x3 \ +-object memory-backend-file,id=shmmem-shmem1,mem-path=/dev/shm/shmem1,\ +size=134217728 \ +-device ivshmem-plain,id=shmem1,memdev=shmmem-shmem1,bus=pci.0,addr=0x5 \ +-object memory-backend-file,id=shmmem-shmem2,mem-path=/dev/shm/shmem2,\ +size=268435456 \ +-device ivshmem-plain,id=shmem2,memdev=shmmem-shmem2,bus=pci.0,addr=0x4 \ +-device ivshmem-doorbell,id=shmem3,chardev=charshmem3,ioeventfd=on,bus=pci.0,\ +addr=0x6 \ +-chardev socket,id=charshmem3,path=/var/lib/libvirt/shmem-shmem3-sock \ +-device ivshmem-doorbell,id=shmem4,chardev=charshmem4,ioeventfd=on,bus=pci.0,\ +addr=0x7 \ +-chardev socket,id=charshmem4,path=/tmp/shmem4-sock \ +-device ivshmem-doorbell,id=shmem5,chardev=charshmem5,ioeventfd=off,bus=pci.0,\ +addr=0x8 \ +-chardev socket,id=charshmem5,path=/tmp/shmem5-sock \ +-device ivshmem-doorbell,id=shmem6,chardev=charshmem6,vectors=16,ioeventfd=on,\ +bus=pci.0,addr=0x9 \ +-chardev socket,id=charshmem6,path=/tmp/shmem6-sock \ +-device ivshmem-doorbell,id=shmem7,chardev=charshmem7,vectors=32,ioeventfd=on,\ +bus=pci.0,addr=0xa \ +-chardev socket,id=charshmem7,path=/tmp/shmem7-sock diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml new file mode 100644 index 000000000000..454437cbdb39 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml @@ -0,0 +1,58 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + <shmem name='shmem0'> + <model type='ivshmem-plain'/> + </shmem> + <shmem name='shmem1'> + <model type='ivshmem-plain'/> + <size unit='M'>128</size> + </shmem> + <shmem name='shmem2'> + <model type='ivshmem-plain'/> + <size unit='M'>256</size> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </shmem> + <shmem name='shmem3'> + <model type='ivshmem-doorbell'/> + <server/> + </shmem> + <shmem name='shmem4'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem4-sock'/> + </shmem> + <shmem name='shmem5'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem5-sock'/> + <msi ioeventfd='off'/> + </shmem> + <shmem name='shmem6'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem6-sock'/> + <msi vectors='16'/> + </shmem> + <shmem name='shmem7'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem7-sock'/> + <msi vectors='32' ioeventfd='on'/> + </shmem> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml new file mode 100644 index 000000000000..ab9c69bfccd4 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml @@ -0,0 +1,67 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + <shmem name='shmem0'> + <model type='ivshmem-plain'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </shmem> + <shmem name='shmem1'> + <model type='ivshmem-plain'/> + <size unit='M'>128</size> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </shmem> + <shmem name='shmem2'> + <model type='ivshmem-plain'/> + <size unit='M'>256</size> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </shmem> + <shmem name='shmem3'> + <model type='ivshmem-doorbell'/> + <server/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> + </shmem> + <shmem name='shmem4'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem4-sock'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> + </shmem> + <shmem name='shmem5'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem5-sock'/> + <msi ioeventfd='off'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> + </shmem> + <shmem name='shmem6'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem6-sock'/> + <msi vectors='16'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> + </shmem> + <shmem name='shmem7'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem7-sock'/> + <msi vectors='32' ioeventfd='on'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> + </shmem> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 496ed130f838..8a2b5ff842fc 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -822,6 +822,7 @@ mymain(void) DO_TEST("tap-vhost", NONE); DO_TEST("tap-vhost-incorrect", NONE); DO_TEST("shmem", NONE); + DO_TEST("shmem-plain-doorbell", NONE); DO_TEST("smbios", NONE); DO_TEST("smbios-multiple-type2", NONE); -- 2.10.1

On Wed, Oct 26, 2016 at 12:51:34 +0200, Martin Kletzander wrote:
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_capabilities.c | 5 ++ src/qemu/qemu_capabilities.h | 4 ++ .../caps_2.6.0-gicv2.aarch64.xml | 2 + .../caps_2.6.0-gicv3.aarch64.xml | 2 + tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml | 2 + tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml | 2 + tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml | 2 + .../qemuxml2argv-shmem-plain-doorbell.args | 43 ++++++++++++++ .../qemuxml2argv-shmem-plain-doorbell.xml | 58 +++++++++++++++++++ .../qemuxml2xmlout-shmem-plain-doorbell.xml | 67 ++++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 11 files changed, 188 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml
[...] The capability stuff is ok.
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args new file mode 100644 index 000000000000..7abc7f8c4be5 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.args @@ -0,0 +1,43 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-object memory-backend-file,id=shmmem-shmem0,mem-path=/dev/shm/shmem0,\ +size=4194304 \ +-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,bus=pci.0,addr=0x3 \ +-object memory-backend-file,id=shmmem-shmem1,mem-path=/dev/shm/shmem1,\ +size=134217728 \ +-device ivshmem-plain,id=shmem1,memdev=shmmem-shmem1,bus=pci.0,addr=0x5 \ +-object memory-backend-file,id=shmmem-shmem2,mem-path=/dev/shm/shmem2,\ +size=268435456 \ +-device ivshmem-plain,id=shmem2,memdev=shmmem-shmem2,bus=pci.0,addr=0x4 \ +-device ivshmem-doorbell,id=shmem3,chardev=charshmem3,ioeventfd=on,bus=pci.0,\ +addr=0x6 \ +-chardev socket,id=charshmem3,path=/var/lib/libvirt/shmem-shmem3-sock \ +-device ivshmem-doorbell,id=shmem4,chardev=charshmem4,ioeventfd=on,bus=pci.0,\ +addr=0x7 \ +-chardev socket,id=charshmem4,path=/tmp/shmem4-sock \ +-device ivshmem-doorbell,id=shmem5,chardev=charshmem5,ioeventfd=off,bus=pci.0,\ +addr=0x8 \ +-chardev socket,id=charshmem5,path=/tmp/shmem5-sock \ +-device ivshmem-doorbell,id=shmem6,chardev=charshmem6,vectors=16,ioeventfd=on,\ +bus=pci.0,addr=0x9 \ +-chardev socket,id=charshmem6,path=/tmp/shmem6-sock \ +-device ivshmem-doorbell,id=shmem7,chardev=charshmem7,vectors=32,ioeventfd=on,\ +bus=pci.0,addr=0xa \ +-chardev socket,id=charshmem7,path=/tmp/shmem7-sock
This file is unused since you didn't register the test to tests/qemuxml2argvtest.c. Also at this point it won't work. I presume this belongs to a different commit
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml new file mode 100644 index 000000000000..454437cbdb39 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem-plain-doorbell.xml @@ -0,0 +1,58 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + <shmem name='shmem0'> + <model type='ivshmem-plain'/> + </shmem> + <shmem name='shmem1'> + <model type='ivshmem-plain'/> + <size unit='M'>128</size> + </shmem> + <shmem name='shmem2'> + <model type='ivshmem-plain'/> + <size unit='M'>256</size> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </shmem> + <shmem name='shmem3'> + <model type='ivshmem-doorbell'/> + <server/> + </shmem> + <shmem name='shmem4'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem4-sock'/> + </shmem> + <shmem name='shmem5'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem5-sock'/> + <msi ioeventfd='off'/> + </shmem> + <shmem name='shmem6'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem6-sock'/> + <msi vectors='16'/> + </shmem> + <shmem name='shmem7'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem7-sock'/> + <msi vectors='32' ioeventfd='on'/> + </shmem> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml new file mode 100644 index 000000000000..ab9c69bfccd4 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml @@ -0,0 +1,67 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + <shmem name='shmem0'> + <model type='ivshmem-plain'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </shmem> + <shmem name='shmem1'> + <model type='ivshmem-plain'/> + <size unit='M'>128</size> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </shmem> + <shmem name='shmem2'> + <model type='ivshmem-plain'/> + <size unit='M'>256</size> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </shmem> + <shmem name='shmem3'> + <model type='ivshmem-doorbell'/> + <server/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> + </shmem> + <shmem name='shmem4'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem4-sock'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> + </shmem> + <shmem name='shmem5'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem5-sock'/> + <msi ioeventfd='off'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> + </shmem> + <shmem name='shmem6'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem6-sock'/> + <msi vectors='16'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> + </shmem> + <shmem name='shmem7'> + <model type='ivshmem-doorbell'/> + <server path='/tmp/shmem7-sock'/> + <msi vectors='32' ioeventfd='on'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> + </shmem> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 496ed130f838..8a2b5ff842fc 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -822,6 +822,7 @@ mymain(void) DO_TEST("tap-vhost", NONE); DO_TEST("tap-vhost-incorrect", NONE); DO_TEST("shmem", NONE); + DO_TEST("shmem-plain-doorbell", NONE); DO_TEST("smbios", NONE); DO_TEST("smbios-multiple-type2", NONE);
These tests look like they belong to the previous patch.

We're keeping some things at default and that's not something we want to do intentionally. Let's save some sensible defaults upfront in order to avoid having problems later. The details for the defaults (of the newer implementation) can be found in qemu's commit 5400c02b90bb: http://git.qemu.org/?p=qemu.git;a=commit;h=5400c02b90bb Since we are merely saving the defaults it will not change the guest ABI and thanks to the fact that we're doing it in the PostParse callback it will not break the ABI stability checks. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_domain.c | 54 ++++++++++++++++++++++ tests/qemuxml2argvdata/qemuxml2argv-shmem.args | 2 +- .../qemuxml2xmlout-shmem-plain-doorbell.xml | 5 +- tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 1 + 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 94f793e8ce9c..ee3bf8cae3a2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2671,6 +2671,56 @@ qemuDomainChrDefDropDefaultPath(virDomainChrDefPtr chr, static int +qemuDomainShmemDefPostParse(virDomainShmemDefPtr shm) +{ + /* This was the default since the introduction of this device. */ + if (shm->model != VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL && !shm->size) + shm->size = 4 << 20; + + /* Nothing more to check/change for IVSHMEM */ + if (shm->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM) + return 0; + + if (!shm->server.enabled) { + if (shm->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shmem model '%s' is supported " + "only with server option enabled"), + virDomainShmemModelTypeToString(shm->model)); + return -1; + } + + if (shm->msi.enabled) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shmem model '%s' doesn't support " + "msi"), + virDomainShmemModelTypeToString(shm->model)); + } + } else { + if (shm->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shmem model '%s' is supported " + "only with server option disabled"), + virDomainShmemModelTypeToString(shm->model)); + return -1; + } + + if (shm->size) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shmem model '%s' does not support size setting"), + virDomainShmemModelTypeToString(shm->model)); + return -1; + } + shm->msi.enabled = true; + if (!shm->msi.ioeventfd) + shm->msi.ioeventfd = VIR_TRISTATE_SWITCH_ON; + } + + return 0; +} + + +static int qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, virCapsPtr caps, @@ -2874,6 +2924,10 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, } } + if (dev->type == VIR_DOMAIN_DEVICE_SHMEM && + qemuDomainShmemDefPostParse(dev->data.shmem) < 0) + goto cleanup; + ret = 0; cleanup: diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem.args b/tests/qemuxml2argvdata/qemuxml2argv-shmem.args index 99fac119b04c..bdf660a3c435 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-shmem.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem.args @@ -17,7 +17,7 @@ QEMU_AUDIO_DRV=none \ -no-acpi \ -boot c \ -usb \ --device ivshmem,id=shmem0,shm=shmem0,bus=pci.0,addr=0x3 \ +-device ivshmem,id=shmem0,size=4m,shm=shmem0,bus=pci.0,addr=0x3 \ -device ivshmem,id=shmem1,size=128m,shm=shmem1,bus=pci.0,addr=0x5 \ -device ivshmem,id=shmem2,size=256m,shm=shmem2,bus=pci.0,addr=0x4 \ -device ivshmem,id=shmem3,size=512m,chardev=charshmem3,bus=pci.0,addr=0x6 \ diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml index ab9c69bfccd4..7872e1c8a102 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem-plain-doorbell.xml @@ -23,6 +23,7 @@ <memballoon model='none'/> <shmem name='shmem0'> <model type='ivshmem-plain'/> + <size unit='M'>4</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </shmem> <shmem name='shmem1'> @@ -38,11 +39,13 @@ <shmem name='shmem3'> <model type='ivshmem-doorbell'/> <server/> + <msi ioeventfd='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </shmem> <shmem name='shmem4'> <model type='ivshmem-doorbell'/> <server path='/tmp/shmem4-sock'/> + <msi ioeventfd='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </shmem> <shmem name='shmem5'> @@ -54,7 +57,7 @@ <shmem name='shmem6'> <model type='ivshmem-doorbell'/> <server path='/tmp/shmem6-sock'/> - <msi vectors='16'/> + <msi vectors='16' ioeventfd='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> </shmem> <shmem name='shmem7'> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml index 5602913648bc..04b463a27892 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml @@ -23,6 +23,7 @@ <memballoon model='none'/> <shmem name='shmem0'> <model type='ivshmem'/> + <size unit='M'>4</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </shmem> <shmem name='shmem1'> -- 2.10.1

On Wed, Oct 26, 2016 at 12:51:35 +0200, Martin Kletzander wrote:
We're keeping some things at default and that's not something we want to do intentionally. Let's save some sensible defaults upfront in order to avoid having problems later. The details for the defaults (of the newer implementation) can be found in qemu's commit 5400c02b90bb:
http://git.qemu.org/?p=qemu.git;a=commit;h=5400c02b90bb
Since we are merely saving the defaults it will not change the guest ABI and thanks to the fact that we're doing it in the PostParse callback it will not break the ABI stability checks.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_domain.c | 54 ++++++++++++++++++++++ tests/qemuxml2argvdata/qemuxml2argv-shmem.args | 2 +- .../qemuxml2xmlout-shmem-plain-doorbell.xml | 5 +- tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 1 + 4 files changed, 60 insertions(+), 2 deletions(-)
ACK

QEMU added support for ivshmem-plain and ivshmem-doorbell. Those are reworked varians of legacy ivshmem that are compatible from the guest POV, but not from host's POV and have sane specification and handling. Details about the newer device type can be found in qemu's commit 5400c02b90bb: http://git.qemu.org/?p=qemu.git;a=commit;h=5400c02b90bb Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_command.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_command.h | 10 +++++ tests/qemuxml2argvtest.c | 3 ++ 3 files changed, 109 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 558122b4cf7e..972cccee25de 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8443,6 +8443,50 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def, return NULL; } +char * +qemuBuildShmemDevStr(virDomainDefPtr def, + virDomainShmemDefPtr shmem, + virQEMUCapsPtr qemuCaps) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if ((shmem->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_PLAIN)) || + (shmem->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shmem model '%s' is not supported " + "by this QEMU binary"), + virDomainShmemModelTypeToString(shmem->model)); + return NULL; + } + + virBufferAsprintf(&buf, "%s", virDomainShmemModelTypeToString(shmem->model)); + virBufferAsprintf(&buf, ",id=%s", shmem->info.alias); + + if (shmem->server.enabled) + virBufferAsprintf(&buf, ",chardev=char%s", shmem->info.alias); + else + virBufferAsprintf(&buf, ",memdev=shmmem-%s", shmem->info.alias); + + if (shmem->msi.vectors) + virBufferAsprintf(&buf, ",vectors=%u", shmem->msi.vectors); + if (shmem->msi.ioeventfd) { + virBufferAsprintf(&buf, ",ioeventfd=%s", + virTristateSwitchTypeToString(shmem->msi.ioeventfd)); + } + + if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info, qemuCaps) < 0) { + virBufferFreeAndReset(&buf); + return NULL; + } + + if (virBufferCheckError(&buf) < 0) + return NULL; + + return virBufferContentAndReset(&buf); +} + static char * qemuBuildShmemBackendChrStr(virLogManagerPtr logManager, virCommandPtr cmd, @@ -8463,6 +8507,50 @@ qemuBuildShmemBackendChrStr(virLogManagerPtr logManager, return devstr; } + +virJSONValuePtr +qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem) +{ + char *mem_path = NULL; + virJSONValuePtr ret = NULL; + + if (virAsprintf(&mem_path, "/dev/shm/%s", shmem->name) < 0) + return NULL; + + virJSONValueObjectCreate(&ret, + "s:mem-path", mem_path, + "U:size", shmem->size, + NULL); + + VIR_FREE(mem_path); + return ret; +} + + +static char * +qemuBuildShmemBackendMemStr(virDomainShmemDefPtr shmem) +{ + char *ret = NULL; + char *alias = NULL; + virJSONValuePtr props = qemuBuildShmemBackendMemProps(shmem); + + if (!props) + return NULL; + + if (virAsprintf(&alias, "shmmem-%s", shmem->info.alias) < 0) + goto cleanup; + + ret = virQEMUBuildObjectCommandlineFromJSON("memory-backend-file", + alias, + props); + cleanup: + VIR_FREE(alias); + virJSONValueFree(props); + + return ret; +} + + static int qemuBuildShmemCommandLine(virLogManagerPtr logManager, virCommandPtr cmd, @@ -8505,10 +8593,15 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager, break; case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: + if (!(devstr = qemuBuildShmemBackendMemStr(shmem))) + return -1; + + virCommandAddArgList(cmd, "-object", devstr, NULL); + VIR_FREE(devstr); + + /* fall-through */ case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("%s device is not supported with this QEMU binary"), - virDomainShmemModelTypeToString(shmem->model)); + devstr = qemuBuildShmemDevStr(def, shmem, qemuCaps); break; case VIR_DOMAIN_SHMEM_MODEL_LAST: diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 2f2a6ff877e7..facc833bf886 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -186,4 +186,14 @@ bool qemuCheckCCWS390AddressSupport(const virDomainDef *def, virJSONValuePtr qemuBuildHotpluggableCPUProps(const virDomainVcpuDef *vcpu) ATTRIBUTE_NONNULL(1); +virJSONValuePtr qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem) + ATTRIBUTE_NONNULL(1); + +char *qemuBuildShmemDevStr(virDomainDefPtr def, + virDomainShmemDefPtr shmem, + virQEMUCapsPtr qemuCaps) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); + + + #endif /* __QEMU_COMMAND_H__*/ diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4126388316ea..1fa6b0fdd338 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2058,6 +2058,9 @@ mymain(void) DO_TEST("fips-enabled", QEMU_CAPS_ENABLE_FIPS); DO_TEST("shmem", QEMU_CAPS_DEVICE_IVSHMEM); + DO_TEST("shmem-plain-doorbell", QEMU_CAPS_DEVICE_IVSHMEM, + QEMU_CAPS_DEVICE_IVSHMEM_PLAIN, + QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL); DO_TEST_FAILURE("shmem", NONE); DO_TEST_FAILURE("shmem-invalid-size", QEMU_CAPS_DEVICE_IVSHMEM); -- 2.10.1

On Wed, Oct 26, 2016 at 12:51:36 +0200, Martin Kletzander wrote:
QEMU added support for ivshmem-plain and ivshmem-doorbell. Those are reworked varians of legacy ivshmem that are compatible from the guest POV, but not from host's POV and have sane specification and handling.
Details about the newer device type can be found in qemu's commit 5400c02b90bb:
http://git.qemu.org/?p=qemu.git;a=commit;h=5400c02b90bb
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_command.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_command.h | 10 +++++ tests/qemuxml2argvtest.c | 3 ++ 3 files changed, 109 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 558122b4cf7e..972cccee25de 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8443,6 +8443,50 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def, return NULL; }
+char * +qemuBuildShmemDevStr(virDomainDefPtr def, + virDomainShmemDefPtr shmem, + virQEMUCapsPtr qemuCaps) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if ((shmem->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_PLAIN)) || + (shmem->model == VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shmem model '%s' is not supported " + "by this QEMU binary"), + virDomainShmemModelTypeToString(shmem->model)); + return NULL; + } + + virBufferAsprintf(&buf, "%s", virDomainShmemModelTypeToString(shmem->model));
virBufferAdd.
+ virBufferAsprintf(&buf, ",id=%s", shmem->info.alias); + + if (shmem->server.enabled) + virBufferAsprintf(&buf, ",chardev=char%s", shmem->info.alias); + else + virBufferAsprintf(&buf, ",memdev=shmmem-%s", shmem->info.alias); + + if (shmem->msi.vectors) + virBufferAsprintf(&buf, ",vectors=%u", shmem->msi.vectors); + if (shmem->msi.ioeventfd) { + virBufferAsprintf(&buf, ",ioeventfd=%s", + virTristateSwitchTypeToString(shmem->msi.ioeventfd)); + } + + if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info, qemuCaps) < 0) { + virBufferFreeAndReset(&buf); + return NULL; + } + + if (virBufferCheckError(&buf) < 0) + return NULL; + + return virBufferContentAndReset(&buf); +} + static char * qemuBuildShmemBackendChrStr(virLogManagerPtr logManager, virCommandPtr cmd, @@ -8463,6 +8507,50 @@ qemuBuildShmemBackendChrStr(virLogManagerPtr logManager, return devstr; }
+ +virJSONValuePtr +qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem) +{ + char *mem_path = NULL; + virJSONValuePtr ret = NULL; + + if (virAsprintf(&mem_path, "/dev/shm/%s", shmem->name) < 0)
I was a bit worried that we'd encode a linuxism here, but qemu was doing the same.
+ return NULL; + + virJSONValueObjectCreate(&ret, + "s:mem-path", mem_path, + "U:size", shmem->size, + NULL); + + VIR_FREE(mem_path); + return ret; +}
ACK

This is needed in order to migrate a domain with shmem devices as that is not allowed to migrate. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_driver.c | 39 +++- src/qemu/qemu_hotplug.c | 248 ++++++++++++++++++++- src/qemu/qemu_hotplug.h | 6 + tests/qemuhotplugtest.c | 21 ++ .../qemuhotplug-ivshmem-doorbell-detach.xml | 7 + .../qemuhotplug-ivshmem-doorbell.xml | 4 + .../qemuhotplug-ivshmem-plain-detach.xml | 6 + .../qemuhotplug-ivshmem-plain.xml | 3 + ...muhotplug-base-live+ivshmem-doorbell-detach.xml | 1 + .../qemuhotplug-base-live+ivshmem-doorbell.xml | 65 ++++++ .../qemuhotplug-base-live+ivshmem-plain-detach.xml | 1 + .../qemuhotplug-base-live+ivshmem-plain.xml | 58 +++++ 12 files changed, 454 insertions(+), 5 deletions(-) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bacabd2d348f..c164c390eccf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7601,6 +7601,15 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, dev->data.memory = NULL; break; + case VIR_DOMAIN_DEVICE_SHMEM: + ret = qemuDomainAttachShmemDevice(driver, vm, + dev->data.shmem); + if (!ret) { + alias = dev->data.shmem->info.alias; + dev->data.shmem = NULL; + } + break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: @@ -7612,7 +7621,6 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: case VIR_DOMAIN_DEVICE_IOMMU: @@ -7690,6 +7698,9 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_MEMORY: ret = qemuDomainDetachMemoryDevice(driver, vm, dev->data.memory); break; + case VIR_DOMAIN_DEVICE_SHMEM: + ret = qemuDomainDetachShmemDevice(driver, vm, dev->data.shmem); + break; case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: @@ -7701,7 +7712,6 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_REDIRDEV: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: @@ -7848,6 +7858,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainControllerDefPtr controller; virDomainFSDefPtr fs; virDomainRedirdevDefPtr redirdev; + virDomainShmemDefPtr shmem; switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: @@ -7972,6 +7983,18 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, dev->data.redirdev = NULL; break; + case VIR_DOMAIN_DEVICE_SHMEM: + shmem = dev->data.shmem; + if (virDomainShmemDefFind(vmdef, shmem) >= 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("device is already in the domain configuration")); + return -1; + } + if (virDomainShmemDefInsert(vmdef, shmem) < 0) + return -1; + dev->data.shmem = NULL; + break; + case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: @@ -7981,7 +8004,6 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: @@ -8128,6 +8150,16 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainRedirdevDefFree(virDomainRedirdevDefRemove(vmdef, idx)); break; + case VIR_DOMAIN_DEVICE_SHMEM: + if ((idx = virDomainShmemDefFind(vmdef, dev->data.shmem)) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("matching shmem device was not found")); + return -1; + } + + virDomainShmemDefFree(virDomainShmemDefRemove(vmdef, idx)); + break; + case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: @@ -8138,7 +8170,6 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7a21dc67f533..10236a0bccd9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2375,6 +2375,131 @@ qemuDomainAttachHostDevice(virConnectPtr conn, return -1; } + +int +qemuDomainAttachShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr shmem) +{ + int ret = -1; + char *shmstr = NULL; + char *charAlias = NULL; + char *memAlias = NULL; + bool release_backing = false; + bool release_address = true; + virErrorPtr orig_err = NULL; + virJSONValuePtr props = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; + + switch ((virDomainShmemModel)shmem->model) { + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: + break; + + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("live attach of shmem model '%s' is not supported"), + virDomainShmemModelTypeToString(shmem->model)); + /* fall-through */ + case VIR_DOMAIN_SHMEM_MODEL_LAST: + return -1; + } + + if (qemuAssignDeviceShmemAlias(vm->def, shmem, -1) < 0) + return -1; + + if (qemuDomainPrepareShmemChardev(shmem) < 0) + return -1; + + if (VIR_REALLOC_N(vm->def->shmems, vm->def->nshmems + 1) < 0) + return -1; + + if ((shmem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE || + shmem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) && + (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &shmem->info) < 0)) + return -1; + + if (!(shmstr = qemuBuildShmemDevStr(vm->def, shmem, priv->qemuCaps))) + goto cleanup; + + if (shmem->server.enabled) { + if (virAsprintf(&charAlias, "char%s", shmem->info.alias) < 0) + goto cleanup; + } else { + if (!(props = qemuBuildShmemBackendMemProps(shmem))) + goto cleanup; + + if (virAsprintf(&memAlias, "shmmem-%s", shmem->info.alias) < 0) + goto cleanup; + } + + qemuDomainObjEnterMonitor(driver, vm); + + if (shmem->server.enabled) { + if (qemuMonitorAttachCharDev(priv->mon, charAlias, + &shmem->server.chr) < 0) + goto exit_monitor; + } else { + if (qemuMonitorAddObject(priv->mon, "memory-backend-file", + memAlias, props) < 0) { + props = NULL; + goto exit_monitor; + } + props = NULL; + } + + release_backing = true; + + if (qemuMonitorAddDevice(priv->mon, shmstr) < 0) + goto exit_monitor; + + if (qemuDomainObjExitMonitor(driver, vm) < 0) { + release_address = false; + goto cleanup; + } + + /* Doing a copy here just so the pointer doesn't get nullified + * because we need it in the audit function */ + VIR_APPEND_ELEMENT_COPY_INPLACE(vm->def->shmems, vm->def->nshmems, shmem); + + ret = 0; + release_address = false; + + audit: + virDomainAuditShmem(vm, shmem, "attach", ret == 0); + + cleanup: + if (release_address) + qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL); + + virJSONValueFree(props); + VIR_FREE(memAlias); + VIR_FREE(charAlias); + VIR_FREE(shmstr); + + return ret; + + exit_monitor: + orig_err = virSaveLastError(); + if (release_backing) { + if (shmem->server.enabled) + ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias)); + else + ignore_value(qemuMonitorDelObject(priv->mon, memAlias)); + } + + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + } + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + release_address = false; + + goto audit; +} + + static int qemuDomainChangeNetBridge(virDomainObjPtr vm, virDomainNetDefPtr olddev, @@ -3652,6 +3777,62 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, } +static int +qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr shmem) +{ + int rc; + int ret = -1; + ssize_t idx = -1; + char *charAlias = NULL; + char *memAlias = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; + virObjectEventPtr event = NULL; + + VIR_DEBUG("Removing shmem device %s from domain %p %s", + shmem->info.alias, vm, vm->def->name); + + if (shmem->server.enabled) { + if (virAsprintf(&charAlias, "char%s", shmem->info.alias) < 0) + return -1; + } else { + if (virAsprintf(&memAlias, "shmmem-%s", shmem->info.alias) < 0) + return -1; + } + + qemuDomainObjEnterMonitor(driver, vm); + + if (shmem->server.enabled) + rc = qemuMonitorDetachCharDev(priv->mon, charAlias); + else + rc = qemuMonitorDelObject(priv->mon, memAlias); + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto cleanup; + + virDomainAuditShmem(vm, shmem, "detach", rc == 0); + + if (rc < 0) + goto cleanup; + + event = virDomainEventDeviceRemovedNewFromObj(vm, shmem->info.alias); + qemuDomainEventQueue(driver, event); + + if ((idx = virDomainShmemDefFind(vm->def, shmem)) >= 0) + virDomainShmemDefRemove(vm->def, idx); + qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL); + virDomainShmemDefFree(shmem); + + ret = 0; + cleanup: + VIR_FREE(charAlias); + VIR_FREE(memAlias); + + return ret; +} + + int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -3683,6 +3864,10 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, ret = qemuDomainRemoveMemoryDevice(driver, vm, dev->data.memory); break; + case VIR_DOMAIN_DEVICE_SHMEM: + ret = qemuDomainRemoveShmemDevice(driver, vm, dev->data.shmem); + break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: @@ -3696,7 +3881,6 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: case VIR_DOMAIN_DEVICE_IOMMU: @@ -4271,6 +4455,68 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, return qemuDomainDetachThisHostDevice(driver, vm, detach); } + +int +qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr dev) +{ + int ret = -1; + ssize_t idx = -1; + virErrorPtr orig_err = NULL; + virDomainShmemDefPtr shmem = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; + + if ((idx = virDomainShmemDefFind(vm->def, dev)) < 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("device not present in domain configuration")); + return -1; + } + + shmem = vm->def->shmems[idx]; + + switch ((virDomainShmemModel)shmem->model) { + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: + break; + + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("live detach of shmem model '%s' is not supported"), + virDomainShmemModelTypeToString(shmem->model)); + /* fall-through */ + case VIR_DOMAIN_SHMEM_MODEL_LAST: + return -1; + } + + qemuDomainMarkDeviceForRemoval(vm, &shmem->info); + qemuDomainObjEnterMonitor(driver, vm); + + ret = qemuMonitorDelDevice(priv->mon, shmem->info.alias); + + if (ret < 0) + orig_err = virSaveLastError(); + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret = -1; + + if (ret == 0) { + if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) { + qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL); + ret = qemuDomainRemoveShmemDevice(driver, vm, shmem); + } + } + qemuDomainResetDeviceRemoval(vm); + + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + } + + return ret; +} + + int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index b048cf4688a4..ca54bbdf005a 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -50,6 +50,9 @@ int qemuDomainAttachHostDevice(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev); +int qemuDomainAttachShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr shmem); int qemuDomainFindGraphicsIndex(virDomainDefPtr def, virDomainGraphicsDefPtr dev); int qemuDomainAttachMemory(virQEMUDriverPtr driver, @@ -86,6 +89,9 @@ int qemuDomainDetachNetDevice(virQEMUDriverPtr driver, int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev); +int qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr dev); int qemuDomainAttachLease(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainLeaseDefPtr lease); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 43eb1cfd1fc3..a380fe60fc13 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -74,6 +74,8 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW); + virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_PLAIN); + virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL); if (event) virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT); @@ -120,6 +122,9 @@ testQemuHotplugAttach(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_CHR: ret = qemuDomainAttachChrDevice(&driver, vm, dev->data.chr); break; + case VIR_DOMAIN_DEVICE_SHMEM: + ret = qemuDomainAttachShmemDevice(&driver, vm, dev->data.shmem); + break; default: VIR_TEST_VERBOSE("device type '%s' cannot be attached\n", virDomainDeviceTypeToString(dev->type)); @@ -142,6 +147,9 @@ testQemuHotplugDetach(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_CHR: ret = qemuDomainDetachChrDevice(&driver, vm, dev->data.chr); break; + case VIR_DOMAIN_DEVICE_SHMEM: + ret = qemuDomainDetachShmemDevice(&driver, vm, dev->data.shmem); + break; default: VIR_TEST_VERBOSE("device type '%s' cannot be detached\n", virDomainDeviceTypeToString(dev->type)); @@ -561,6 +569,19 @@ mymain(void) "human-monitor-command", HMP("OK\\r\\n"), "device_add", QMP_OK); + DO_TEST_ATTACH("base-live", "ivshmem-plain", false, true, + "object-add", QMP_OK, + "device_add", QMP_OK); + DO_TEST_ATTACH("base-live", "ivshmem-doorbell", false, true, + "chardev-add", QMP_OK, + "device_add", QMP_OK); + DO_TEST_DETACH("base-live+ivshmem-plain", "ivshmem-doorbell-detach", false, true, + "device_del", QMP_OK, + "chardev-remove", QMP_OK); + DO_TEST_DETACH("base-live", "ivshmem-plain-detach", false, false, + "device_del", QMP_OK, + "object-del", QMP_OK); + qemuTestDriverFree(&driver); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml new file mode 100644 index 000000000000..7c066964d745 --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml @@ -0,0 +1,7 @@ +<shmem name='shmem1'> + <model type='ivshmem-doorbell'/> + <server path='/var/lib/libvirt/shmem-shmem1-sock'/> + <msi ioeventfd='on'/> + <alias name='shmem1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> +</shmem> diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml new file mode 100644 index 000000000000..06cb0c978605 --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml @@ -0,0 +1,4 @@ +<shmem name='shmem1'> + <model type='ivshmem-doorbell'/> + <server/> +</shmem> diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml new file mode 100644 index 000000000000..68f592fb2128 --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml @@ -0,0 +1,6 @@ +<shmem name='shmem0'> + <model type='ivshmem-plain'/> + <size unit='M'>4</size> + <alias name='shmem0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> +</shmem> diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml new file mode 100644 index 000000000000..6bd96ff16767 --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml @@ -0,0 +1,3 @@ +<shmem name='shmem0'> + <model type='ivshmem-plain'/> +</shmem> diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml new file mode 120000 index 000000000000..021e5471d197 --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml @@ -0,0 +1 @@ +qemuhotplug-base-live+ivshmem-plain.xml \ No newline at end of file diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml new file mode 100644 index 000000000000..8d09fee265fc --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml @@ -0,0 +1,65 @@ +<domain type='kvm' id='7'> + <name>hotplug</name> + <uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid> + <memory unit='KiB'>4194304</memory> + <currentMemory unit='KiB'>4194304</currentMemory> + <vcpu placement='static'>4</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <features> + <acpi/> + <apic/> + <pae/> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <emulator>/usr/libexec/qemu-kvm</emulator> + <controller type='usb' index='0'> + <alias name='usb'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <alias name='ide'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='scsi' index='0' model='virtio-scsi'> + <alias name='scsi0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </controller> + <controller type='pci' index='0' model='pci-root'> + <alias name='pci'/> + </controller> + <controller type='virtio-serial' index='0'> + <alias name='virtio-serial0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </controller> + <input type='mouse' bus='ps2'> + <alias name='input0'/> + </input> + <input type='keyboard' bus='ps2'> + <alias name='input1'/> + </input> + <memballoon model='none'> + <alias name='balloon0'/> + </memballoon> + <shmem name='shmem0'> + <model type='ivshmem-plain'/> + <size unit='M'>4</size> + <alias name='shmem0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </shmem> + <shmem name='shmem1'> + <model type='ivshmem-doorbell'/> + <server path='/var/lib/libvirt/shmem-shmem1-sock'/> + <msi ioeventfd='on'/> + <alias name='shmem1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> + </shmem> + </devices> + <seclabel type='none' model='none'/> +</domain> diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml new file mode 120000 index 000000000000..48c1b1755a4e --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml @@ -0,0 +1 @@ +qemuhotplug-base-live.xml \ No newline at end of file diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml new file mode 100644 index 000000000000..ac3fa4f42047 --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml @@ -0,0 +1,58 @@ +<domain type='kvm' id='7'> + <name>hotplug</name> + <uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid> + <memory unit='KiB'>4194304</memory> + <currentMemory unit='KiB'>4194304</currentMemory> + <vcpu placement='static'>4</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <features> + <acpi/> + <apic/> + <pae/> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <emulator>/usr/libexec/qemu-kvm</emulator> + <controller type='usb' index='0'> + <alias name='usb'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <alias name='ide'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='scsi' index='0' model='virtio-scsi'> + <alias name='scsi0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </controller> + <controller type='pci' index='0' model='pci-root'> + <alias name='pci'/> + </controller> + <controller type='virtio-serial' index='0'> + <alias name='virtio-serial0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </controller> + <input type='mouse' bus='ps2'> + <alias name='input0'/> + </input> + <input type='keyboard' bus='ps2'> + <alias name='input1'/> + </input> + <memballoon model='none'> + <alias name='balloon0'/> + </memballoon> + <shmem name='shmem0'> + <model type='ivshmem-plain'/> + <size unit='M'>4</size> + <alias name='shmem0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </shmem> + </devices> + <seclabel type='none' model='none'/> +</domain> -- 2.10.1

On Wed, Oct 26, 2016 at 12:51:37 +0200, Martin Kletzander wrote:
This is needed in order to migrate a domain with shmem devices as that is not allowed to migrate.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_driver.c | 39 +++- src/qemu/qemu_hotplug.c | 248 ++++++++++++++++++++- src/qemu/qemu_hotplug.h | 6 + tests/qemuhotplugtest.c | 21 ++ .../qemuhotplug-ivshmem-doorbell-detach.xml | 7 + .../qemuhotplug-ivshmem-doorbell.xml | 4 + .../qemuhotplug-ivshmem-plain-detach.xml | 6 + .../qemuhotplug-ivshmem-plain.xml | 3 + ...muhotplug-base-live+ivshmem-doorbell-detach.xml | 1 + .../qemuhotplug-base-live+ivshmem-doorbell.xml | 65 ++++++ .../qemuhotplug-base-live+ivshmem-plain-detach.xml | 1 + .../qemuhotplug-base-live+ivshmem-plain.xml | 58 +++++ 12 files changed, 454 insertions(+), 5 deletions(-) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bacabd2d348f..c164c390eccf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7601,6 +7601,15 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, dev->data.memory = NULL; break;
+ case VIR_DOMAIN_DEVICE_SHMEM: + ret = qemuDomainAttachShmemDevice(driver, vm, + dev->data.shmem); + if (!ret) {
Change the condition to something more orthodox, like "< 0".
+ alias = dev->data.shmem->info.alias; + dev->data.shmem = NULL; + } + break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT:
[...]
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7a21dc67f533..10236a0bccd9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c
[...]
@@ -4271,6 +4455,68 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver, return qemuDomainDetachThisHostDevice(driver, vm, detach); }
+ +int +qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainShmemDefPtr dev) +{ + int ret = -1; + ssize_t idx = -1; + virErrorPtr orig_err = NULL; + virDomainShmemDefPtr shmem = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; + + if ((idx = virDomainShmemDefFind(vm->def, dev)) < 0) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("device not present in domain configuration")); + return -1; + } + + shmem = vm->def->shmems[idx]; + + switch ((virDomainShmemModel)shmem->model) { + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: + break; + + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("live detach of shmem model '%s' is not supported"), + virDomainShmemModelTypeToString(shmem->model)); + /* fall-through */ + case VIR_DOMAIN_SHMEM_MODEL_LAST: + return -1; + } + + qemuDomainMarkDeviceForRemoval(vm, &shmem->info); + qemuDomainObjEnterMonitor(driver, vm); + + ret = qemuMonitorDelDevice(priv->mon, shmem->info.alias); + + if (ret < 0) + orig_err = virSaveLastError();
Is this necessary? The only place where it would be overwritten is ...
+ + if (qemuDomainObjExitMonitor(driver, vm) < 0)
... here and only if qemu crashes at this point.
+ ret = -1; + + if (ret == 0) { + if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) { + qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL); + ret = qemuDomainRemoveShmemDevice(driver, vm, shmem); + } + } + qemuDomainResetDeviceRemoval(vm); + + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + }
ACK

On Wed, 2016-10-26 at 12:51 +0200, Martin Kletzander wrote:
v4: - Incorporated John's review v3: - https://www.redhat.com/archives/libvir-list/2016-September/msg01232.html Martin Kletzander (6): conf, qemu: Add support for shmem model conf, qemu: Add newer shmem models qemu: Add capabilities for ivshmem-{plain,doorbell} qemu: Save various defaults for shmem qemu: Support newer ivshmem device variants qemu: Add support for hot/cold-(un)plug of shmem devices
This looks like a user-visible improvement that would deserve of being highlighted in the NEWS file. Care to propose such an entry? :) </polite-nagging> -- Andrea Bolognani / Red Hat / Virtualization
participants (3)
-
Andrea Bolognani
-
Martin Kletzander
-
Peter Krempa