From a7dec3fd92e9b77b0bc7bb8e8e0b4c878baef45a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 30 May 2013 14:31:09 +1000 Subject: [PATCH] Make sure NOFILE resource limit is big enough. Some people want to create truely enormous arrays. As we sometimes need to hold one file descriptor for each device, this can hit the NOFILE limit. So raise the limit if it ever looks like it might be a problem. Signed-off-by: NeilBrown --- Assemble.c | 1 + Create.c | 2 +- Grow.c | 2 ++ mdadm.h | 1 + util.c | 15 +++++++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Assemble.c b/Assemble.c index 7e8cdb4d..b45abc2f 100644 --- a/Assemble.c +++ b/Assemble.c @@ -1618,6 +1618,7 @@ try_again: pr_err(":%s has an active reshape - checking " "if critical section needs to be restored\n", chosen_name); + enable_fds(bestcnt/2); for (i = 0; i < bestcnt/2; i++) { int j = best[i*2]; if (j >= 0) { diff --git a/Create.c b/Create.c index fe1d4e97..ac22f77c 100644 --- a/Create.c +++ b/Create.c @@ -832,7 +832,7 @@ int Create(struct supertype *st, char *mddev, } infos = xmalloc(sizeof(*infos) * total_slots); - + enable_fds(total_slots); for (pass=1; pass <=2 ; pass++) { struct mddev_dev *moved_disk = NULL; /* the disk that was moved out of the insert point */ diff --git a/Grow.c b/Grow.c index a3c8083c..defcb750 100644 --- a/Grow.c +++ b/Grow.c @@ -52,6 +52,7 @@ int restore_backup(struct supertype *st, dprintf("Called restore_backup()\n"); fdlist = xmalloc(sizeof(int) * disk_count); + enable_fds(next_spare); for (i = 0; i < next_spare; i++) fdlist[i] = -1; for (dev = content->devs; dev; dev = dev->next) { @@ -838,6 +839,7 @@ int reshape_prepare_fdlist(char *devname, int d = 0; struct mdinfo *sd; + enable_fds(nrdisks); for (d = 0; d <= nrdisks; d++) fdlist[d] = -1; d = raid_disks; diff --git a/mdadm.h b/mdadm.h index b7af65dc..e0837acb 100644 --- a/mdadm.h +++ b/mdadm.h @@ -1220,6 +1220,7 @@ extern int open_dev_excl(char *devnm); extern int is_standard(char *dev, int *nump); extern int same_dev(char *one, char *two); extern int compare_paths (char* path1,char* path2); +extern void enable_fds(int devices); extern int parse_auto(char *str, char *msg, int config); extern struct mddev_ident *conf_get_ident(char *dev); diff --git a/util.c b/util.c index c18105fe..3ac63e3a 100644 --- a/util.c +++ b/util.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1959,3 +1960,17 @@ int compare_paths (char* path1, char* path2) return 0; return 1; } + +/* Make sure we can open as many devices as needed */ +void enable_fds(int devices) +{ + unsigned int fds = 20 + devices; + struct rlimit lim; + if (getrlimit(RLIMIT_NOFILE, &lim) != 0 + || lim.rlim_cur >= fds) + return; + if (lim.rlim_max < fds) + lim.rlim_max = fds; + lim.rlim_cur = fds; + setrlimit(RLIMIT_NOFILE, &lim); +} -- 2.39.2