summaryrefslogtreecommitdiff
path: root/Incremental.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-10-31 17:02:42 +1100
committerNeilBrown <neilb@suse.de>2012-11-20 12:08:16 +1100
commit75a410f6226d1e3ef441bbb8cd4f198d5de5cf5b (patch)
tree551d0622cf714e319d75d773afe627691810e11c /Incremental.c
parentbde085f411acfc236fc06f074ffb7ccfe4f836b3 (diff)
Incremental: allow recently removed device to be added as a spare.
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>
Diffstat (limited to 'Incremental.c')
-rw-r--r--Incremental.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/Incremental.c b/Incremental.c
index bc23a885..19e4a1ec 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -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;