config: Support container=uuid as alternative to container=/dev/name in mdadm.conf

When mdadm.conf is automatically generated, we might not know a
suitable /dev/name.  But we do know the uuid of the container.
So allow that as an option.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2008-11-04 20:50:38 +11:00
parent fe056d1fb0
commit 1771a6e214
3 changed files with 32 additions and 8 deletions

View File

@ -708,6 +708,31 @@ int IncrementalScan(int verbose)
return rv;
}
static char *container2devname(char *devname)
{
char *mdname = NULL;
if (devname[0] == '/') {
int fd = open(devname, O_RDONLY);
if (fd >= 0) {
mdname = devnum2devname(fd2devnum(fd));
close(fd);
}
} else {
int uuid[4];
struct map_ent *mp, *map = NULL;
if (!parse_uuid(devname, uuid))
return mdname;
mp = map_by_uuid(&map, uuid);
if (mp)
mdname = devnum2devname(mp->devnum);
map_free(map);
}
return mdname;
}
int Incremental_container(struct supertype *st, char *devname, int verbose,
int runstop, int autof, int trustworthy)
{
@ -741,7 +766,6 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
} else
array_list = NULL;
for(; array_list ; array_list = array_list->next) {
int fd;
char *dn;
if (array_list->member == NULL ||
array_list->container == NULL)
@ -751,11 +775,9 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
if (array_list->uuid_set &&
!same_uuid(ra->uuid, array_list->uuid, st->ss->swapuuid))
continue;
fd = open(array_list->container, O_RDONLY);
if (fd < 0)
dn = container2devname(array_list->container);
if (dn == NULL)
continue;
dn = devnum2devname(fd2devnum(fd));
close(fd);
if (strncmp(dn, ra->text_version+1,
strlen(dn)) != 0 ||
ra->text_version[strlen(dn)+1] != '/') {

View File

@ -522,7 +522,8 @@ void arrayline(char *line)
/* subarray within a container */
mis.member = strdup(w+7);
} else if (strncasecmp(w, "container=", 10) == 0) {
/* the container holding this subarray */
/* the container holding this subarray. Either a device name
* or a uuid */
mis.container = strdup(w+10);
} else {
fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n",

View File

@ -259,8 +259,9 @@ typedef struct mddev_ident_s {
char *bitmap_file;
int bitmap_fd;
char *container; /* /dev/whatever name of container. You
* would expect this to be the 'devname'
char *container; /* /dev/whatever name of container, or
* uuid of container. You would expect
* this to be the 'devname' or UUID
* of some other entry.
*/
char *member; /* subarray within a container */