From 75a410f6226d1e3ef441bbb8cd4f198d5de5cf5b Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 31 Oct 2012 17:02:42 +1100 Subject: [PATCH] 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 --- Incremental.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Incremental.c b/Incremental.c index bc23a88..19e4a1e 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<ss->name, + act_force_spare)) { + info.disk.state &= ~(1<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;