]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Make sure NOFILE resource limit is big enough.
authorNeilBrown <neilb@suse.de>
Thu, 30 May 2013 04:31:09 +0000 (14:31 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 30 May 2013 04:31:09 +0000 (14:31 +1000)
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>
Assemble.c
Create.c
Grow.c
mdadm.h
util.c

index 7e8cdb4de8ee75a16cfedb2a7b06dded4159ba13..b45abc2f408d4ad27ff4f7d55a03af8b51470d62 100644 (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) {
index fe1d4e971b4b353cda69f15a68d9322a5c857e91..ac22f77c92d3e5205bcb7773b8958ae6d88eb3a4 100644 (file)
--- 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 a3c8083c60d158549164d585688631448f6d5c9c..defcb75098ee287f2ce69a5b268b093fa8338992 100644 (file)
--- 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 b7af65dcb74556b6c5dba1a07a6dcbf312f3d292..e0837acb6234310416b707ca8f3cb16baec5baa8 100644 (file)
--- 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 c18105fe7822aa57388d40d2228ea97e32c5d29c..3ac63e3a7ff2ae27d1d3c88a13631b92481dc5cf 100644 (file)
--- a/util.c
+++ b/util.c
@@ -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);
+}