X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=util.c;h=dddcc8b3cefd4fb365d00de4d723ccf6593a3f9a;hp=1736d70791c8ce5d145f6c01516384f4c19adb30;hb=603f24a05f48063a7239e323e2aeab497cb0feb6;hpb=9008ed1c9623b7c11775ea8a7be17eb1bde5fd09 diff --git a/util.c b/util.c index 1736d707..dddcc8b3 100644 --- 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) @@ -887,7 +916,10 @@ struct supertype *super_by_fd(int fd) if (sra) sysfs_free(sra); sra = sysfs_read(-1, devnum, GET_VERSION); - verstr = sra->text_version ? : "-no-metadata-"; + if (sra && sra->text_version[0]) + verstr = sra->text_version; + else + verstr = "-no-metadata-"; } for (i = 0; st == NULL && superlist[i] ; i++) @@ -1063,7 +1095,8 @@ int add_disk(int mdfd, struct supertype *st, int rv; #ifndef MDASSEMBLE if (st->ss->external) { - rv = sysfs_add_disk(sra, info); + rv = sysfs_add_disk(sra, info, + info->disk.state & (1<devs; sd2; sd2=sd2->next) @@ -1247,9 +1280,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");