]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
Don't try to set_array_info when -I find new devices for an array.
[thirdparty/mdadm.git] / Incremental.c
index 869ae8396802f81a729e3678d60de55362f38b03..c9ba1eafffa3a01041a325acddf5dd65061ad743 100644 (file)
@@ -233,7 +233,7 @@ int Incremental(char *devname, int verbose, int runstop,
        mp = map_by_uuid(&map, info.uuid);
 
        if (uuid_for_name && ! mp) {
-               name_to_use = fname_from_uuid(st, &info, nbuf);
+               name_to_use = fname_from_uuid(st, &info, nbuf, '-');
                if (verbose >= 0)
                        fprintf(stderr, Name
                ": not found in mdadm.conf and not identified by homehost"
@@ -783,7 +783,7 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
        }
 
        for (ra = list ; ra ; ra = ra->next) {
-               struct mdinfo *dev;
+               struct mdinfo *dev, *sra;
                int devnum = -1;
                int mdfd;
                char chosen_name[1024];
@@ -793,6 +793,7 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                struct map_ent *mp, *map = NULL;
                char nbuf[64];
                char *name_to_use;
+               struct mddev_ident_s *match = NULL;
 
                if ((autof&7) == 3 || (autof&7) == 5)
                        usepart = 0;
@@ -804,12 +805,53 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                    ! *name_to_use ||
                    (*devname != '/' || strncmp("UUID-", strrchr(devname,'/')+1,5) == 0)
                        )
-                       name_to_use = fname_from_uuid(st, ra, nbuf);
+                       name_to_use = fname_from_uuid(st, ra, nbuf, '-');
                    
-               if (mp)
+               if (!mp) {
+
+                       /* Check in mdadm.conf for devices == devname and
+                        * member == ra->text_version after second slash.
+                        */
+                       char *sub = strchr(ra->text_version+1, '/');
+                       struct mddev_ident_s *array_list;
+                       if (sub) {
+                               sub++;
+                               array_list = conf_get_ident(NULL);
+                       } 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)
+                                       continue;
+                               if (strcmp(array_list->member, sub) != 0)
+                                       continue;
+                               fd = open(array_list->container, O_RDONLY);
+                               if (fd < 0)
+                                       continue;
+                               dn = devnum2devname(fd2devnum(fd));
+                               close(fd);
+                               if (strncmp(dn, ra->text_version+1,
+                                           strlen(dn)) != 0 ||
+                                   ra->text_version[strlen(dn)+1] != '/') {
+                                       free(dn);
+                                       continue;
+                               }
+                               free(dn);
+                               /* we have a match */
+                               match = array_list;
+                               break;
+                       }
+               }
+
+               if (match && is_standard(match->devname, &devnum))
+                       /* we have devnum now */;
+               else if (mp)
                        devnum = mp->devnum;
+               else if (is_standard(name_to_use, &devnum))
+                       /* have devnum */;
                else {
-
                        n = name_to_use;
                        if (*n == 'd')
                                n++;
@@ -851,7 +893,8 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                        else
                                devnum = find_free_devnum(usepart);
                }
-               mdfd = open_mddev_devnum(mp ? mp->path : NULL, devnum, name_to_use,
+               mdfd = open_mddev_devnum(mp ? mp->path : match ? match->devname : NULL,
+                                        devnum, name_to_use,
                                         chosen_name, autof>>3);
 
                if (mdfd < 0) {
@@ -860,8 +903,16 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
                        return 2;
                }
 
+
                sysfs_init(ra, mdfd, 0);
-               sysfs_set_array(ra, md_get_version(mdfd));
+
+               sra = sysfs_read(mdfd, 0, GET_VERSION);
+               if (sra == NULL || strcmp(sra->text_version, ra->text_version) != 0)
+                       if (sysfs_set_array(ra, md_get_version(mdfd)) != 0)
+                               return 1;
+               if (sra)
+                       sysfs_free(sra);
+
                for (dev = ra->devs; dev; dev = dev->next)
                        if (sysfs_add_disk(ra, dev) == 0)
                                working++;