[PATCH v2 3/7] qemu: Add qemuDomainAdjustMaxMemLock()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function detects whether a domain needs RLIMIT_MEMLOCK
to be set, and if so, uses an appropriate value.
---
 src/qemu/qemu_domain.c | 30 ++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 6f19d49..4b796ab 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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:
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 916d5d3..704351b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -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,
-- 
2.5.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]