[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 056/108] virtiofsd: set maximum RLIMIT_NOFILE limit
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PULL 056/108] virtiofsd: set maximum RLIMIT_NOFILE limit |
Date: |
Thu, 23 Jan 2020 16:45:38 +0000 |
From: Stefan Hajnoczi <address@hidden>
virtiofsd can exceed the default open file descriptor limit easily on
most systems. Take advantage of the fact that it runs as root to raise
the limit.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Daniel P. Berrangé <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
tools/virtiofsd/passthrough_ll.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index d53cb1e005..c281d817af 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -53,6 +53,7 @@
#include <sys/file.h>
#include <sys/mount.h>
#include <sys/prctl.h>
+#include <sys/resource.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -2268,6 +2269,35 @@ static void setup_sandbox(struct lo_data *lo, struct
fuse_session *se)
setup_seccomp();
}
+/* Raise the maximum number of open file descriptors */
+static void setup_nofile_rlimit(void)
+{
+ const rlim_t max_fds = 1000000;
+ struct rlimit rlim;
+
+ if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ fuse_log(FUSE_LOG_ERR, "getrlimit(RLIMIT_NOFILE): %m\n");
+ exit(1);
+ }
+
+ if (rlim.rlim_cur >= max_fds) {
+ 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) {
+ return;
+ }
+
+ fuse_log(FUSE_LOG_ERR, "setrlimit(RLIMIT_NOFILE): %m\n");
+ exit(1);
+ }
+}
+
int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -2389,6 +2419,8 @@ int main(int argc, char *argv[])
fuse_daemonize(opts.foreground);
+ setup_nofile_rlimit();
+
/* Must be before sandbox since it wants /proc */
setup_capng();
--
2.24.1
- [PULL 042/108] virtiofsd: Pass write iov's all the way through, (continued)
- [PULL 042/108] virtiofsd: Pass write iov's all the way through, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 047/108] virtiofsd: prevent ".." escape in lo_do_readdir(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 048/108] virtiofsd: use /proc/self/fd/ O_PATH file descriptor, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 049/108] virtiofsd: sandbox mount namespace, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 045/108] virtiofsd: check input buffer size in fuse_lowlevel.c ops, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 050/108] virtiofsd: move to an empty network namespace, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 051/108] virtiofsd: move to a new pid namespace, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 053/108] virtiofsd: Parse flag FUSE_WRITE_KILL_PRIV, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 052/108] virtiofsd: add seccomp whitelist, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 054/108] virtiofsd: cap-ng helpers, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 056/108] virtiofsd: set maximum RLIMIT_NOFILE limit,
Dr. David Alan Gilbert (git) <=
- [PULL 057/108] virtiofsd: fix libfuse information leaks, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 055/108] virtiofsd: Drop CAP_FSETID if client asked for it, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 058/108] virtiofsd: add --syslog command-line option, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 059/108] virtiofsd: print log only when priority is high enough, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 063/108] virtiofsd: Handle hard reboot, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 064/108] virtiofsd: Kill threads when queues are stopped, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 060/108] virtiofsd: Add ID to the log with FUSE_LOG_DEBUG level, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 067/108] virtiofsd: passthrough_ll: add renameat2 support, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 061/108] virtiofsd: Add timestamp to the log with FUSE_LOG_DEBUG level, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 062/108] virtiofsd: Handle reinit, Dr. David Alan Gilbert (git), 2020/01/23