mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 09:43:56 -06:00
virtiofsd: add --rlimit-nofile=NUM option
Make it possible to specify the RLIMIT_NOFILE on the command-line. Users running multiple virtiofsd processes should allocate a certain number to each process so that the system-wide limit can never be exhausted. When this option is set to 0 the rlimit is left at its current value. This is useful when a management tool wants to configure the rlimit itself. The default behavior remains unchanged: try to set the limit to 1,000,000 file descriptors if the current rlimit is lower. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20200501140644.220940-2-stefanha@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
parent
1c47613588
commit
6dbb716877
3 changed files with 32 additions and 14 deletions
|
@ -2707,24 +2707,18 @@ static void setup_sandbox(struct lo_data *lo, struct fuse_session *se,
|
|||
setup_seccomp(enable_syslog);
|
||||
}
|
||||
|
||||
/* Raise the maximum number of open file descriptors */
|
||||
static void setup_nofile_rlimit(void)
|
||||
/* Set the maximum number of open file descriptors */
|
||||
static void setup_nofile_rlimit(unsigned long rlimit_nofile)
|
||||
{
|
||||
const rlim_t max_fds = 1000000;
|
||||
struct rlimit rlim;
|
||||
struct rlimit rlim = {
|
||||
.rlim_cur = rlimit_nofile,
|
||||
.rlim_max = rlimit_nofile,
|
||||
};
|
||||
|
||||
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
|
||||
fuse_log(FUSE_LOG_ERR, "getrlimit(RLIMIT_NOFILE): %m\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (rlim.rlim_cur >= max_fds) {
|
||||
if (rlimit_nofile == 0) {
|
||||
return; /* nothing to do */
|
||||
}
|
||||
|
||||
rlim.rlim_cur = max_fds;
|
||||
rlim.rlim_max = max_fds;
|
||||
|
||||
if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
|
||||
/* Ignore SELinux denials */
|
||||
if (errno == EPERM) {
|
||||
|
@ -2977,7 +2971,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
fuse_daemonize(opts.foreground);
|
||||
|
||||
setup_nofile_rlimit();
|
||||
setup_nofile_rlimit(opts.rlimit_nofile);
|
||||
|
||||
/* Must be before sandbox since it wants /proc */
|
||||
setup_capng();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue