]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
Monitor: fix reporting for Fail vs FailSpare etc.
[thirdparty/mdadm.git] / Incremental.c
index 6ff64f3a2bfad90a25555b16726b600528f31b2c..a61f45336aa58c7b59309ca55fd3fe8ab27f921e 100644 (file)
@@ -44,16 +44,12 @@ static int try_spare(char *devname, int *dfdp, struct dev_policy *pol,
 
 static int Incremental_container(struct supertype *st, char *devname,
                                 char *homehost,
-                                int verbose, int runstop, int autof);
-
-static struct mddev_ident *search_mdstat(struct supertype *st,
-                                          struct mdinfo *info,
-                                          char *devname,
-                                          int verbose, int *rvp);
+                                int verbose, int runstop, int autof,
+                                int freeze_reshape);
 
 int Incremental(char *devname, int verbose, int runstop,
                struct supertype *st, char *homehost, int require_homehost,
-               int autof)
+               int autof, int freeze_reshape)
 {
        /* Add this device to an array, creating the array if necessary
         * and starting the array if sensible or - if runstop>0 - if possible.
@@ -138,9 +134,16 @@ int Incremental(char *devname, int verbose, int runstop,
                        rv = st->ss->load_container(st, dfd, NULL);
 
                close(dfd);
-               if (!rv && st->ss->container_content)
-                       return Incremental_container(st, devname, homehost,
-                                                    verbose, runstop, autof);
+               if (!rv && st->ss->container_content) {
+                       if (map_lock(&map))
+                               fprintf(stderr, Name ": failed to get "
+                                       "exclusive lock on mapfile\n");
+                       rv = Incremental_container(st, devname, homehost,
+                                                  verbose, runstop, autof,
+                                                  freeze_reshape);
+                       map_unlock(&map);
+                       return rv;
+               }
 
                fprintf(stderr, Name ": %s is not part of an md array.\n",
                        devname);
@@ -202,11 +205,10 @@ int Incremental(char *devname, int verbose, int runstop,
        }
        close (dfd); dfd = -1;
 
-       memset(&info, 0, sizeof(info));
        st->ss->getinfo_super(st, &info, NULL);
 
        /* 3/ Check if there is a match in mdadm.conf */
-       match = search_mdstat(st, &info, devname, verbose, &rv);
+       match = conf_match(st, &info, devname, verbose, &rv);
        if (!match && rv == 2)
                goto out;
 
@@ -257,8 +259,7 @@ int Incremental(char *devname, int verbose, int runstop,
 
        name_to_use = info.name;
        if (name_to_use[0] == 0 &&
-           info.array.level == LEVEL_CONTAINER &&
-           trustworthy == LOCAL) {
+           info.array.level == LEVEL_CONTAINER) {
                name_to_use = info.text_version;
                trustworthy = METADATA;
        }
@@ -291,7 +292,7 @@ int Incremental(char *devname, int verbose, int runstop,
                                    name_to_use, autof, trustworthy, chosen_name);
 
                if (mdfd < 0)
-                       goto out;
+                       goto out_unlock;
 
                sysfs_init(&info, mdfd, 0);
 
@@ -299,7 +300,7 @@ int Incremental(char *devname, int verbose, int runstop,
                        fprintf(stderr, Name ": failed to set array info for %s: %s\n",
                                chosen_name, strerror(errno));
                        rv = 2;
-                       goto out;
+                       goto out_unlock;
                }
 
                dinfo = info;
@@ -310,7 +311,7 @@ int Incremental(char *devname, int verbose, int runstop,
                                devname, chosen_name, strerror(errno));
                        ioctl(mdfd, STOP_ARRAY, 0);
                        rv = 2;
-                       goto out;
+                       goto out_unlock;
                }
                sra = sysfs_read(mdfd, -1, (GET_DEVS | GET_STATE |
                                            GET_OFFSET | GET_SIZE));
@@ -324,9 +325,8 @@ int Incremental(char *devname, int verbose, int runstop,
                        fprintf(stderr, Name
                      ": You have an old buggy kernel which cannot support\n"
                                "      --incremental reliably.  Aborting.\n");
-                       sysfs_free(sra);
                        rv = 2;
-                       goto out;
+                       goto out_unlock;
                }
                info.array.working_disks = 1;
                /* 6/ Make sure /var/run/mdadm.map contains this array. */
@@ -358,37 +358,38 @@ 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);
                                rv = 2;
