Just the default one now, new ones will be added in following commits.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
docs/schemas/domaincommon.rng | 9 +++++
src/conf/domain_conf.c | 41 +++++++++++++++++------
src/conf/domain_conf.h | 8 +++++
src/libvirt_private.syms | 2 ++
src/qemu/qemu_command.c | 14 ++++++--
tests/qemuxml2argvdata/qemuxml2argv-shmem.xml | 2 ++
tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml | 8 +++++
7 files changed, 70 insertions(+), 14 deletions(-)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 751d9141deea..3fb4f3999a01 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3586,6 +3586,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 b4a3e92dd78a..97cb3de95529 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -843,6 +843,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);
@@ -12198,6 +12201,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"));
@@ -18687,6 +18704,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
"
@@ -21764,20 +21790,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 c14a39c439a6..5556b6d535f0 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1554,9 +1554,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;
@@ -3044,6 +3051,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 80d5e86d0e34..409e0c0018e6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -454,6 +454,8 @@ virDomainSaveStatus;
virDomainSaveXML;
virDomainSeclabelTypeFromString;
virDomainSeclabelTypeToString;
+virDomainShmemModelTypeFromString;
+virDomainShmemModelTypeToString;
virDomainShutdownReasonTypeFromString;
virDomainShutdownReasonTypeToString;
virDomainShutoffReasonTypeFromString;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3a61863b9abb..5eae0631a14f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8648,10 +8648,18 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
{
char *devstr = NULL;
- if (!(devstr = qemuBuildShmemDevStr(def, shmem, qemuCaps)))
+ switch ((virDomainShmemModel)shmem->model) {
+ case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM:
+ if (!(devstr = qemuBuildShmemDevStr(def, shmem, qemuCaps)))
+ return -1;
+ virCommandAddArgList(cmd, "-device", devstr, NULL);
+ VIR_FREE(devstr);
+ break;
+
+ /* coverity[dead_error_begin] */
+ case VIR_DOMAIN_SHMEM_MODEL_LAST:
return -1;
- virCommandAddArgList(cmd, "-device", devstr, NULL);
- VIR_FREE(devstr);
+ }
if (shmem->server.enabled) {
if (!(devstr = qemuBuildShmemBackendStr(logManager, cmd, cfg, def,
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.0