]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Incremental: allow recently removed device to be added as a spare.
authorNeilBrown <neilb@suse.de>
Wed, 31 Oct 2012 06:02:42 +0000 (17:02 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 20 Nov 2012 01:08:16 +0000 (12:08 +1100)
Currently, action=force-spare isn't effective at all as I'm not
sure what is really sensible.
This patch allows a device that was part of an array, but has been
removed, to be added as a spare of passed to --incremental while
force-spare is active.

If it is can be re-added, that done first.  If it fails, we add it as
a spare.

Signed-off-by: NeilBrown <neilb@suse.de>
Incremental.c

index bc23a885d5e404358646eb2f4a5b0c8d35b40336..19e4a1ecb12d81abc3dbc948816f8a95222ffc48 100644 (file)
@@ -317,7 +317,7 @@ int Incremental(char *devname, struct context *c,
                dinfo.disk.major = major(stb.st_rdev);
                dinfo.disk.minor = minor(stb.st_rdev);
                if (add_disk(mdfd, st, &info, &dinfo) != 0) {
-                       pr_err("failed to add %s to %s: %s.\n",
+                       pr_err("failed to add %s to new array %s: %s.\n",
                                devname, chosen_name, strerror(errno));
                        ioctl(mdfd, STOP_ARRAY, 0);
                        rv = 2;
@@ -433,8 +433,20 @@ int Incremental(char *devname, struct context *c,
                                    info.events, c->verbose, chosen_name);
                        err = add_disk(mdfd, st, sra, &info);
                }
+               if (err < 0 && errno == EINVAL &&
+                   info.disk.state & (1<<MD_DISK_SYNC)) {
+                       /* Maybe it needs to be added as a spare */
+                       if (policy_action_allows(policy, st->ss->name,
+                                                act_force_spare)) {
+                               info.disk.state &= ~(1<<MD_DISK_SYNC);
+                               err = add_disk(mdfd, st, sra, &info);
+                       } else
+                               if (c->verbose >= 0)
+                                       pr_err("can only add %s to %s as a spare, and force-spare is not set.\n",
+                                              devname, chosen_name);
+               }
                if (err < 0) {
-                       pr_err("failed to add %s to %s: %s.\n",
+                       pr_err("failed to add %s to existing array %s: %s.\n",
                                devname, chosen_name, strerror(errno));
                        rv = 2;
                        goto out_unlock;