-                               goto out;
+                               goto out_unlock;
                        }
                }
                if (!sra) {
                        rv = 2;
-                       goto out;
+                       goto out_unlock;
                }
                if (sra->devs) {
                        sprintf(dn, "%d:%d", sra->devs->disk.major,
                                sra->devs->disk.minor);
                        dfd2 = dev_open(dn, O_RDONLY);
+                       if (dfd2 < 0) {
+                               fprintf(stderr, Name
+                                       ": unable to open %s\n", devname);
+                               rv = 2;
+                               goto out_unlock;
+                       }
                        st2 = dup_super(st);
                        if (st2->ss->load_super(st2, dfd2, NULL) ||
                            st->ss->compare_super(st, st2) != 0) {
@@ -398,10 +399,9 @@ int Incremental(char *devname, int verbose, int runstop,
                                        devname, chosen_name);
                                close(dfd2);
                                rv = 2;
-                               goto out;
+                               goto out_unlock;
                        }
                        close(dfd2);
-                       memset(&info2, 0, sizeof(info2));
                        st2->ss->getinfo_super(st2, &info2, NULL);
                        st2->ss->free_super(st2);
                        if (info.array.level != info2.array.level ||
@@ -411,28 +411,28 @@ int Incremental(char *devname, int verbose, int runstop,
                                        ": unexpected difference between %s and %s.\n",
                                        chosen_name, devname);
                                rv = 2;
-                               goto out;
+                               goto out_unlock;
                        }
                }
-               info2.disk.major = major(stb.st_rdev);
-               info2.disk.minor = minor(stb.st_rdev);
+               info.disk.major = major(stb.st_rdev);
+               info.disk.minor = minor(stb.st_rdev);
                /* add disk needs to know about containers */
                if (st->ss->external)
                        sra->array.level = LEVEL_CONTAINER;
-               err = add_disk(mdfd, st, sra, &info2);
+               err = add_disk(mdfd, st, sra, &info);
                if (err < 0 && errno == EBUSY) {
                        /* could be another device present with the same
                         * disk.number. Find and reject any such
                         */
                        find_reject(mdfd, st, sra, info.disk.number,
                                    info.events, verbose, chosen_name);
-                       err = add_disk(mdfd, st, sra, &info2);
+                       err = add_disk(mdfd, st, sra, &info);
                }
                if (err < 0) {
                        fprintf(stderr, Name ": failed to add %s to %s: %s.\n",
                                devname, chosen_name, strerror(errno));
                        rv = 2;
-                       goto out;
+                       goto out_unlock;
                }
                info.array.working_disks = 0;
                for (d = sra->devs; d; d=d->next)
@@ -443,21 +443,26 @@ int Incremental(char *devname, int verbose, int runstop,
        /* 7/ Is there enough devices to possibly start the array? */
        /* 7a/ if not, finish with success. */
        if (info.array.level == LEVEL_CONTAINER) {
-               char *devname = NULL;
+               int devnum = devnum; /* defined and used iff ->external */
                /* Try to assemble within the container */
-               map_unlock(&map);
-               sysfs_uevent(&info, "change");
+               sysfs_uevent(sra, "change");
                if (verbose >= 0)
                        fprintf(stderr, Name
-                               ": container %s now has %d devices\n",
-                               chosen_name, info.array.working_disks);
+                               ": container %s now has %d device%s\n",
+                               chosen_name, info.array.working_disks,
+                               info.array.working_disks==1?"":"s");
                wait_for(chosen_name, mdfd);
                if (st->ss->external)
-                       devname = devnum2devname(fd2devnum(mdfd));
+                       devnum = fd2devnum(mdfd);
+               if (st->ss->load_container)
+                       rv = st->ss->load_container(st, mdfd, NULL);
                close(mdfd);
                sysfs_free(sra);
-               rv = Incremental(chosen_name, verbose, runstop,
-                                NULL, homehost, require_homehost, autof);
+               if (!rv)
+                       rv = Incremental_container(st, chosen_name, homehost,
+                                                  verbose, runstop, autof,
+                                                  freeze_reshape);
+               map_unlock(&map);
                if (rv == 1)
                        /* Don't fail the whole -I if a subarray didn't
                         * have enough devices to start yet
@@ -465,10 +470,8 @@ int Incremental(char *devname, int verbose, int runstop,
                        rv = 0;
                /* after spare is added, ping monitor for external metadata
                 * so that it can eg. try to rebuild degraded array */
-               if (st->ss->external) {
-                       ping_monitor(devname);
-                       free(devname);
-               }
+               if (st->ss->external)
+                       ping_monitor_by_id(devnum);
                return rv;
        }
 
