linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mwilck@arcor.de
To: neilb@suse.de, linux-raid@vger.kernel.org
Cc: mwilck@arcor.de
Subject: [PATCH 2/4] DDF: ddf_activate_spare: Add RAID10 code
Date: Thu, 25 Jul 2013 20:59:11 +0200	[thread overview]
Message-ID: <1374778753-6252-3-git-send-email-mwilck@arcor.de> (raw)
In-Reply-To: <1374778753-6252-1-git-send-email-mwilck@arcor.de>

The check for degraded array is a bit more complex for RAID10.
Fixing it.
---
 super-ddf.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/super-ddf.c b/super-ddf.c
index ac30e4e..13a2e61 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -4655,6 +4655,55 @@ static void ddf_prepare_update(struct supertype *st,
 }
 
 /*
+ * Check degraded state of a RAID10.
+ * returns 2 for good, 1 for degraded, 0 for failed, and -1 for error
+ */
+static int raid10_degraded(struct mdinfo *info)
+{
+	int n_prim, n_bvds;
+	int i;
+	struct mdinfo *d, *sra;
+	char *found;
+	int ret = -1;
+
+	if (info->array.layout == 0) {
+		sra = sysfs_read(-1, info->sys_name, GET_LAYOUT);
+		info->array.layout = sra->array.layout;
+		free(sra);
+	}
+
+	n_prim = info->array.layout & ~0x100;
+	n_bvds = info->array.raid_disks / n_prim;
+	found = xmalloc(n_bvds);
+	if (found == NULL)
+		return ret;
+	memset(found, 0, n_bvds);
+	for (d = info->devs; d; d = d->next) {
+		i = d->disk.raid_disk / n_prim;
+		if (i >= n_bvds) {
+			pr_err("%s: BUG: invalid raid disk\n", __func__);
+			goto out;
+		}
+		if (d->state_fd > 0)
+			found[i]++;
+	}
+	ret = 2;
+	for (i = 0; i < n_bvds; i++)
+		if (!found[i]) {
+			dprintf("%s: BVD %d/%d failed\n", __func__, i, n_bvds);
+			ret = 0;
+			goto out;
+		} else if (found[i] < n_prim) {
+			dprintf("%s: BVD %d/%d degraded\n", __func__, i,
+				n_bvds);
+			ret = 1;
+		}
+out:
+	free(found);
+	return ret;
+}
+
+/*
  * Check if the array 'a' is degraded but not failed.
  * If it is, find as many spares as are available and needed and
  * arrange for their inclusion.
@@ -4694,7 +4743,7 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
 			working ++;
 	}
 
-	dprintf("ddf_activate: working=%d (%d) level=%d\n", working,
+	dprintf("%s: working=%d (%d) level=%d\n", __func__, working,
 		a->info.array.raid_disks,
 		a->info.array.level);
 	if (working == a->info.array.raid_disks)
@@ -4713,6 +4762,10 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
 		if (working < a->info.array.raid_disks - 2)
 			return NULL; /* failed */
 		break;
+	case 10:
+		if (raid10_degraded(&a->info) < 1)
+			return NULL;
+		break;
 	default: /* concat or stripe */
 		return NULL; /* failed */
 	}
-- 
1.7.1

  parent reply	other threads:[~2013-07-25 18:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25 18:59 [PATCH 0/4] Basic hotspare handling for RAID10 mwilck
2013-07-25 18:59 ` [PATCH 1/4] DDF: find_vdcr: fix minor bug in debug message mwilck
2013-07-25 18:59 ` mwilck [this message]
2013-07-25 18:59 ` [PATCH 3/4] DDF: ddf_activate_spare: only activate good drives mwilck
2013-07-25 18:59 ` [PATCH 4/4] DDF: ddf_activate_spare: fix metadata update for SVDs mwilck
2013-07-30  1:22 ` [PATCH 0/4] Basic hotspare handling for RAID10 NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1374778753-6252-3-git-send-email-mwilck@arcor.de \
    --to=mwilck@arcor.de \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).