]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
Query: Remove all references to md_get_version()
[thirdparty/mdadm.git] / Incremental.c
index 0c9a9a4cd922a4586b0cc189e73c72bb2dd6d9e2..28f1f7734956277c371b3d60915c1ff113b754db 100644 (file)
@@ -104,6 +104,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        struct map_ent target_array;
        int have_target;
        char *devname = devlist->devname;
+       int journal_device_missing = 0;
 
        struct createinfo *ci = conf_get_create_info();
 
@@ -130,8 +131,6 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        if (must_be_container(dfd)) {
                if (!st)
                        st = super_by_fd(dfd, NULL);
-               if (st)
-                       st->ignore_hw_compat = 1;
                if (st && st->ss->load_container)
                        rv = st->ss->load_container(st, dfd, NULL);
 
@@ -204,9 +203,10 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                               NULL, c->verbose);
                goto out;
        }
-       st->ignore_hw_compat = 1;
+       st->ignore_hw_compat = 0;
+
        if (st->ss->compare_super == NULL ||
-           st->ss->load_super(st, dfd, NULL)) {
+           st->ss->load_super(st, dfd, c->verbose >= 0 ? devname : NULL)) {
                if (c->verbose >= 0)
                        pr_err("no RAID superblock on %s.\n",
                                devname);
@@ -313,6 +313,12 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
 
        if (mdfd < 0) {
 
+               /* Skip the clustered ones. This should be started by
+                * clustering resource agents
+                */
+               if (info.array.state & (1 << MD_SB_CLUSTERED))
+                       goto out;
+
                /* Couldn't find an existing array, maybe make a new one */
                mdfd = create_mddev(match ? match->devname : NULL,
                                    name_to_use, c->autof, trustworthy, chosen_name);
@@ -320,7 +326,12 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                if (mdfd < 0)
                        goto out_unlock;
 
-               sysfs_init(&info, mdfd, NULL);
+               if (sysfs_init(&info, mdfd, NULL)) {
+                       pr_err("unable to initialize sysfs for %s\n",
+                              chosen_name);
+                       rv = 2;
+                       goto out_unlock;
+               }
 
                if (set_array_info(mdfd, st, &info) != 0) {
                        pr_err("failed to set array info for %s: %s\n",
@@ -392,7 +403,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                    && ! policy_action_allows(policy, st->ss->name,
                                              act_re_add)
                    && c->runstop < 1) {
-                       if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
+                       if (md_get_array_info(mdfd, &ainf) == 0) {
                                pr_err("not adding %s to active array (without --run) %s\n",
                                       devname, chosen_name);
                                rv = 2;
@@ -438,6 +449,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
@@ -515,6 +530,12 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        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 = (info.journal_device_required) && (info.journal_clean == 0);
+
+       if (info.consistency_policy == CONSISTENCY_POLICY_PPL)
+               info.array.state |= 1;
+
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
                   avail) == 0) {
@@ -533,7 +554,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        /*   + add any bitmap file  */
        /*   + start the array (auto-readonly). */
 
-       if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
+       if (md_get_array_info(mdfd, &ainf) == 0) {
                if (c->export) {
                        printf("MD_STARTED=already\n");
                } else if (c->verbose >= 0)
@@ -544,10 +565,12 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        }
 
        map_unlock(&map);
-       if (c->runstop > 0 || active_disks >= info.array.working_disks) {
+       if (c->runstop > 0 || (!journal_device_missing && active_disks >= info.array.working_disks)) {
                struct mdinfo *dsk;
                /* Let's try to start it */
 
+               if (journal_device_missing)
+                       pr_err("Trying to run with missing journal device\n");
                if (info.reshape_active && !(info.reshape_active & RESHAPE_NO_BACKUP)) {
                        pr_err("%s: This array is being reshaped and cannot be started\n",
                               chosen_name);
@@ -614,6 +637,8 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        } else {
                if (c->export) {
                        printf("MD_STARTED=unsafe\n");
+               } else if (journal_device_missing) {
+                       pr_err("Journal device is missing, not safe to start yet.\n");
                } else if (c->verbose >= 0)
                        pr_err("%s attached to %s, not enough to start safely.\n",
                               devname, chosen_name);
@@ -627,8 +652,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);
@@ -645,12 +669,12 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
        struct mdinfo *d;
        mdu_array_info_t ra;
 
-       if (ioctl(mdfd, GET_ARRAY_INFO, &ra) == 0)
+       if (md_get_array_info(mdfd, &ra) == 0)
                return; /* not safe to remove from active arrays
                         * 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);
@@ -714,8 +738,11 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                close(dfd);
                if (ok != 0)
                        continue;
+
                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)
+                       bestinfo->journal_clean = 1;
                if (!avail) {
                        raid_disks = info.array.raid_disks;
                        avail = xcalloc(raid_disks, 1);
@@ -765,6 +792,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                        replcnt++;
                st->ss->free_super(st);
        }
+
        if (!avail)
                return 0;
        /* We need to reject any device that thinks the best device is
@@ -814,7 +842,7 @@ static int container_members_max_degradation(struct map_ent *map, struct map_ent
                if (afd < 0)
                        continue;
                /* most accurate information regarding array degradation */
-               if (ioctl(afd, GET_ARRAY_INFO, &array) >= 0) {
+               if (md_get_array_info(afd, &array) >= 0) {
                        int degraded = array.raid_disks - array.active_disks -
                                       array.spare_disks;
                        if (degraded > max_degraded)
@@ -968,8 +996,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 */
@@ -1001,8 +1028,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)
@@ -1013,12 +1039,13 @@ 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.writemostly = FlagDefault;
+                       devlist.failfast = FlagDefault;
+                       devlist.devname = chosen_devname;
+                       sprintf(chosen_devname, "%d:%d", major(stb.st_rdev),
                                minor(stb.st_rdev));
                        devlist.disposition = 'a';
                        close(dfd);
@@ -1123,6 +1150,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                if (st2 == NULL ||
                    st2->ss->load_super(st2, fd, NULL) < 0)
                        goto next;
+               st2->ignore_hw_compat = 0;
 
                if (!st) {
                        /* Check domain policy again, this time referring to metadata */
@@ -1322,14 +1350,17 @@ int IncrementalScan(struct context *c, char *devnm)
 restart:
        for (me = mapl ; me ; me = me->next) {
                mdu_array_info_t array;
-               mdu_bitmap_file_t bmf;
                struct mdinfo *sra;
                int mdfd;
 
                if (devnm && strcmp(devnm, me->devnm) != 0)
                        continue;
-               if (devnm && me->metadata[0] == '/') {
+               if (me->metadata[0] == '/') {
                        char *sl;
+
+                       if (!devnm)
+                               continue;
+
                        /* member array, need to work on container */
                        strncpy(container, me->metadata+1, 32);
                        container[31] = 0;
@@ -1349,8 +1380,7 @@ restart:
                        struct supertype *st = super_by_fd(mdfd, NULL);
                        int ret = 0;
                        struct map_ent *map = NULL;
-                       if (st)
-                               st->ignore_hw_compat = 1;
+
                        if (st && st->ss->load_container)
                                ret = st->ss->load_container(st, mdfd, NULL);
                        close(mdfd);
@@ -1364,8 +1394,7 @@ restart:
                                rv = 1;
                        continue;
                }
-               if (ioctl(mdfd, GET_ARRAY_INFO, &array) == 0 ||
-                   errno != ENODEV) {
+               if (md_get_array_info(mdfd, &array) == 0 || errno != ENODEV) {
                        close(mdfd);
                        continue;
                }
@@ -1380,13 +1409,12 @@ restart:
                         * is a hint only
                         */
                        int added = -1;
-                       if (ioctl(mdfd, GET_ARRAY_INFO, &bmf) < 0) {
-                               int bmfd = open(mddev->bitmap_file, O_RDWR);
-                               if (bmfd >= 0) {
-                                       added = ioctl(mdfd, SET_BITMAP_FILE,
-                                                     bmfd);
-                                       close(bmfd);
-                               }
+                       int bmfd;
+
+                       bmfd = open(mddev->bitmap_file, O_RDWR);
+                       if (bmfd >= 0) {
+                               added = ioctl(mdfd, SET_BITMAP_FILE, bmfd);
+                               close(bmfd);
                        }
                        if (c->verbose >= 0) {
                                if (added == 0)
@@ -1711,7 +1739,10 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
                        pr_err("%s does not appear to be a component of any array\n", devname);
                return 1;
        }
-       sysfs_init(&mdi, -1, ent->devnm);
+       if (sysfs_init(&mdi, -1, ent->devnm)) {
+               pr_err("unable to initialize sysfs for: %s\n", devname);
+               return 1;
+       }
        mdfd = open_dev_excl(ent->devnm);
        if (mdfd > 0) {
                close(mdfd);
@@ -1726,7 +1757,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
        mdfd = open_dev(ent->devnm);
        if (mdfd < 0) {
                if (verbose >= 0)
-                       pr_err("Cannot open array %s!!\n", ent->dev);
+                       pr_err("Cannot open array %s!!\n", ent->devnm);
                free_mdstat(ent);
                return 1;
        }
@@ -1748,11 +1779,11 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
                struct mdstat_ent *mdstat = mdstat_read(0, 0);
                struct mdstat_ent *memb;
                for (memb = mdstat ; memb ; memb = memb->next)
-                       if (is_container_member(memb, ent->dev)) {
+                       if (is_container_member(memb, ent->devnm)) {
                                int subfd = open_dev(memb->devnm);
                                if (subfd >= 0) {
                                        rv |= Manage_subdevs(
-                                               memb->dev, subfd,
+                                               memb->devnm, subfd,
                                                &devlist, verbose, 0,
                                                NULL, 0);
                                        close(subfd);
@@ -1760,7 +1791,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
                        }
                free_mdstat(mdstat);
        } else
-               rv |= Manage_subdevs(ent->dev, mdfd, &devlist,
+               rv |= Manage_subdevs(ent->devnm, mdfd, &devlist,
                                    verbose, 0, NULL, 0);
        if (rv & 2) {
                /* Failed due to EBUSY, try to stop the array.
@@ -1768,7 +1799,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
                 */
                int devid = devnm2devid(ent->devnm);
                run_udisks("--unmount", map_dev(major(devid),minor(devid), 0));
-               rv = Manage_stop(ent->dev, mdfd, verbose, 1);
+               rv = Manage_stop(ent->devnm, mdfd, verbose, 1);
                if (rv)
                        /* At least we can try to trigger a 'remove' */
                        sysfs_uevent(&mdi, "remove");
@@ -1778,7 +1809,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
                }
        } else {
                devlist.disposition = 'r';
-               rv = Manage_subdevs(ent->dev, mdfd, &devlist,
+               rv = Manage_subdevs(ent->devnm, mdfd, &devlist,
                                    verbose, 0, NULL, 0);
        }
        close(mdfd);