]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
super-intel: Simplify for() loop in ahci_enumerate_ports
[thirdparty/mdadm.git] / Incremental.c
index 5b2974c384f66eaad17a18f8f34ce9e291a4c674..ba97b008187975681fb2dd65b4378878f2a735ea 100644 (file)
@@ -35,7 +35,7 @@
 
 static int count_active(struct supertype *st, struct mdinfo *sra,
                        int mdfd, char **availp,
-                       struct mdinfo *info, int *journal_device_missing);
+                       struct mdinfo *info);
 static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
                        int number, __u64 events, int verbose,
                        char *array_name);
@@ -444,6 +444,10 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                /* add disk needs to know about containers */
                if (st->ss->external)
                        sra->array.level = LEVEL_CONTAINER;
+
+               if (info.array.state & (1 << MD_SB_CLUSTERED))
+                       info.disk.state |= (1 << MD_DISK_CLUSTER_ADD);
+
                err = add_disk(mdfd, st, sra, &info);
                if (err < 0 && errno == EBUSY) {
                        /* could be another device present with the same
@@ -520,7 +524,10 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        sysfs_free(sra);
        sra = sysfs_read(mdfd, NULL, (GET_DEVS | GET_STATE |
                                    GET_OFFSET | GET_SIZE));
-       active_disks = count_active(st, sra, mdfd, &avail, &info, &journal_device_missing);
+       active_disks = count_active(st, sra, mdfd, &avail, &info);
+
+       journal_device_missing = (info.journal_device_required) && (info.journal_clean == 0);
+
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
                   avail) == 0) {
@@ -637,8 +644,7 @@ out:
                close(mdfd);
        if (policy)
                dev_policy_free(policy);
-       if (sra)
-               sysfs_free(sra);
+       sysfs_free(sra);
        return rv;
 out_unlock:
        map_unlock(&map);
@@ -660,7 +666,7 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
                         * without thinking more */
 
        for (d = sra->devs; d ; d = d->next) {
-               char dn[10];
+               char dn[24]; // 2*11 bytes for ints (including sign) + colon + null byte
                int dfd;
                struct mdinfo info;
                sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
@@ -690,8 +696,7 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
 
 static int count_active(struct supertype *st, struct mdinfo *sra,
                        int mdfd, char **availp,
-                       struct mdinfo *bestinfo,
-                       int *journal_device_missing)
+                       struct mdinfo *bestinfo)
 {
        /* count how many devices in sra think they are active */
        struct mdinfo *d;
@@ -705,8 +710,6 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
        int devnum;
        int b, i;
        int raid_disks = 0;
-       int require_journal_dev = 0;
-       int has_journal_dev = 0;
 
        if (!sra)
                return 0;
@@ -728,18 +731,10 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                if (ok != 0)
                        continue;
 
-               if (st->ss->require_journal) {
-                       require_journal_dev = st->ss->require_journal(st);
-                       if (require_journal_dev == 2) {
-                               pr_err("BUG: Superblock not loaded in Incremental.c:count_active\n");
-                               return 0;
-                       }
-               }
-
                info.array.raid_disks = raid_disks;
                st->ss->getinfo_super(st, &info, devmap + raid_disks * devnum);
                if (info.disk.raid_disk == MD_DISK_ROLE_JOURNAL)
-                       has_journal_dev = 1;
+                       bestinfo->journal_clean = 1;
                if (!avail) {
                        raid_disks = info.array.raid_disks;
                        avail = xcalloc(raid_disks, 1);
@@ -790,9 +785,6 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                st->ss->free_super(st);
        }
 
-       if (require_journal_dev && !has_journal_dev)
-               *journal_device_missing = 1;
-
        if (!avail)
                return 0;
        /* We need to reject any device that thinks the best device is
@@ -996,8 +988,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                                   sizeof(target->uuid)) == 0 &&
                            sra->array.failed_disks > 0) {
                                /* This is our target!! */
-                               if (chosen)
-                                       sysfs_free(chosen);
+                               sysfs_free(chosen);
                                chosen = sra;
                                sra = NULL;
                                /* skip to end so we don't check any more */
@@ -1029,8 +1020,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                        sra = NULL;
                }
        next:
-               if (sra)
-                       sysfs_free(sra);
+               sysfs_free(sra);
                if (st != st2)
                        free(st2);
                if (dl)
@@ -1041,12 +1031,12 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                int mdfd = open_dev(chosen->sys_name);
                if (mdfd >= 0) {
                        struct mddev_dev devlist;
-                       char devname[20];
+                       char chosen_devname[24]; // 2*11 for int (including signs) + colon + null
                        devlist.next = NULL;
                        devlist.used = 0;
                        devlist.writemostly = 0;
-                       devlist.devname = devname;
-                       sprintf(devname, "%d:%d", major(stb.st_rdev),
+                       devlist.devname = chosen_devname;
+                       sprintf(chosen_devname, "%d:%d", major(stb.st_rdev),
                                minor(stb.st_rdev));
                        devlist.disposition = 'a';
                        close(dfd);