linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Basic hotspare handling for RAID10
@ 2013-07-25 18:59 mwilck
  2013-07-25 18:59 ` [PATCH 1/4] DDF: find_vdcr: fix minor bug in debug message mwilck
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mwilck @ 2013-07-25 18:59 UTC (permalink / raw)
  To: neilb, linux-raid; +Cc: mwilck

This patch set contains a minor bug fix and code to make --fail/--add
work with DDF/RAID10.

Martin Wilck (4):
  DDF: find_vdcr: fix minor bug in debug message
  DDF: ddf_activate_spare: Add RAID10 code
  DDF: ddf_activate_spare: only activate good drives
  DDF: ddf_activate_spare: fix metadata update for SVDs

 super-ddf.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 95 insertions(+), 12 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] DDF: find_vdcr: fix minor bug in debug message
  2013-07-25 18:59 [PATCH 0/4] Basic hotspare handling for RAID10 mwilck
@ 2013-07-25 18:59 ` mwilck
  2013-07-25 18:59 ` [PATCH 2/4] DDF: ddf_activate_spare: Add RAID10 code mwilck
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mwilck @ 2013-07-25 18:59 UTC (permalink / raw)
  To: neilb, linux-raid; +Cc: mwilck

This code could find disk -1. Fixed.
---
 super-ddf.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/super-ddf.c b/super-ddf.c
index ae6cdf4..ac30e4e 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -1731,7 +1731,7 @@ static struct vd_config *find_vdcr(struct ddf_super *ddf, unsigned int inst,
 	struct vcl *v;
 
 	for (v = ddf->conflist; v; v = v->next) {
-		unsigned int nsec, ibvd;
+		unsigned int nsec, ibvd = 0;
 		struct vd_config *conf;
 		if (inst != v->vcnum)
 			continue;
@@ -1763,7 +1763,7 @@ static struct vd_config *find_vdcr(struct ddf_super *ddf, unsigned int inst,
 				       n - nsec*conf->sec_elmnt_count, n_bvd))
 			goto bad;
 		dprintf("%s: found disk %u as member %u in bvd %d of array %u\n"
-			, __func__, n, *n_bvd, ibvd-1, inst);
+			, __func__, n, *n_bvd, ibvd, inst);
 		*vcl = v;
 		return conf;
 	}
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] DDF: ddf_activate_spare: Add RAID10 code
  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
  2013-07-25 18:59 ` [PATCH 3/4] DDF: ddf_activate_spare: only activate good drives mwilck
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mwilck @ 2013-07-25 18:59 UTC (permalink / raw)
  To: neilb, linux-raid; +Cc: mwilck

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] DDF: ddf_activate_spare: only activate good drives
  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 ` [PATCH 2/4] DDF: ddf_activate_spare: Add RAID10 code mwilck
@ 2013-07-25 18:59 ` 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
  4 siblings, 0 replies; 6+ messages in thread
From: mwilck @ 2013-07-25 18:59 UTC (permalink / raw)
  To: neilb, linux-raid; +Cc: mwilck

Do not try to activate drives marked missing or failed.
---
 super-ddf.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/super-ddf.c b/super-ddf.c
index 13a2e61..ae1222c 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -4773,6 +4773,13 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
 	/* For each slot, if it is not working, find a spare */
 	dl = ddf->dlist;
 	for (i = 0; i < a->info.array.raid_disks; i++) {
+		be16 state = ddf->phys->entries[dl->pdnum].state;
+		if (be16_and(state,
+			     cpu_to_be16(DDF_Failed|DDF_Missing)) ||
+		    !be16_and(state,
+			      cpu_to_be16(DDF_Online)))
+			continue;
+
 		for (d = a->info.devs ; d ; d = d->next)
 			if (d->disk.raid_disk == i)
 				break;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] DDF: ddf_activate_spare: fix metadata update for SVDs
  2013-07-25 18:59 [PATCH 0/4] Basic hotspare handling for RAID10 mwilck
                   ` (2 preceding siblings ...)
  2013-07-25 18:59 ` [PATCH 3/4] DDF: ddf_activate_spare: only activate good drives mwilck
@ 2013-07-25 18:59 ` mwilck
  2013-07-30  1:22 ` [PATCH 0/4] Basic hotspare handling for RAID10 NeilBrown
  4 siblings, 0 replies; 6+ messages in thread
From: mwilck @ 2013-07-25 18:59 UTC (permalink / raw)
  To: neilb, linux-raid; +Cc: mwilck

Metadata updates for secondary RAID (RAID10) need to cover
all BVDs. Compare with code in write_init_super_ddf().
---
 super-ddf.c |   41 ++++++++++++++++++++++++++++++++---------
 1 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/super-ddf.c b/super-ddf.c
