]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
Fix test for imsm prodigal member scenario
[thirdparty/mdadm.git] / Incremental.c
index 7f67535bee724075361e2a9bb5c5a5e1d35f909b..a8a072d438b209212b4b3299908c5e556944ac35 100644 (file)
@@ -294,7 +294,9 @@ int Incremental(char *devname, int verbose, int runstop,
 
        /* 4/ Check if array exists.
         */
-       map_lock(&map);
+       if (map_lock(&map))
+               fprintf(stderr, Name ": failed to get exclusive lock on "
+                       "mapfile\n");
        mp = map_by_uuid(&map, info.uuid);
        if (mp)
                mdfd = open_dev(mp->devnum);
@@ -376,7 +378,16 @@ int Incremental(char *devname, int verbose, int runstop,
                 * statement about this.
                 */
                if (runstop < 1) {
-                       if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
+                       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) {
                                fprintf(stderr, Name
                                        ": not adding %s to active array (without --run) %s\n",
                                        devname, chosen_name);
@@ -385,6 +396,8 @@ int Incremental(char *devname, int verbose, int runstop,
                        }
                }
                sra = sysfs_read(mdfd, fd2devnum(mdfd), (GET_DEVS | GET_STATE));
+               if (!sra)
+                       return 2;
 
                if (sra->devs) {
                        sprintf(dn, "%d:%d", sra->devs->disk.major,
@@ -602,6 +615,9 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
        struct mdinfo *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
        char *avail = NULL;
 
+       if (!sra)
+               return 0;
+
        for (d = sra->devs ; d ; d = d->next) {
                char dn[30];
                int dfd;
@@ -779,7 +795,9 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
        struct mdinfo *ra;
        struct map_ent *map = NULL;
 
-       map_lock(&map);
+       if (map_lock(&map))
+               fprintf(stderr, Name ": failed to get exclusive lock on "
+                       "mapfile\n");
 
        for (ra = list ; ra ; ra = ra->next) {
                int mdfd;
@@ -878,6 +896,7 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
 int IncrementalRemove(char *devname, int verbose)
 {
        int mdfd;
+       int rv;
        struct mdstat_ent *ent;
        struct mddev_dev_s devlist;
 
@@ -900,7 +919,9 @@ int IncrementalRemove(char *devname, int verbose)
        memset(&devlist, 0, sizeof(devlist));
        devlist.devname = devname;
        devlist.disposition = 'f';
-       Manage_subdevs(ent->dev, mdfd, &devlist, verbose);
+       Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0);
        devlist.disposition = 'r';
-       return Manage_subdevs(ent->dev, mdfd, &devlist, verbose);
+       rv = Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0);
+       close(mdfd);
+       return rv;
 }