]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
Allow domain_test to report that no domains were found.
[thirdparty/mdadm.git] / Incremental.c
index 4ee198136f1c81efaf6d184102a6f1a633c95c82..52558e4059d42aa4dd5fd7fb51925055ddaabcfe 100644 (file)
@@ -358,22 +358,17 @@ int Incremental(char *devname, int verbose, int runstop,
                 * array was possibly started early and our best bet is
                 * to add this anyway.
                 * Also if action policy is re-add or better we allow
-                * re-add
+                * re-add.
+                * This doesn't apply to containers as the 'non-spare'
+                * flag has a different meaning.  The test has to happen
+                * at the device level there
                 */
-               if ((info.disk.state & (1<<MD_DISK_SYNC)) != 0
+               if (!st->ss->external
+                   && (info.disk.state & (1<<MD_DISK_SYNC)) != 0
                    && ! policy_action_allows(policy, st->ss->name,
                                              act_re_add)
                    && runstop < 1) {
-                       int active = 0;
-                       
-                       if (st->ss->external) {
-                               char *devname = devnum2devname(fd2devnum(mdfd));
-
-                               active = devname && is_container_active(devname);
-                               free(devname);
-                       } else if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0)
-                               active = 1;
-                       if (active) {
+                       if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
                                fprintf(stderr, Name
                                        ": not adding %s to active array (without --run) %s\n",
                                        devname, chosen_name);
@@ -1000,7 +995,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                }
 
                dl = domain_from_array(sra, st2->ss->name);
-               if (!domain_test(dl, pol, st2->ss->name)) {
+               if (domain_test(dl, pol, st2->ss->name) != 1) {
                        /* domain test fails */
                        if (verbose > 1)
                                fprintf(stderr, Name ": not adding %s to %s as"
@@ -1116,7 +1111,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                pol2 = path_policy(de->d_name, type_disk);
 
                domain_merge(&domlist, pol2, st ? st->ss->name : NULL);
-               if (domain_test(domlist, pol, st ? st->ss->name : NULL) == 0)
+               if (domain_test(domlist, pol, st ? st->ss->name : NULL) != 1)
                        /* new device is incompatible with this device. */
                        goto next;
 
@@ -1142,7 +1137,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                if (!st) {
                        /* Check domain policy again, this time referring to metadata */
                        domain_merge(&domlist, pol2, st2->ss->name);
-                       if (domain_test(domlist, pol, st2->ss->name) == 0)
+                       if (domain_test(domlist, pol, st2->ss->name) != 1)
                                /* Incompatible devices for this metadata type */
                                goto next;
                        if (!policy_action_allows(pol, st2->ss->name, act_spare))
@@ -1434,6 +1429,10 @@ static int Incremental_container(struct supertype *st, char *devname,
        int trustworthy;
        struct mddev_ident *match;
        int rv = 0;
+       struct domainlist *domains;
+       struct map_ent *smp;
+       int suuid[4];
+       int sfd;
 
        memset(&info, 0, sizeof(info));
        st->ss->getinfo_super(st, &info, NULL);
@@ -1553,6 +1552,52 @@ static int Incremental_container(struct supertype *st, char *devname,
                assemble_container_content(st, mdfd, ra, runstop,
                                           chosen_name, verbose);
        }
+
+       /* Now move all suitable spares from spare container */
+       domains = domain_from_array(list, st->ss->name);
+       memcpy(suuid, uuid_zero, sizeof(int[4]));
+       if (domains &&
+           (smp = map_by_uuid(&map, suuid)) != NULL &&
+           (sfd = open(smp->path, O_RDONLY)) >= 0) {
+               /* spare container found */
+               struct supertype *sst =
+                       super_imsm.match_metadata_desc("imsm");
+               struct mdinfo *sinfo;
+               unsigned long long min_size = 0;
+               if (st->ss->min_acceptable_spare_size)
+                       min_size = st->ss->min_acceptable_spare_size(st);
+               if (!sst->ss->load_container(sst, sfd, NULL)) {
+                       close(sfd);
+                       sinfo = container_choose_spares(sst, min_size,
+                                                       domains, NULL,
+                                                       st->ss->name, 0);
+                       sst->ss->free_super(sst);
+                       if (sinfo){
+                               int count = 0;
+                               struct mdinfo *disks = sinfo->devs;
+                               while (disks) {
+                                       /* move spare from spare
+                                        * container to currently
+                                        * assembled one
+                                        */
+                                       if (move_spare(
+                                                   smp->path,
+                                                   devname,
+                                                   makedev(disks->disk.major,
+                                                           disks->disk.minor)))
+                                               count++;
+                                       disks = disks->next;
+                               }
+                               if (count)
+                                       fprintf(stderr, Name
+                                               ": Added %d spare%s to %s\n",
+                                               count, count>1?"s":"", devname);
+                       }
+                       sysfs_free(sinfo);
+               } else
+                       close(sfd);
+       }
+       domain_free(domains);
        map_unlock(&map);
        return 0;
 }