index ae1222c..47074fe 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -4730,6 +4730,7 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
 	struct metadata_update *mu;
 	struct dl *dl;
 	int i;
+	unsigned int j;
 	struct vcl *vcl;
 	struct vd_config *vc;
 	unsigned int n_bvd;
@@ -4902,26 +4903,48 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
 	 * Create a metadata_update record to update the
 	 * phys_refnum and lba_offset values
 	 */
+	vc = find_vdcr(ddf, a->info.container_member, di->disk.raid_disk,
+		       &n_bvd, &vcl);
+	if (vc == NULL)
+		return NULL;
+
 	mu = xmalloc(sizeof(*mu));
 	if (posix_memalign(&mu->space, 512, sizeof(struct vcl)) != 0) {
 		free(mu);
 		mu = NULL;
 	}
-	mu->buf = xmalloc(ddf->conf_rec_len * 512);
-	mu->len = ddf->conf_rec_len * 512;
+
+	mu->len = ddf->conf_rec_len * 512 * vcl->conf.sec_elmnt_count;
+	mu->buf = xmalloc(mu->len);
 	mu->space = NULL;
 	mu->space_list = NULL;
 	mu->next = *updates;
-	vc = find_vdcr(ddf, a->info.container_member, di->disk.raid_disk,
-		       &n_bvd, &vcl);
-	memcpy(mu->buf, vc, ddf->conf_rec_len * 512);
+	memcpy(mu->buf, &vcl->conf, ddf->conf_rec_len * 512);
+	for (j = 1; j < vcl->conf.sec_elmnt_count; j++)
+		memcpy(mu->buf + j * ddf->conf_rec_len * 512,
+		       vcl->other_bvds[j-1], ddf->conf_rec_len * 512);
 
 	vc = (struct vd_config*)mu->buf;
 	for (di = rv ; di ; di = di->next) {
-		vc->phys_refnum[di->disk.raid_disk] =
-			ddf->phys->entries[dl->pdnum].refnum;
-		LBA_OFFSET(ddf, vc)[di->disk.raid_disk]
-			= cpu_to_be64(di->data_offset);
+		unsigned int i_sec, i_prim;
+		i_sec = di->disk.raid_disk
+			/ be16_to_cpu(vcl->conf.prim_elmnt_count);
+		i_prim = di->disk.raid_disk
+			% be16_to_cpu(vcl->conf.prim_elmnt_count);
+		vc = (struct vd_config *)(mu->buf
+					  + i_sec * ddf->conf_rec_len * 512);
+		for (dl = ddf->dlist; dl; dl = dl->next)
+			if (dl->major == di->disk.major
+			    && dl->minor == di->disk.minor)
+				break;
+		if (!dl) {
+			pr_err("%s: BUG: can't find disk %d (%d/%d)\n",
+			       __func__, di->disk.raid_disk,
+			       di->disk.major, di->disk.minor);
+			return NULL;
+		}
+		vc->phys_refnum[i_prim] = ddf->phys->entries[dl->pdnum].refnum;
+		LBA_OFFSET(ddf, vc)[i_prim] = cpu_to_be64(di->data_offset);
 	}
 	*updates = mu;
 	return rv;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] Basic hotspare handling for RAID10
  2013-07-25 18:59 [PATCH 0/4] Basic hotspare handling for RAID10 mwilck
                   ` (3 preceding siblings ...)
  2013-07-25 18:59 ` [PATCH 4/4] DDF: ddf_activate_spare: fix metadata update for SVDs mwilck
@ 2013-07-30  1:22 ` NeilBrown
  4 siblings, 0 replies; 6+ messages in thread
From: NeilBrown @ 2013-07-30  1:22 UTC (permalink / raw)
  To: mwilck; +Cc: linux-raid

[-- Attachment #1: Type: text/plain, Size: 577 bytes --]

On Thu, 25 Jul 2013 20:59:09 +0200 mwilck@arcor.de wrote:

> This patch set contains a minor bug fix and code to make --fail/--add
> work with DDF/RAID10.
> 
> Martin Wilck (4):
>   DDF: find_vdcr: fix minor bug in debug message
>   DDF: ddf_activate_spare: Add RAID10 code
>   DDF: ddf_activate_spare: only activate good drives
>   DDF: ddf_activate_spare: fix metadata update for SVDs
> 
>  super-ddf.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
>  1 files changed, 95 insertions(+), 12 deletions(-)

All applied - thanks.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-07-30  1:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/4] DDF: ddf_activate_spare: Add RAID10 code mwilck
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

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).