]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
wait_for improvement.
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 1736d70791c8ce5d145f6c01516384f4c19adb30..02fc46339742c6058ae099d729f94728c20982f2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -467,8 +467,10 @@ int devlist_ready = 0;
 int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
 {
        struct stat st;
+
        if (S_ISLNK(stb->st_mode)) {
-               stat(name, &st);
+               if (stat(name, &st) != 0)
+                       return 0;
                stb = &st;
        }
 
@@ -763,7 +765,7 @@ int find_free_devnum(int use_partitions)
 {
        int devnum;
        for (devnum = 127; devnum != 128;
-            devnum = devnum ? devnum-1 : (1<<22)-1) {
+            devnum = devnum ? devnum-1 : (1<<20)-1) {
                char *dn;
                int _devnum;
 
@@ -811,6 +813,14 @@ int dev_open(char *dev, int flags)
        return fd;
 }
 
+int open_dev(int devnum)
+{
+       char buf[20];
+
+       sprintf(buf, "%d:%d", dev2major(devnum), dev2minor(devnum));
+       return dev_open(buf, O_RDWR);
+}
+
 int open_dev_excl(int devnum)
 {
        char buf[20];
@@ -842,6 +852,25 @@ int same_dev(char *one, char *two)
        return st1.st_rdev == st2.st_rdev;
 }
 
+void wait_for(char *dev, int fd)
+{
+       int i;
+       struct stat stb_want;
+
+       if (fstat(fd, &stb_want) != 0 ||
+           (stb_want.st_mode & S_IFMT) != S_IFBLK)
+               return;
+
+       for (i=0 ; i<25 ; i++) {
+               struct stat stb;
+               if (stat(dev, &stb) == 0 &&
+                   (stb.st_mode & S_IFMT) == S_IFBLK &&
+                   (stb.st_rdev == stb_want.st_rdev))
+                       return;
+               usleep(200000);
+       }
+}
+
 struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL };
 
 #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
@@ -1247,9 +1276,8 @@ int start_mdmon(int devnum)
                for (i=0; paths[i]; i++)
                        if (paths[i][0])
                                execl(paths[i], "mdmon",
-                                     map_dev(dev2major(devnum),
-                                             dev2minor(devnum),
-                                             1), NULL);
+                                     devnum2devname(devnum),
+                                     NULL);
                exit(1);
        case -1: fprintf(stderr, Name ": cannot run mdmon. "
                         "Array remains readonly\n");