]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
Check write journal in incremental
[thirdparty/mdadm.git] / Incremental.c
index 13b68bc0adea3fb86038fd7f1d4d13dcab0a1b90..5b2974c384f66eaad17a18f8f34ce9e291a4c674 100644 (file)
@@ -35,7 +35,7 @@
 
 static int count_active(struct supertype *st, struct mdinfo *sra,
                        int mdfd, char **availp,
-                       struct mdinfo *info);
+                       struct mdinfo *info, int *journal_device_missing);
 static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
                        int number, __u64 events, int verbose,
                        char *array_name);
@@ -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,16 +131,13 @@ 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);
 
                close(dfd);
                if (!rv && st->ss->container_content) {
                        if (map_lock(&map))
-                               pr_err("failed to get "
-                                      "exclusive lock on mapfile\n");
+                               pr_err("failed to get exclusive lock on mapfile\n");
                        if (c->export)
                                printf("MD_DEVNAME=%s\n", devname);
                        rv = Incremental_container(st, devname, c, NULL);
@@ -205,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);
@@ -229,8 +228,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        if (match && match->devname
            && strcasecmp(match->devname, "<ignore>") == 0) {
                if (c->verbose >= 0)
-                       pr_err("array containing %s is explicitly"
-                               " ignored by mdadm.conf\n",
+                       pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
                                devname);
                goto out;
        }
@@ -251,8 +249,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        if (!match && !conf_test_metadata(st->ss->name, policy,
                                          (trustworthy == LOCAL))) {
                if (c->verbose >= 1)
-                       pr_err("%s has metadata type %s for which "
-                              "auto-assembly is disabled\n",
+                       pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
                               devname, st->ss->name);
                goto out;
        }
@@ -289,8 +286,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
        /* 4/ Check if array exists.
         */
        if (map_lock(&map))
-               pr_err("failed to get exclusive lock on "
-                       "mapfile\n");
+               pr_err("failed to get exclusive lock on mapfile\n");
        /* Now check we can get O_EXCL.  If not, probably "mdadm -A" has
         * taken over
         */
@@ -317,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);
@@ -352,8 +354,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                         * So reject it.
                         */
                        ioctl(mdfd, STOP_ARRAY, NULL);
-                       pr_err("You have an old buggy kernel which cannot support\n"
-                              "      --incremental reliably.  Aborting.\n");
+                       pr_err("You have an old buggy kernel which cannot support\n      --incremental reliably.  Aborting.\n");
                        rv = 2;
                        goto out_unlock;
                }
@@ -420,8 +421,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                        st2 = dup_super(st);
                        if (st2->ss->load_super(st2, dfd2, NULL) ||
                            st->ss->compare_super(st, st2) != 0) {
-                               pr_err("metadata mismatch between %s and "
-                                      "chosen array %s\n",
+                               pr_err("metadata mismatch between %s and chosen array %s\n",
                                       devname, chosen_name);
                                close(dfd2);
                                rv = 2;
@@ -520,7 +520,7 @@ 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);
+       active_disks = count_active(st, sra, mdfd, &avail, &info, &journal_device_missing);
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
                   avail) == 0) {
@@ -550,10 +550,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);
@@ -620,6 +622,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);
@@ -686,7 +690,8 @@ 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)
+                       struct mdinfo *bestinfo,
+                       int *journal_device_missing)
 {
        /* count how many devices in sra think they are active */
        struct mdinfo *d;
@@ -700,6 +705,8 @@ 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;
@@ -720,8 +727,19 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                close(dfd);
                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;
                if (!avail) {
                        raid_disks = info.array.raid_disks;
                        avail = xcalloc(raid_disks, 1);
@@ -771,6 +789,10 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
                        replcnt++;
                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
@@ -864,8 +886,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
         */
 
        if (map_lock(&map)) {
-               pr_err("failed to get exclusive lock on "
-                       "mapfile\n");
+               pr_err("failed to get exclusive lock on mapfile\n");
                return 1;
        }
        for (mp = map ; mp ; mp = mp->next) {
@@ -911,8 +932,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                                        sra->text_version);
                        if (!st2) {
                                if (verbose > 1)
-                                       pr_err("not adding %s to %s"
-                                               " as metadata not recognised.\n",
+                                       pr_err("not adding %s to %s as metadata not recognised.\n",
                                                devname, mp->path);
                                goto next;
                        }
@@ -994,8 +1014,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                if (domain_test(dl, pol, st2->ss->name) != 1) {
                        /* domain test fails */
                        if (verbose > 1)
-                               pr_err("not adding %s to %s as"
-                                       " it is not in a compatible domain\n",
+                               pr_err("not adding %s to %s as it is not in a compatible domain\n",
                                        devname, mp->path);
 
                        goto next;
@@ -1132,6 +1151,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 */
@@ -1267,8 +1287,7 @@ static int try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                    !policy_action_allows(pol, st?st->ss->name:NULL,
                                          act_spare_same_slot)) {
                        if (verbose > 1)
-                               pr_err("%s is not bare, so not "
-                                       "considering as a spare\n",
+                               pr_err("%s is not bare, so not considering as a spare\n",
                                        devname);
                        return 1;
                }
@@ -1359,12 +1378,11 @@ 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);
-                       if (!ret && st->ss->container_content) {
+                       if (!ret && st && st->ss->container_content) {
                                if (map_lock(&map))
                                        pr_err("failed to get exclusive lock on mapfile\n");
                                ret = Incremental_container(st, me->path, c, only);
@@ -1576,8 +1594,7 @@ static int Incremental_container(struct supertype *st, char *devname,
                        if (match && match->devname &&
                            strcasecmp(match->devname, "<ignore>") == 0) {
                                if (c->verbose > 0)
-                                       pr_err("array %s/%s is "
-                                              "explicitly ignored by mdadm.conf\n",
+                                       pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
                                               match->container, match->member);
                                continue;
                        }
@@ -1710,34 +1727,34 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
        char buf[32];
 
        if (!id_path)
-               dprintf(Name ": incremental removal without --path <id_path> "
-                       "lacks the possibility to re-add new device in this "
-                       "port\n");
+               dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
 
        if (strchr(devname, '/')) {
-               pr_err("incremental removal requires a "
-                       "kernel device name, not a file: %s\n", devname);
+               pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname);
                return 1;
        }
        ent = mdstat_by_component(devname);
        if (!ent) {
                if (verbose >= 0)
-                       pr_err("%s does not appear to be a component "
-                              "of any array\n", devname);
+                       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_get_str(&mdi, NULL, "array_state",
-                         buf, sizeof(buf)) > 0) {
-               if (strncmp(buf, "active", 6) == 0 ||
-                   strncmp(buf, "clean", 5) == 0)
-                       sysfs_set_str(&mdi, NULL,
-                                     "array_state", "read-auto");
+       mdfd = open_dev_excl(ent->devnm);
+       if (mdfd > 0) {
+               close(mdfd);
+               if (sysfs_get_str(&mdi, NULL, "array_state",
+                                 buf, sizeof(buf)) > 0) {
+                       if (strncmp(buf, "active", 6) == 0 ||
+                           strncmp(buf, "clean", 5) == 0)
+                               sysfs_set_str(&mdi, NULL,
+                                             "array_state", "read-auto");
+               }
        }
        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;
        }
@@ -1759,11 +1776,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);
@@ -1771,7 +1788,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.
@@ -1779,7 +1796,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");
@@ -1789,7 +1806,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);