@@ -482,14 +485,13 @@ int Incremental(char *devname, int verbose, int runstop,
        active_disks = count_active(st, sra, mdfd, &avail, &info);
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
-                  avail, active_disks) == 0) {
+                  avail) == 0) {
                if (verbose >= 0)
                        fprintf(stderr, Name
                             ": %s attached to %s, not enough to start (%d).\n",
                                devname, chosen_name, active_disks);
-               map_unlock(&map);
                rv = 0;
-               goto out;
+               goto out_unlock;
        }
 
        /* 7b/ if yes, */
@@ -503,9 +505,8 @@ int Incremental(char *devname, int verbose, int runstop,
                        fprintf(stderr, Name
                           ": %s attached to %s which is already active.\n",
                                devname, chosen_name);
-               map_unlock(&map);
                rv = 0;
-               goto out;
+               goto out_unlock;
        }
 
        map_unlock(&map);
@@ -586,79 +587,9 @@ out:
        if (sra)
                sysfs_free(sra);
        return rv;
-}
-
-static struct mddev_ident *search_mdstat(struct supertype *st,
-                                          struct mdinfo *info,
-                                          char *devname,
-                                          int verbose, int *rvp)
-{
-       struct mddev_ident *array_list, *match;
-       array_list = conf_get_ident(NULL);
-       match = NULL;
-       for (; array_list; array_list = array_list->next) {
-               if (array_list->uuid_set &&
-                   same_uuid(array_list->uuid, info->uuid, st->ss->swapuuid)
-                   == 0) {
-                       if (verbose >= 2 && array_list->devname)
-                               fprintf(stderr, Name
-                                       ": UUID differs from %s.\n",
-                                       array_list->devname);
-                       continue;
-               }
-               if (array_list->name[0] &&
-                   strcasecmp(array_list->name, info->name) != 0) {
-                       if (verbose >= 2 && array_list->devname)
-                               fprintf(stderr, Name
-                                       ": Name differs from %s.\n",
-                                       array_list->devname);
-                       continue;
-               }
-               if (array_list->devices &&
-                   !match_oneof(array_list->devices, devname)) {
-                       if (verbose >= 2 && array_list->devname)
-                               fprintf(stderr, Name
-                                       ": Not a listed device for %s.\n",
-                                       array_list->devname);
-                       continue;
-               }
-               if (array_list->super_minor != UnSet &&
-                   array_list->super_minor != info->array.md_minor) {
-                       if (verbose >= 2 && array_list->devname)
-                               fprintf(stderr, Name
-                                       ": Different super-minor to %s.\n",
-                                       array_list->devname);
-                       continue;
-               }
-               if (!array_list->uuid_set &&
-                   !array_list->name[0] &&
-                   !array_list->devices &&
-                   array_list->super_minor == UnSet) {
-                       if (verbose >= 2 && array_list->devname)
-                               fprintf(stderr, Name
-                                       ": %s doesn't have any identifying information.\n",
-                                       array_list->devname);
-                       continue;
-               }
-               /* FIXME, should I check raid_disks and level too?? */
-
-               if (match) {
-                       if (verbose >= 0) {
-                               if (match->devname && array_list->devname)
-                                       fprintf(stderr, Name
-                                               ": we match both %s and %s - cannot decide which to use.\n",
-                                               match->devname, array_list->devname);
-                               else
-                                       fprintf(stderr, Name
-                                               ": multiple lines in mdadm.conf match\n");
-                       }
-                       *rvp = 2;
-                       match = NULL;
-                       break;
-               }
-               match = array_list;
-       }
-       return match;
+out_unlock:
+       map_unlock(&map);
+       goto out;
 }
 
 static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
@@ -714,7 +645,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
        int cnt = 0;
        __u64 max_events = 0;
        char *avail = NULL;
