render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 0f6a07209863beec18fb907b293531bd6c61f5d5 Mon Sep 17 00:00:00 2001
Message-Id: <0f6a07209863beec18fb907b293531bd6c61f5d5@dist-git>
From: Martin Kletzander <mkletzan@redhat.com>
Date: Fri, 4 Nov 2016 10:29:52 +0100
Subject: [PATCH] qemu: Save various defaults for shmem

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>
(cherry picked from commit acf0ec024a220364c4a6a94996c82875c6d1ba13)

https://bugzilla.redhat.com/show_bug.cgi?id=1392031

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 4f99c14..3d2650f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2544,6 +2544,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 ATTRIBUTE_UNUSED,
@@ -2708,6 +2758,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 99fac11..bdf660a 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 ab9c69b..7872e1c 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 5602913..04b463a 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.2