Choose better devnumbers and tidy up some issues with finding names.
authorNeil Brown <neilb@suse.de>
Fri, 26 May 2006 01:40:53 +0000 (01:40 +0000)
committerNeil Brown <neilb@suse.de>
Fri, 26 May 2006 01:40:53 +0000 (01:40 +0000)
Signed-off-by: Neil Brown <neilb@suse.de>
Monitor.c
Query.c
mdopen.c
super0.c
util.c

index c94bfd8..7314cdc 100644 (file)
--- 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 4cae450..46707ed 100644 (file)
--- 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;
 }
index b6dbbe9..5cca179 100644 (file)
--- 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;
index 7025445..87ef1e0 100644 (file)
--- 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 3d4f6d5..d36feb5 100644 (file)
--- 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);