]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
config: Support container=uuid as alternative to container=/dev/name in mdadm.conf
authorNeilBrown <neilb@suse.de>
Tue, 4 Nov 2008 09:50:38 +0000 (20:50 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 4 Nov 2008 09:50:38 +0000 (20:50 +1100)
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>
Incremental.c
config.c
mdadm.h

index 55a5f10c78b49b2a7c7c4efe002021f792826548..1cccdf7cdc95421d6e8ee5e6e3837013d62c9b1c 100644 (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] != '/') {
index f08a9f077d420b55b47dc37c0710232c758257cf..9eb8197a9382a1b805f50adb3e8f2d6bc55266ec 100644 (file)
--- 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 b94cda34478d4955363be0ada3ca91ba5d1e9f61..8b8208766be92bb97351547909e148926ec4c706 100644 (file)
--- 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 */