-       int *best;
+       int *best = NULL;
        char *devmap = NULL;
        int numdevs = 0;
        int devnum;
@@ -785,9 +716,10 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                                best[info.disk.raid_disk] = devnum;
                                st->ss->getinfo_super(st, bestinfo, NULL);
                        } else { /* info.events much bigger */
-                               memset(avail, 0, info.disk.raid_disk);
+                               memset(avail, 0, raid_disks);
                                max_events = info.events;
                                avail[info.disk.raid_disk] = 2;
+                               best[info.disk.raid_disk] = devnum;
                                st->ss->getinfo_super(st, bestinfo, NULL);
                        }
                }
@@ -888,6 +820,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                struct domainlist *dl = NULL;
                struct mdinfo *sra;
                unsigned long long devsize;
+               unsigned long long component_size = 0;
 
                if (is_subarray(mp->metadata))
                        continue;
@@ -946,19 +879,30 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                        sra->array.failed_disks = container_members_max_degradation(map, mp);
 
                get_dev_size(dfd, NULL, &devsize);
-               if (st2->ss->avail_size(st2, devsize) < sra->component_size) {
-                       if (verbose > 1)
-                               fprintf(stderr, Name ": not adding %s to %s as it is too small\n",
-                                       devname, mp->path);
-                       goto next;
+               if (sra->component_size == 0) {
+                       /* true for containers, here we must read superblock
+                        * to obtain minimum spare size */
+                       struct supertype *st3 = dup_super(st2);
+                       int mdfd = open_dev(mp->devnum);
+                       if (mdfd < 0) {
+                               free(st3);
+                               goto next;
+                       }
+                       if (st3->ss->load_container &&
+                           !st3->ss->load_container(st3, mdfd, mp->path)) {
+                               component_size = st3->ss->min_acceptable_spare_size(st3);
+                               st3->ss->free_super(st3);
+                       }
+                       free(st3);
+                       close(mdfd);
                }
-               dl = domain_from_array(sra, st2->ss->name);
-               if (!domain_test(dl, pol, st2->ss->name)) {
-                       /* domain test fails */
+               if ((sra->component_size > 0 &&
+                    st2->ss->avail_size(st2, devsize) < sra->component_size)
+                   ||
+                   (sra->component_size == 0 && devsize < component_size)) {
                        if (verbose > 1)
-                               fprintf(stderr, Name ": not adding %s to %s as it is not in a compatible domain\n",
+                               fprintf(stderr, Name ": not adding %s to %s as it is too small\n",
                                        devname, mp->path);
-
                        goto next;
                }
                /* test against target.
@@ -966,11 +910,14 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                 * arrays/containers that match 'target'.
                 * If 'target' is set and 'bare' is true, we prefer the
                 * array which matches 'target'.
+                * target is considered only if we deal with degraded array
                 */
-               if (target) {
+               if (target && policy_action_allows(pol, st2->ss->name,
+                                                  act_spare_same_slot)) {
                        if (strcmp(target->metadata, mp->metadata) == 0 &&
                            memcmp(target->uuid, mp->uuid,
-                                  sizeof(target->uuid)) == 0) {
+                                  sizeof(target->uuid)) == 0 &&
+                           sra->array.failed_disks > 0) {
                                /* This is our target!! */
                                if (chosen)
                                        sysfs_free(chosen);
@@ -986,6 +933,16 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                                goto next;
                }
 
+               dl = domain_from_array(sra, 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"
+                                       " it is not in a compatible domain\n",
+                                       devname, mp->path);
+
+                       goto next;
+               }
                /* all tests passed, OK to add to this array */
                if (!chosen) {
                        chosen = sra;
@@ -1020,7 +977,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                        close(dfd);
                        *dfdp = -1;
                        rv =  Manage_subdevs(chosen->sys_name, mdfd, &devlist,
-                                            -1, 0, NULL);
+                                            -1, 0, NULL, 0);
                        close(mdfd);
                }
                if (verbose > 0) {
@@ -1033,6 +990,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                }
                sysfs_free(chosen);
        }
+       map_unlock(&map);
        return rv;
 }
 
@@ -1059,7 +1017,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
        DIR *dir;
        struct dirent *de;
        char *chosen = NULL;
-       unsigned long long chosen_size;
+       unsigned long long chosen_size = 0;
        struct supertype *chosen_st = NULL;
        int fd;
 
