qemu: Add qemuDomainAdjustMaxMemLock()

This function detects whether a domain needs RLIMIT_MEMLOCK
to be set, and if so, uses an appropriate value.
This commit is contained in:
Andrea Bolognani 2015-12-10 18:39:14 +01:00
parent bbefc9cc2e
commit ac7e4df4f4
2 changed files with 31 additions and 0 deletions

View 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:

View 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,