]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Add qemuDomainAdjustMaxMemLock()
authorAndrea Bolognani <abologna@redhat.com>
Thu, 10 Dec 2015 17:39:14 +0000 (18:39 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Thu, 17 Dec 2015 09:12:47 +0000 (10:12 +0100)
This function detects whether a domain needs RLIMIT_MEMLOCK
to be set, and if so, uses an appropriate value.

src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index 6f19d49f4f09317abdf51f39fcd460f325a7a93b..4b796ab60eadc46f5fd747ede7d7d20db57d833a 100644 (file)
@@ -41,6 +41,7 @@
 #include "virstring.h"
 #include "virthreadjob.h"
 #include "viratomic.h"
+#include "virprocess.h"
 #include "logging/log_manager.h"
 
 #include "storage/storage_driver.h"
@@ -4117,6 +4118,35 @@ qemuDomainRequiresMlock(virDomainDefPtr def)
     return false;
 }
 
+/**
+ * qemuDomainAdjustMaxMemLock:
+ * @vm: domain
+ *
+ * Adjust the memory locking limit for the QEMU process associated to @vm, in
+ * order to comply with VFIO or architecture requirements.
+ *
+ * The limit will not be changed unless doing so is needed.
+ *
+ * Returns: 0 on success, <0 on failure
+ */
+int
+qemuDomainAdjustMaxMemLock(virDomainObjPtr vm)
+{
+    unsigned long long bytes = 0;
+    int ret = -1;
+
+    if (qemuDomainRequiresMlock(vm->def))
+        bytes = qemuDomainGetMlockLimitBytes(vm->def);
+
+    /* Trying to set the memory locking limit to zero is a no-op */
+    if (virProcessSetMaxMemLock(vm->pid, bytes) < 0)
+        goto out;
+
+    ret = 0;
+
+ out:
+     return ret;
+}
 
 /**
  * qemuDomainHasVcpuPids:
index 916d5d3ff5e7cfaa09a1dc8bfed7a15260318e77..704351b956f0ff623cb262ad1973d6df6e00ec49 100644 (file)
@@ -500,6 +500,7 @@ int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
 
 unsigned long long qemuDomainGetMlockLimitBytes(virDomainDefPtr def);
 bool qemuDomainRequiresMlock(virDomainDefPtr def);
+int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
 
 int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                        virQEMUCapsPtr qemuCaps,