Choose better devnumbers and tidy up some issues with finding names.

Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
Neil Brown 2006-05-26 01:40:53 +00:00
parent da6b5ca9bd
commit e7bb5d23a9
5 changed files with 18 additions and 3 deletions

View File

@ -385,6 +385,7 @@ int Monitor(mddev_dev_t devlist,
if (fd >=0) close(fd);
free(st->devname);
free(st);
put_md_name(st->devname);
continue;
}
close(fd);

View File

@ -130,6 +130,8 @@ int Query(char *dev)
activity,
map_num(pers, info.array.level),
mddev);
if (st->ss->major == 0)
put_md_name(mddev);
}
return 0;
}

View File

@ -183,7 +183,10 @@ int open_mddev(char *dev, int autof)
if (num < 0) {
/* need to pick an unused number */
mdlist = mdstat_read(0, 0);
for (num = 0 ; ; num++) {
/* Choose a large number. Start from 127 and search down,
* but if nothing is found, start really big
*/
for (num = 127 ; num != 128 ; num = num ? num-1 : (1<<22)-1) {
struct mdstat_ent *me;
int devnum = num;
if (major != MD_MAJOR)
@ -193,7 +196,7 @@ int open_mddev(char *dev, int autof)
if (me->devnum == devnum)
break;
if (!me) {
/* doesn't exist if mdstat.
/* doesn't exist in mdstat.
* make sure it is new to /dev too
*/
char *dn;

View File

@ -227,9 +227,10 @@ static void brief_examine_super0(void *sbv)
{
mdp_super_t *sb = sbv;
char *c=map_num(pers, sb->level);
char *nm;
printf("ARRAY %s level=%s num-devices=%d UUID=",
get_md_name(sb->md_minor),
nm = get_md_name(sb->md_minor),
c?c:"-unknown-", sb->raid_disks);
if (sb->minor_version >= 90)
printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
@ -237,6 +238,7 @@ static void brief_examine_super0(void *sbv)
else
printf("%08x", sb->set_uuid0);
printf("\n");
put_md_name(nm);
}
static void detail_super0(void *sbv, char *homehost)

7
util.c
View File

@ -414,6 +414,8 @@ char *map_dev(int major, int minor, int create)
{
struct devmap *p;
char *std = NULL, *nonstd=NULL;
int did_check = 0;
retry:
if (!devlist_ready) {
char *dev = "/dev";
struct stat stb;
@ -422,6 +424,7 @@ char *map_dev(int major, int minor, int create)
dev = "/dev/.";
nftw(dev, add_dev, 10, FTW_PHYS);
devlist_ready=1;
did_check = 1;
}
for (p=devlist; p; p=p->next)
@ -437,6 +440,10 @@ char *map_dev(int major, int minor, int create)
nonstd = p->name;
}
}
if (!std && !nonstd && !did_check) {
devlist_ready = 0;
goto retry;
}
if (create && !std && !nonstd) {
static char buf[30];
snprintf(buf, 1024, "%d:%d", major, minor);