linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Avoid OOPS when reshaping raid1 to raid0
@ 2012-03-26  8:31 Jes.Sorensen
  2012-03-27  3:35 ` NeilBrown
  0 siblings, 1 reply; 3+ messages in thread
From: Jes.Sorensen @ 2012-03-26  8:31 UTC (permalink / raw)
  To: neilb; +Cc: dledford, linux-raid

From: Jes Sorensen <Jes.Sorensen@redhat.com>

raid1 arrays do not have the notion of chunk size. Calculate the
larges chunk sector size we can use to avoid a divide by zero OOPS
when aligning the size of the new array to the chunk size.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 drivers/md/raid0.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 6f31f55..3ac9757 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -625,6 +625,7 @@ static void *raid0_takeover_raid10(struct mddev *mddev)
 static void *raid0_takeover_raid1(struct mddev *mddev)
 {
 	struct r0conf *priv_conf;
+	int chunksect;
 
 	/* Check layout:
 	 *  - (N - 1) mirror drives must be already faulty
@@ -635,10 +636,25 @@ static void *raid0_takeover_raid1(struct mddev *mddev)
 		return ERR_PTR(-EINVAL);
 	}
 
+	/*
+	 * a raid1 doesn't have the notion of chunk size, so
+	 * figure out the largest suitable size we can use.
+	 */
+	chunksect = 64 * 2; /* 64K by default */
+
+	/* The array must be an exact multiple of chunksize */
+	while (chunksect && (mddev->array_sectors & (chunksect - 1)))
+		chunksect >>= 1;
+
+	if ((chunksect << 9) < PAGE_SIZE)
+		/* array size does not allow a suitable chunk size */
+		return ERR_PTR(-EINVAL);
+
 	/* Set new parameters */
 	mddev->new_level = 0;
 	mddev->new_layout = 0;
 	mddev->new_chunk_sectors = 128; /* by default set chunk size to 64k */
+	mddev->chunk_sectors = chunksect;
 	mddev->delta_disks = 1 - mddev->raid_disks;
 	mddev->raid_disks = 1;
 	/* make sure it will be not marked as dirty */
-- 
1.7.7.6


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

* Re: [PATCH v2] Avoid OOPS when reshaping raid1 to raid0
  2012-03-26  8:31 [PATCH v2] Avoid OOPS when reshaping raid1 to raid0 Jes.Sorensen
@ 2012-03-27  3:35 ` NeilBrown
  2012-03-27  7:17   ` Jes Sorensen
  0 siblings, 1 reply; 3+ messages in thread
From: NeilBrown @ 2012-03-27  3:35 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: dledford, linux-raid

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

On Mon, 26 Mar 2012 10:31:25 +0200 Jes.Sorensen@redhat.com wrote:

> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> raid1 arrays do not have the notion of chunk size. Calculate the
> larges chunk sector size we can use to avoid a divide by zero OOPS
> when aligning the size of the new array to the chunk size.
> 
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>

Thanks.
Applied with one change:

>  	/* Set new parameters */
>  	mddev->new_level = 0;
>  	mddev->new_layout = 0;
>  	mddev->new_chunk_sectors = 128; /* by default set chunk size to 64k */

I changed the above line to
	mddev->new_chunk_sectors = chunksect;

as that makes more sense.

Thanks,
NeilBrown


> +	mddev->chunk_sectors = chunksect;
>  	mddev->delta_disks = 1 - mddev->raid_disks;
>  	mddev->raid_disks = 1;
>  	/* make sure it will be not marked as dirty */


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

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

* Re: [PATCH v2] Avoid OOPS when reshaping raid1 to raid0
  2012-03-27  3:35 ` NeilBrown
@ 2012-03-27  7:17   ` Jes Sorensen
  0 siblings, 0 replies; 3+ messages in thread
From: Jes Sorensen @ 2012-03-27  7:17 UTC (permalink / raw)
  To: NeilBrown; +Cc: dledford, linux-raid

On 03/27/12 05:35, NeilBrown wrote:
> On Mon, 26 Mar 2012 10:31:25 +0200 Jes.Sorensen@redhat.com wrote:
> 
>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>>
>> raid1 arrays do not have the notion of chunk size. Calculate the
>> larges chunk sector size we can use to avoid a divide by zero OOPS
>> when aligning the size of the new array to the chunk size.
>>
>> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> Thanks.
> Applied with one change:
> 
>>  	/* Set new parameters */
>>  	mddev->new_level = 0;
>>  	mddev->new_layout = 0;
>>  	mddev->new_chunk_sectors = 128; /* by default set chunk size to 64k */
> 
> I changed the above line to
> 	mddev->new_chunk_sectors = chunksect;
> 
> as that makes more sense.

I agree, I was wondering whether to change it as well.

Thanks - will it be in your git repo soon?

Cheers,
Jes

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

end of thread, other threads:[~2012-03-27  7:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-26  8:31 [PATCH v2] Avoid OOPS when reshaping raid1 to raid0 Jes.Sorensen
2012-03-27  3:35 ` NeilBrown
2012-03-27  7:17   ` Jes Sorensen

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