]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
conditionally remove map_dev from find_free_devnum
authorNeilBrown <neilb@suse.de>
Sun, 6 Jan 2013 23:17:04 +0000 (10:17 +1100)
committerNeilBrown <neilb@suse.de>
Sun, 6 Jan 2013 23:17:04 +0000 (10:17 +1100)
map_dev can be slow so it is best to not call it when
not necessary.
The final test in "find_free_devnum" is not relevant when
udev is being used, so remove the test in that case.

Signed-off-by: NeilBrown <neilb@suse.de>
lib.c
mdadm.h
mdopen.c
util.c

diff --git a/lib.c b/lib.c
index 1c856541c9cc538ea2f142af75ef8f7fa81e9c2a..8124fa1b7479e3a3a90f188e604af8805daea1f6 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -390,3 +390,16 @@ void print_escape(char *str)
                }
        }
 }
+
+int use_udev(void)
+{
+       static int use = -1;
+       struct stat stb;
+
+       if (use < 0) {
+               use = ((stat("/dev/.udev", &stb) == 0
+                       || stat("/run/udev", &stb) == 0)
+                      && check_env("MDADM_NO_UDEV") == 0);
+       }
+       return use;
+}
diff --git a/mdadm.h b/mdadm.h
index 7adf7d94deadd9d39b0d6fd36f050c152535c3cb..be760d26980d82a14a72e1c52891b3e1e07441bf 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1217,6 +1217,7 @@ extern char *conf_line(FILE *file);
 extern char *conf_word(FILE *file, int allow_key);
 extern void print_quoted(char *str);
 extern void print_escape(char *str);
+extern int use_udev(void);
 extern int conf_name_is_free(char *name);
 extern int conf_verify_devnames(struct mddev_ident *array_list);
 extern int devname_matches(char *name, char *match);
index 24188df69912555a4bd02aaef241f15348a70eb1..462743c44bd1fc3bdb183b67ecdc8b0cc2d28944 100644 (file)
--- a/mdopen.c
+++ b/mdopen.c
@@ -330,8 +330,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
         * If we cannot detect udev, we need to make
         * devices and links ourselves.
         */
-       if ((stat("/dev/.udev", &stb) != 0 && stat("/run/udev", &stb) != 0) ||
-           check_env("MDADM_NO_UDEV")) {
+       if (!use_udev()) {
                /* Make sure 'devname' exists and 'chosen' is a symlink to it */
                if (lstat(devname, &stb) == 0) {
                        /* Must be the correct device, else error */
diff --git a/util.c b/util.c
index 6c10365e80c99a39e55111af98b5ccc4e40c5296..70ab6f12ed82bb3604fb5b3a23074fc22bfcce9f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -839,7 +839,6 @@ int find_free_devnum(int use_partitions)
        int devnum;
        for (devnum = 127; devnum != 128;
             devnum = devnum ? devnum-1 : (1<<20)-1) {
-               char *dn;
                int _devnum;
                char nbuf[50];
 
@@ -849,11 +848,14 @@ int find_free_devnum(int use_partitions)
                sprintf(nbuf, "%s%d", use_partitions?"mdp":"md", devnum);
                if (!conf_name_is_free(nbuf))
                        continue;
-               /* make sure it is new to /dev too, at least as a
-                * non-standard */
-               dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0);
-               if (dn && ! is_standard(dn, NULL))
-                       continue;
+               if (!use_udev()) {
+                       /* make sure it is new to /dev too, at least as a
+                        * non-standard */
+                       char *dn = map_dev(dev2major(_devnum),
+                                          dev2minor(_devnum), 0);
+                       if (dn && ! is_standard(dn, NULL))
+                               continue;
+               }
                break;
        }
        if (devnum == 128)