In order for memory locking to work, the hard limit on memory
locking (and usage) has to be set appropriately by the user.
The documentation mentions the requirement already: with this
patch, it's going to be enforced by runtime checks as well.
Note that this will make existing guests that don't satisfy
the requirement disappear; that said, such guests have never
been able to start in the first place.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1316774
---
src/qemu/qemu_domain.c | 20 ++++++++++++++++++++
tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml | 3 +++
....xml => qemuxml2argv-mlock-without-hardlimit.xml} | 0
tests/qemuxml2argvtest.c | 1 +
4 files changed, 24 insertions(+)
copy tests/qemuxml2argvdata/{qemuxml2argv-mlock-on.xml =>
qemuxml2argv-mlock-without-hardlimit.xml} (100%)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c6ce090..bb29cfe 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2629,6 +2629,23 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def)
static int
+qemuDomainDefMemoryLockingPostParse(virDomainDefPtr def)
+{
+ /* Memory locking can only work properly if the memory locking limit
+ * for the QEMU process has been raised appropriately: the default one
+ * is extrememly low, so there's no way the guest will fit in there */
+ if (def->mem.locked && !virMemoryLimitIsSet(def->mem.hard_limit)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Setting <memoryBacking><locked> requires
"
+ "<memtune><hard_limit> to be set as
well"));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int
qemuDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps,
unsigned int parseFlags,
@@ -2692,6 +2709,9 @@ qemuDomainDefPostParse(virDomainDefPtr def,
if (qemuDomainDefVcpusPostParse(def) < 0)
goto cleanup;
+ if (qemuDomainDefMemoryLockingPostParse(def) < 0)
+ goto cleanup;
+
ret = 0;
cleanup:
virObjectUnref(qemuCaps);
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
b/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
index 20a5eaa..2046663 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
@@ -3,6 +3,9 @@
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
+ <memtune>
+ <hard_limit unit='KiB'>256000</hard_limit>
+ </memtune>
<memoryBacking>
<locked/>
</memoryBacking>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
b/tests/qemuxml2argvdata/qemuxml2argv-mlock-without-hardlimit.xml
similarity index 100%
copy from tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
copy to tests/qemuxml2argvdata/qemuxml2argv-mlock-without-hardlimit.xml
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3532cb5..9b2fec5 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2129,6 +2129,7 @@ mymain(void)
DO_TEST_FAILURE("mlock-on", NONE);
DO_TEST("mlock-off", QEMU_CAPS_REALTIME_MLOCK);
DO_TEST("mlock-unsupported", NONE);
+ DO_TEST_PARSE_ERROR("mlock-without-hardlimit", NONE);
DO_TEST_PARSE_ERROR("pci-bridge-negative-index-invalid",
QEMU_CAPS_DEVICE_PCI_BRIDGE);
--
2.7.4