Role controls how the domain behaves on migration. Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> --- docs/formatdomain.html.in | 10 +++++- docs/schemas/domaincommon.rng | 8 +++++ src/conf/domain_conf.c | 39 ++++++++++++++++++++++- src/conf/domain_conf.h | 11 +++++++ tests/qemuxml2argvdata/qemuxml2argv-shmem.xml | 4 +-- tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 4 +-- 6 files changed, 70 insertions(+), 6 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f48a4d8b813f..f4d08959c787 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -6747,7 +6747,7 @@ qemu-kvm -net nic,model=? /dev/null <pre> ... <devices> - <shmem name='my_shmem0'> + <shmem name='my_shmem0' role='peer'> <size unit='M'>4</size> </shmem> <shmem name='shmem_server'> @@ -6764,6 +6764,14 @@ qemu-kvm -net nic,model=? /dev/null <dd> The <code>shmem</code> element has one mandatory attribute, <code>name</code> to identify the shared memory. + Optional attribute <code>role</code> can be set to values + "master" or "peer". The former will mean that upon migration, + the data in the shared memory is migrated with the domain. + There should be only one "master" per shared memory object. + Migration with "peer" role is disabled. If migration of such + domain is required, the shmem device needs to be unplugged + before migration and plugged in at the destination upon + successful migration. </dd> <dt><code>size</code></dt> <dd> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 3fb4f3999a01..fd7d52d72515 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3584,6 +3584,14 @@ <define name="shmem"> <element name="shmem"> <attribute name="name"/> + <optional> + <attribute name="role"> + <choice> + <value>master</value> + <value>peer</value> + </choice> + </attribute> + </optional> <interleave> <optional> <element name="model"> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 97cb3de95529..2ccc10515f30 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -846,6 +846,11 @@ VIR_ENUM_IMPL(virDomainMemoryModel, VIR_DOMAIN_MEMORY_MODEL_LAST, VIR_ENUM_IMPL(virDomainShmemModel, VIR_DOMAIN_SHMEM_MODEL_LAST, "ivshmem") +VIR_ENUM_IMPL(virDomainShmemRole, VIR_DOMAIN_SHMEM_ROLE_LAST, + "default", + "master", + "peer") + static virClassPtr virDomainObjClass; static virClassPtr virDomainXMLOptionClass; static void virDomainObjDispose(void *obj); @@ -12201,6 +12206,23 @@ virDomainShmemDefParseXML(xmlNodePtr node, ctxt->node = node; + if (!(def->name = virXMLPropString(node, "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("shmem element must contain 'name' attribute")); + goto cleanup; + } + + tmp = virXMLPropString(node, "role"); + if (tmp) { + if ((def->role = virDomainShmemRoleTypeFromString(tmp)) <= 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Unknown shmem role type '%s'"), tmp); + goto cleanup; + } + + VIR_FREE(tmp); + } + tmp = virXPathString("string(./model/@type)", ctxt); if (tmp) { /* If there's none, we will automatically have the first one @@ -18704,6 +18726,15 @@ virDomainShmemDefCheckABIStability(virDomainShmemDefPtr src, return false; } + if (src->role != dst->role) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target shared memory role '%s' does not match " + "source role '%s'"), + virDomainShmemRoleTypeToString(dst->role), + virDomainShmemRoleTypeToString(src->role)); + return false; + } + if (src->model != dst->model) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target shared memory model '%s' does not match " @@ -21790,8 +21821,14 @@ virDomainShmemDefFormat(virBufferPtr buf, virDomainShmemDefPtr def, unsigned int flags) { - virBufferEscapeString(buf, "<shmem name='%s'>\n", def->name); + virBufferEscapeString(buf, "<shmem name='%s'", def->name); + if (def->role) { + virBufferEscapeString(buf, " role='%s'", + virDomainShmemRoleTypeToString(def->role)); + } + + virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "<model type='%s'/>\n", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5556b6d535f0..bd674a565373 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1560,10 +1560,20 @@ typedef enum { VIR_DOMAIN_SHMEM_MODEL_LAST } virDomainShmemModel; +typedef enum { + VIR_DOMAIN_SHMEM_ROLE_DEFAULT, + + VIR_DOMAIN_SHMEM_ROLE_MASTER, + VIR_DOMAIN_SHMEM_ROLE_PEER, + + VIR_DOMAIN_SHMEM_ROLE_LAST +} virDomainShmemRole; + struct _virDomainShmemDef { char *name; unsigned long long size; int model; /* enum virDomainShmemModel */ + int role; /* enum virDomainShmemRole */ struct { bool enabled; virDomainChrSourceDef chr; @@ -3052,6 +3062,7 @@ VIR_ENUM_DECL(virDomainMemoryModel) VIR_ENUM_DECL(virDomainMemoryBackingModel) VIR_ENUM_DECL(virDomainIOMMUModel) VIR_ENUM_DECL(virDomainShmemModel) +VIR_ENUM_DECL(virDomainShmemRole) /* from libvirt.h */ VIR_ENUM_DECL(virDomainState) VIR_ENUM_DECL(virDomainNostateReason) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml b/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml index b56e9e187895..977947eb3355 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml @@ -20,10 +20,10 @@ <input type='keyboard' bus='ps2'/> <memballoon model='none'/> <shmem name='shmem0'/> - <shmem name='shmem1'> + <shmem name='shmem1' role='peer'> <size unit='M'>128</size> </shmem> - <shmem name='shmem2'> + <shmem name='shmem2' role='master'> <size unit='M'>256</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </shmem> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml index 5602913648bc..0a1579155170 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml @@ -25,12 +25,12 @@ <model type='ivshmem'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </shmem> - <shmem name='shmem1'> + <shmem name='shmem1' role='peer'> <model type='ivshmem'/> <size unit='M'>128</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </shmem> - <shmem name='shmem2'> + <shmem name='shmem2' role='master'> <model type='ivshmem'/> <size unit='M'>256</size> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> -- 2.10.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list