@@ -1093,14 +1051,17 @@ 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;
 
                domain_free(domlist);
                domlist = NULL;
 
-               asprintf(&devname, "/dev/disk/by-path/%s", de->d_name);
+               if (asprintf(&devname, "/dev/disk/by-path/%s", de->d_name) != 1) {
+                       devname = NULL;
+                       goto next;
+               }
                fd = open(devname, O_RDONLY);
                if (fd < 0)
                        goto next;
@@ -1119,7 +1080,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))
@@ -1166,6 +1127,8 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                        close(fd);
        }
 
+       closedir(dir);
+
        if (!chosen)
                return 1;
 
@@ -1366,6 +1329,7 @@ int IncrementalScan(int verbose)
                                        strerror(errno));
                                rv = 1;
                        }
+                       sysfs_free(sra);
                }
        }
        return rv;
@@ -1398,7 +1362,7 @@ static char *container2devname(char *devname)
 
 static int Incremental_container(struct supertype *st, char *devname,
                                 char *homehost, int verbose,
-                                int runstop, int autof)
+                                int runstop, int autof, int freeze_reshape)
 {
        /* Collect the contents of this container and for each
         * array, choose a device name and assemble the array.
@@ -1411,8 +1375,13 @@ 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;
+       int ra_blocked = 0;
+       int ra_all = 0;
 
-       memset(&info, 0, sizeof(info));
        st->ss->getinfo_super(st, &info, NULL);
 
        if ((runstop > 0 && info.container_enough >= 0) ||
@@ -1424,7 +1393,7 @@ static int Incremental_container(struct supertype *st, char *devname,
                return 0;
        }
 
-       match = search_mdstat(st, &info, devname, verbose, &rv);
+       match = conf_match(st, &info, devname, verbose, &rv);
        if (match == NULL && rv == 2)
                return rv;
 
@@ -1439,22 +1408,23 @@ static int Incremental_container(struct supertype *st, char *devname,
                trustworthy = FOREIGN;
 
        list = st->ss->container_content(st, NULL);
-       if (map_lock(&map))
-               fprintf(stderr, Name ": failed to get exclusive lock on "
-                       "mapfile\n");
-       /* do not assemble arrays that might have bad blocks */
-       if (list->array.state & (1<<MD_SB_BBM_ERRORS)) {
-               fprintf(stderr, Name ": BBM log found in metadata. "
-                                       "Cannot activate array(s).\n");
-               list = NULL;
-       }
-
+       /* when nothing to activate - quit */
+       if (list == NULL)
+               return 0;
        for (ra = list ; ra ; ra = ra->next) {
                int mdfd;
                char chosen_name[1024];
                struct map_ent *mp;
                struct mddev_ident *match = NULL;
 
+               ra_all++;
+               /* do not activate arrays blocked by metadata handler */
+               if (ra->array.state & (1 << MD_SB_BLOCK_VOLUME)) {
+                       fprintf(stderr, Name ": Cannot activate array %s in %s.\n",
+                               ra->text_version, devname);
+                       ra_blocked++;
+                       continue;
+               }
                mp = map_by_uuid(&map, ra->uuid);
 
                if (mp) {
@@ -1528,9 +1498,61 @@ static int Incremental_container(struct supertype *st, char *devname,
                }
 
                assemble_container_content(st, mdfd, ra, runstop,
-                                          chosen_name, verbose);
+                                          chosen_name, verbose, NULL,
+                                          freeze_reshape);
+               close(mdfd);
        }
-       map_unlock(&map);
+
+       /* don't move spares to container with volume being activated
+          when all volumes are blocked */
+       if (ra_all == ra_blocked)
+               return 0;
+
+       /* 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);
        return 0;
 }
 
@@ -1596,15 +1618,15 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
                                if (subfd >= 0) {
                                        Manage_subdevs(memb->dev, subfd,
                                                       &devlist, verbose, 0,
-                                                      NULL);
+                                                      NULL, 0);
                                        close(subfd);
                                }
                        }
                free_mdstat(mdstat);
        } else
-               Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0, NULL);
+               Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0, NULL, 0);
        devlist.disposition = 'r';
-       rv = Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0, NULL);
+       rv = Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0, NULL, 0);
        close(mdfd);
        free_mdstat(ent);
        return rv;