]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Assemble.c
Allow domain_test to report that no domains were found.
[thirdparty/mdadm.git] / Assemble.c
index 5e71a434c22a312c335f4017591cd4431984b502..b3f54ce43a811b28f425bf1f92b9cb96361af19e 100644 (file)
@@ -78,7 +78,8 @@ static int ident_matches(struct mddev_ident *ident,
 {
 
        if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) &&
-           same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0) {
+           same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0 &&
+           memcmp(content->uuid, uuid_zero, sizeof(int[4])) != 0) {
                if (devname)
                        fprintf(stderr, Name ": %s has wrong uuid.\n",
                                devname);
@@ -133,7 +134,8 @@ static int ident_matches(struct mddev_ident *ident,
 
 int Assemble(struct supertype *st, char *mddev,
             struct mddev_ident *ident,
-            struct mddev_dev *devlist, char *backup_file,
+            struct mddev_dev *devlist,
+            char *backup_file, int invalid_backup,
             int readonly, int runstop,
             char *update, char *homehost, int require_homehost,
             int verbose, int force)
@@ -230,6 +232,7 @@ int Assemble(struct supertype *st, char *mddev,
        char *name = NULL;
        int trustworthy;
        char chosen_name[1024];
+       struct domainlist *domains = NULL;
 
        if (get_linux_version() < 2004000)
                old_linux = 1;
@@ -332,7 +335,8 @@ int Assemble(struct supertype *st, char *mddev,
                                        fprintf(stderr, Name ": not a recognisable container: %s\n",
                                                devname);
                                tmpdev->used = 2;
-                       } else if (tst->ss->load_container(tst, dfd, NULL)) {
+                       } else if (!tst->ss->load_container
+                                  || tst->ss->load_container(tst, dfd, NULL)) {
                                if (report_missmatch)
                                        fprintf(stderr, Name ": no correct container type: %s\n",
                                                devname);
@@ -375,7 +379,7 @@ int Assemble(struct supertype *st, char *mddev,
                }
                if (dfd >= 0) close(dfd);
                if (tmpdev->used == 2) {
-                       if (auto_assem)
+                       if (auto_assem || !inargv)
                                /* Ignore unrecognised devices during auto-assembly */
                                goto loop;
                        if (ident->uuid_set || ident->name[0] ||
@@ -390,6 +394,7 @@ int Assemble(struct supertype *st, char *mddev,
                        if (st)
                                st->ss->free_super(st);
                        dev_policy_free(pol);
+                       domain_free(domains);
                        return 1;
                }
 
@@ -433,6 +438,13 @@ int Assemble(struct supertype *st, char *mddev,
                             content;
                             content = content->next) {
 
+                               /* do not assemble arrays that might have bad blocks */
+                               if (content->array.state & (1<<MD_SB_BBM_ERRORS)) {
+                                       fprintf(stderr, Name ": BBM log found in metadata. "
+                                                               "Cannot activate array(s).\n");
+                                       tmpdev->used = 2;
+                                       goto loop;
+                               }
                                if (!ident_matches(ident, content, tst,
                                                   homehost, update,
                                                   report_missmatch ? devname : NULL))
@@ -457,6 +469,7 @@ int Assemble(struct supertype *st, char *mddev,
                                        devname);
                                st->ss->free_super(st);
                                dev_policy_free(pol);
+                               domain_free(domains);
                                return 1;
                        }
                        if (verbose > 0)
@@ -476,11 +489,23 @@ int Assemble(struct supertype *st, char *mddev,
                                           homehost, update,
                                           report_missmatch ? devname : NULL))
                                goto loop;
-
+                               
                        if (st == NULL)
                                st = dup_super(tst);
                        if (st->minor_version == -1)
                                st->minor_version = tst->minor_version;
+
+                       if (memcmp(content->uuid, uuid_zero,
+                                  sizeof(int[4])) == 0) {
+                               /* this is a floating spare.  It cannot define
+                                * an array unless there are no more arrays of
+                                * this type to be found.  It can be included
+                                * in an array of this type though.
+                                */
+                               tmpdev->used = 3;
+                               goto loop;
+                       }
+
                        if (st->ss != tst->ss ||
                            st->minor_version != tst->minor_version ||
                            st->ss->compare_super(st, tst) != 0) {
@@ -520,17 +545,69 @@ int Assemble(struct supertype *st, char *mddev,
                                tst->ss->free_super(tst);
                                st->ss->free_super(st);
                                dev_policy_free(pol);
+                               domain_free(domains);
                                return 1;
                        }
                        tmpdev->used = 1;
                }
        loop:
+               /* Collect domain information from members only */
+               if (tmpdev && tmpdev->used == 1) {
+                       if (!pol)
+                               pol = devnum_policy(stb.st_rdev);
+                       domain_merge(&domains, pol, tst?tst->ss->name:NULL);
+               }
                dev_policy_free(pol);
                pol = NULL;
                if (tst)
                        tst->ss->free_super(tst);
        }
 
+       /* Check if we found some imsm spares but no members */
+       if ((auto_assem ||
+            (ident->uuid_set &&
+             memcmp(uuid_zero, ident->uuid,sizeof(uuid_zero)) == 0)) &&
+           (!st || !st->sb))
+               for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) {
+                       if (tmpdev->used != 3)
+                               continue;
+                       tmpdev->used = 1;
+                       content = &info;
+
+                       if (!st->sb) {
+                               /* we need sb from one of the spares */
+                               int dfd = dev_open(tmpdev->devname, O_RDONLY);
+                               if (dfd < 0 ||
+                                   st->ss->load_super(st, dfd, NULL))
+                                       tmpdev->used = 2;
+                               if (dfd > 0)
+                                       close(dfd);
+                       }
+               }
+
+       /* Now reject spares that don't match domains of identified members */
+       for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) {
+               struct stat stb;
+               if (tmpdev->used != 3)
+                       continue;
+               if (stat(tmpdev->devname, &stb)< 0) {
+                       fprintf(stderr, Name ": fstat failed for %s: %s\n",
+                               tmpdev->devname, strerror(errno));
+                       tmpdev->used = 2;
+               } else {
+                       struct dev_policy *pol = NULL;
+                       pol = devnum_policy(stb.st_rdev);
+                       if (domain_test(domains, pol, NULL) == 1)
+                               /* take this spare if domains match */
+                               tmpdev->used = 1;
+                       else
+                               /* if domains don't match mark as unused */
+                               tmpdev->used = 0;
+                       dev_policy_free(pol);
+               }
+       }
+       domain_free(domains);
+       
        if (!st || !st->sb || !content)
                return 2;
 
@@ -843,8 +920,10 @@ int Assemble(struct supertype *st, char *mddev,
                if (content->array.level != LEVEL_MULTIPATH)
                        if (!(devices[j].i.disk.state & (1<<MD_DISK_ACTIVE))) {
                                if (!(devices[j].i.disk.state
-                                     & (1<<MD_DISK_FAULTY)))
+                                     & (1<<MD_DISK_FAULTY))) {
+                                       devices[j].uptodate = 1;
                                        sparecnt++;
+                               }
                                continue;
                        }
                /* If this devices thinks that 'most_recent' has failed, then
@@ -1096,8 +1175,16 @@ int Assemble(struct supertype *st, char *mddev,
                        } else
                                fdlist[i] = -1;
                }
-               if (!err)
-                       err = Grow_restart(st, content, fdlist, bestcnt, backup_file, verbose > 0);
+               if (!err) {
+                       err = Grow_restart(st, content, fdlist, bestcnt,
+                                          backup_file, verbose > 0);
+                       if (err && invalid_backup) {
+                               if (verbose > 0)
+                                       fprintf(stderr, Name ": continuing"
+                                               " without restoring backup\n");
+                               err = 0;
+                       }
+               }
                while (i>0) {
                        i--;
                        if (fdlist[i]>=0) close(fdlist[i]);
@@ -1217,6 +1304,7 @@ int Assemble(struct supertype *st, char *mddev,
                                                content->array.raid_disks);
                                fprintf(stderr, "\n");
                        }
+                       st->ss->free_super(st);
                        sysfs_uevent(content, "change");
                        wait_for(chosen_name, mdfd);
                        close(mdfd);