From f2e55eccfb92969c3e11bc5d4883315f2e866a14 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 4 Nov 2008 20:51:12 +1100 Subject: mdopen: use small sequence number for uniquifying array names. Rather than appending the md minor number, we now append a small sequence number to make sure name in /dev/md/ that aren't LOCAL are unique. As the map file is locked while we do this, we are sure of no losing any races. Signed-off-by: NeilBrown --- mdopen.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'mdopen.c') diff --git a/mdopen.c b/mdopen.c index 44efb840..32ccdbbe 100644 --- a/mdopen.c +++ b/mdopen.c @@ -269,19 +269,33 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, * reasonable length and remove '/' */ char *cp; + struct map_ent *map = NULL; + int conflict = 1; + int unum = 0; + int cnlen; strncpy(cname, name, 200); cname[200] = 0; while ((cp = strchr(cname, '/')) != NULL) *cp = '-'; - if (trustworthy == METADATA) - /* always add device number to metadata */ - sprintf(cname+strlen(cname), "%d", num); - else if (trustworthy == FOREIGN && - strchr(cname, ':') == NULL) - /* add _%d to FOREIGN array that don't have - * a 'host:' prefix - */ - sprintf(cname+strlen(cname), "_%d", num<0?(-1-num):num); + if (trustworthy == LOCAL || + (trustworthy == FOREIGN && strchr(cname, ':') != NULL)) { + /* Only need suffix if there is a conflict */ + if (map_by_name(&map, cname) == NULL) + conflict = 0; + } + cnlen = strlen(cname); + while (conflict) { + if (trustworthy == METADATA) + sprintf(cname+cnlen, "%d", unum); + else + /* add _%d to FOREIGN array that don't + * a 'host:' prefix + */ + sprintf(cname+cnlen, "_%d", unum); + unum++; + if (map_by_name(&map, cname) == NULL) + conflict = 0; + } } if (cname[0] == 0) strcpy(chosen, devname); -- cgit v1.2.3