]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
imsm: fix: correct adding and activation of spare disks
[thirdparty/mdadm.git] / Incremental.c
index f576cbae35b1d8669b9bad2eb3937105caac9134..b90089bb39210d960b27a664dcbaa84623a6b05d 100644 (file)
@@ -44,7 +44,8 @@ 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);
+                                int verbose, int runstop, int autof,
+                                int freeze_reshape);
 
 static struct mddev_ident *search_mdstat(struct supertype *st,
                                           struct mdinfo *info,
@@ -53,7 +54,7 @@ static struct mddev_ident *search_mdstat(struct supertype *st,
 
 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.
@@ -140,7 +141,8 @@ int Incremental(char *devname, int verbose, int runstop,
                close(dfd);
                if (!rv && st->ss->container_content)
                        return Incremental_container(st, devname, homehost,
-                                                    verbose, runstop, autof);
+                                                    verbose, runstop, autof,
+                                                    freeze_reshape);
 
                fprintf(stderr, Name ": %s is not part of an md array.\n",
                        devname);
@@ -450,7 +452,8 @@ int Incremental(char *devname, int verbose, int runstop,
                close(mdfd);
                sysfs_free(sra);
                rv = Incremental(chosen_name, verbose, runstop,
-                                NULL, homehost, require_homehost, autof);
+                                NULL, homehost, require_homehost, autof,
+                                freeze_reshape);
                if (rv == 1)
                        /* Don't fail the whole -I if a subarray didn't
                         * have enough devices to start yet
@@ -705,7 +708,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;
@@ -776,9 +779,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);
                        }
                }
@@ -1034,7 +1038,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) {
@@ -1415,7 +1419,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.
@@ -1463,11 +1467,12 @@ static int Incremental_container(struct supertype *st, char *devname,
                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)) {
+       if (list && list->array.state & (1<<MD_SB_BBM_ERRORS)) {
                fprintf(stderr, Name ": BBM log found in metadata. "
                                        "Cannot activate array(s).\n");
                /* free container data and exit */
                sysfs_free(list);
+               map_unlock(&map);
                return 2;
        }
 
@@ -1531,6 +1536,7 @@ static int Incremental_container(struct supertype *st, char *devname,
                                        fprintf(stderr, Name ": array %s/%s is "
                                                "explicitly ignored by mdadm.conf\n",
                                                match->container, match->member);
+                               map_unlock(&map);
                                return 2;
                        }
                        if (match)
@@ -1546,11 +1552,13 @@ static int Incremental_container(struct supertype *st, char *devname,
                if (mdfd < 0) {
                        fprintf(stderr, Name ": failed to open %s: %s.\n",
                                chosen_name, strerror(errno));
+                       map_unlock(&map);
                        return 2;
                }
 
                assemble_container_content(st, mdfd, ra, runstop,
-                                          chosen_name, verbose, NULL);
+                                          chosen_name, verbose, NULL,
+                                          freeze_reshape);
                close(mdfd);
        }
 
@@ -1665,15 +1673,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;