From 1771a6e214755311530a7099374df53d84e06a82 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 4 Nov 2008 20:50:38 +1100 Subject: [PATCH] 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 --- Incremental.c | 32 +++++++++++++++++++++++++++----- config.c | 3 ++- mdadm.h | 5 +++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Incremental.c b/Incremental.c index 55a5f10c..1cccdf7c 100644 --- a/Incremental.c +++ b/Incremental.c @@ -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] != '/') { diff --git a/config.c b/config.c index f08a9f07..9eb8197a 100644 --- a/config.c +++ b/config.c @@ -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", diff --git a/mdadm.h b/mdadm.h index b94cda34..8b820876 100644 --- a/mdadm.h +++ b/mdadm.h @@ -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 */ -- 2.39.2