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>
This commit is contained in:
NeilBrown 2012-10-31 17:02:42 +11:00
parent bde085f411
commit 75a410f622
1 changed files with 14 additions and 2 deletions

View 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;