1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: Only raise memlock limit if necessary

Attempting to set the memlock limit might fail if we're running
in a containerized environment where CAP_SYS_RESOURCE is not
available, and if the limit is already high enough there's no
point in trying to raise it anyway.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2021-03-09 11:40:21 +01:00
parent b4967d7498
commit af41380672

View File

@ -9351,12 +9351,21 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm,
return -1; return -1;
if (desiredMemLock > 0) { if (desiredMemLock > 0) {
if (currentMemLock < desiredMemLock) {
/* If this is the first time adjusting the limit, save the current /* If this is the first time adjusting the limit, save the current
* value so that we can restore it once memory locking is no longer * value so that we can restore it once memory locking is no longer
* required */ * required */
if (vm->originalMemlock == 0) { if (vm->originalMemlock == 0) {
vm->originalMemlock = currentMemLock; vm->originalMemlock = currentMemLock;
} }
} else {
/* If the limit is already high enough, we can assume
* that some external process is taking care of managing
* process limits and we shouldn't do anything ourselves:
* we're probably running in a containerized environment
* where we don't have enough privilege anyway */
desiredMemLock = 0;
}
} else { } else {
/* Once memory locking is no longer required, we can restore the /* Once memory locking is no longer required, we can restore the
* original, usually very low, limit */ * original, usually very low, limit */