mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
process: Add virProcessGetMaxMemLock()
This function can be used to retrieve the current locked memory limit for a process, so that the setting can be later restored. Add a configure check for getrlimit(), which we now use.
This commit is contained in:
+1
-1
@@ -283,7 +283,7 @@ AC_CHECK_SIZEOF([long])
|
|||||||
dnl Availability of various common functions (non-fatal if missing),
|
dnl Availability of various common functions (non-fatal if missing),
|
||||||
dnl and various less common threadsafe functions
|
dnl and various less common threadsafe functions
|
||||||
AC_CHECK_FUNCS_ONCE([cfmakeraw fallocate geteuid getgid getgrnam_r \
|
AC_CHECK_FUNCS_ONCE([cfmakeraw fallocate geteuid getgid getgrnam_r \
|
||||||
getmntent_r getpwuid_r getuid kill mmap newlocale posix_fallocate \
|
getmntent_r getpwuid_r getrlimit getuid kill mmap newlocale posix_fallocate \
|
||||||
posix_memalign prlimit regexec sched_getaffinity setgroups setns \
|
posix_memalign prlimit regexec sched_getaffinity setgroups setns \
|
||||||
setrlimit symlink sysctlbyname getifaddrs sched_setscheduler])
|
setrlimit symlink sysctlbyname getifaddrs sched_setscheduler])
|
||||||
|
|
||||||
|
|||||||
@@ -2040,6 +2040,7 @@ virPortAllocatorSetUsed;
|
|||||||
virProcessAbort;
|
virProcessAbort;
|
||||||
virProcessExitWithStatus;
|
virProcessExitWithStatus;
|
||||||
virProcessGetAffinity;
|
virProcessGetAffinity;
|
||||||
|
virProcessGetMaxMemLock;
|
||||||
virProcessGetNamespaces;
|
virProcessGetNamespaces;
|
||||||
virProcessGetPids;
|
virProcessGetPids;
|
||||||
virProcessGetStartTime;
|
virProcessGetStartTime;
|
||||||
|
|||||||
@@ -788,6 +788,51 @@ virProcessSetMaxMemLock(pid_t pid ATTRIBUTE_UNUSED, unsigned long long bytes)
|
|||||||
}
|
}
|
||||||
#endif /* ! (HAVE_SETRLIMIT && defined(RLIMIT_MEMLOCK)) */
|
#endif /* ! (HAVE_SETRLIMIT && defined(RLIMIT_MEMLOCK)) */
|
||||||
|
|
||||||
|
#if HAVE_GETRLIMIT && defined(RLIMIT_MEMLOCK)
|
||||||
|
int
|
||||||
|
virProcessGetMaxMemLock(pid_t pid,
|
||||||
|
unsigned long long *bytes)
|
||||||
|
{
|
||||||
|
struct rlimit rlim;
|
||||||
|
|
||||||
|
if (!bytes)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
if (getrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
|
"%s",
|
||||||
|
_("cannot get locked memory limit"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (virProcessPrLimit(pid, RLIMIT_MEMLOCK, NULL, &rlim) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
|
_("cannot get locked memory limit "
|
||||||
|
"of process %lld"),
|
||||||
|
(long long int) pid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* virProcessSetMaxMemLock() sets both rlim_cur and rlim_max to the
|
||||||
|
* same value, so we can retrieve just rlim_max here */
|
||||||
|
*bytes = rlim.rlim_max;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else /* ! (HAVE_GETRLIMIT && defined(RLIMIT_MEMLOCK)) */
|
||||||
|
int
|
||||||
|
virProcessGetMaxMemLock(pid_t pid ATTRIBUTE_UNUSED,
|
||||||
|
unsigned long long *bytes)
|
||||||
|
{
|
||||||
|
if (!bytes)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
virReportSystemError(ENOSYS, "%s", _("Not supported on this platform"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif /* ! (HAVE_GETRLIMIT && defined(RLIMIT_MEMLOCK)) */
|
||||||
|
|
||||||
#if HAVE_SETRLIMIT && defined(RLIMIT_NPROC)
|
#if HAVE_SETRLIMIT && defined(RLIMIT_NPROC)
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes);
|
|||||||
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
|
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
|
||||||
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
|
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
|
||||||
|
|
||||||
|
int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes);
|
||||||
|
|
||||||
/* Callback to run code within the mount namespace tied to the given
|
/* Callback to run code within the mount namespace tied to the given
|
||||||
* pid. This function must use only async-signal-safe functions, as
|
* pid. This function must use only async-signal-safe functions, as
|
||||||
* it gets run after a fork of a multi-threaded process. The return
|
* it gets run after a fork of a multi-threaded process. The return
|
||||||
|
|||||||
Reference in New Issue
Block a user