From: Neil Brown Date: Fri, 26 May 2006 01:40:53 +0000 (+0000) Subject: Choose better devnumbers and tidy up some issues with finding names. X-Git-Tag: mdadm-2.5~7 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=commitdiff_plain;h=e7bb5d23a9b29ae6f316fe3ce8970301e1bc0d4d Choose better devnumbers and tidy up some issues with finding names. Signed-off-by: Neil Brown --- diff --git a/Monitor.c b/Monitor.c index c94bfd85..7314cdcd 100644 --- a/Monitor.c +++ b/Monitor.c @@ -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); diff --git a/Query.c b/Query.c index 4cae4508..46707edd 100644 --- a/Query.c +++ b/Query.c @@ -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; } diff --git a/mdopen.c b/mdopen.c index b6dbbe93..5cca1792 100644 --- a/mdopen.c +++ b/mdopen.c @@ -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; diff --git a/super0.c b/super0.c index 70254455..87ef1e06 100644 --- a/super0.c +++ b/super0.c @@ -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) diff --git a/util.c b/util.c index 3d4f6d55..d36feb53 100644 --- a/util.c +++ b/util.c @@ -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);