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 <neilb@suse.de>
This commit is contained in:
NeilBrown 2013-05-30 14:31:09 +10:00
parent 041b815f17
commit a7dec3fd92
5 changed files with 20 additions and 1 deletions

View File

@ -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) {

View File

@ -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 */

2
Grow.c
View File

@ -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;

View File

@ -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);

15
util.c
View File

@ -28,6 +28,7 @@
#include <sys/utsname.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/resource.h>
#include <ctype.h>
#include <dirent.h>
#include <signal.h>
@ -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);
}