#include "blacklist.h"
#include "defaults.h"
#include "prio.h"
+#include "errno.h"
/*
* default block handlers
}
static int
+get_sys_max_fds(int *max_fds)
+{
+ FILE *file;
+ int nr_open;
+ int ret = 1;
+
+ file = fopen("/proc/sys/fs/nr_open", "r");
+ if (!file) {
+ fprintf(stderr, "Cannot open /proc/sys/fs/nr_open : %s\n",
+ strerror(errno));
+ return 1;
+ }
+ if (fscanf(file, "%d", &nr_open) != 1) {
+ fprintf(stderr, "Cannot read max open fds from /proc/sys/fs/nr_open");
+ if (ferror(file))
+ fprintf(stderr, " : %s\n", strerror(errno));
+ else
+ fprintf(stderr, "\n");
+ } else {
+ *max_fds = nr_open;
+ ret = 0;
+ }
+ fclose(file);
+ return ret;
+}
+
+
+static int
max_fds_handler(vector strvec)
{
char * buff;
+ int r = 0;
buff = set_value(strvec);
if (!buff)
return 1;
- if (strlen(buff) == 9 &&
- !strcmp(buff, "unlimited"))
- conf->max_fds = MAX_FDS_UNLIMITED;
+ if (strlen(buff) == 3 &&
+ !strcmp(buff, "max"))
+ r = get_sys_max_fds(&conf->max_fds);
else
conf->max_fds = atoi(buff);
FREE(buff);
- return 0;
+ return r;
}
static int
if (!conf->max_fds)
return 0;
- if (conf->max_fds < 0)
- return snprintf(buff, len, "unlimited");
return snprintf(buff, len, "%d", conf->max_fds);
}
#define NO_PATH_RETRY_FAIL -1
#define NO_PATH_RETRY_QUEUE -2
-#define MAX_FDS_UNLIMITED -1
enum free_path_switch {
KEEP_PATHS,
# # scope : multipathd
# # desc : Sets the maximum number of open file descriptors for the
# # multipathd process.
-# # values : unlimited|n > 0
+# # values : max|n > 0
# # default : None
# #
# max_fds 8192
if (conf->max_fds) {
struct rlimit fd_limit;
- if (conf->max_fds > 0) {
- fd_limit.rlim_cur = conf->max_fds;
- fd_limit.rlim_max = conf->max_fds;
- }
- else {
- fd_limit.rlim_cur = RLIM_INFINITY;
- fd_limit.rlim_max = RLIM_INFINITY;
- }
+
+ fd_limit.rlim_cur = conf->max_fds;
+ fd_limit.rlim_max = conf->max_fds;
if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0)
condlog(0, "can't set open fds limit to %d : %s\n",
conf->max_fds, strerror(errno));
be overriden by any specific aliases in the \fImultipaths\fR section.
Default is
.I no
+.TP
+.B max_fds
+Specify the maximum number of file descriptors that can be opened by multipath
+and multipathd. This is equivalent to ulimit -n. A value of \fImax\fR will set
+this to the system limit from /proc/sys/fs/nr_open. If this is not set, the
+maximum number of open fds is taken from the calling process. It is usually
+1024. To be safe, this should be set to the maximum number of paths plus 32,
+if that number is greated than 1024.
.
.SH "blacklist section"
The
if (conf->max_fds) {
struct rlimit fd_limit;
- if (conf->max_fds > 0) {
- fd_limit.rlim_cur = conf->max_fds;
- fd_limit.rlim_max = conf->max_fds;
- }
- else {
- fd_limit.rlim_cur = RLIM_INFINITY;
- fd_limit.rlim_max = RLIM_INFINITY;
- }
+
+ fd_limit.rlim_cur = conf->max_fds;
+ fd_limit.rlim_max = conf->max_fds;
if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0)
condlog(0, "can't set open fds limit to %d : %s\n",
conf->max_fds, strerror(errno));