linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] md: Add support for Raid5->Raid0 and Raid10->Raid0 takeover
@ 2010-01-29 14:54 Trela, Maciej
  2010-02-01  0:05 ` Neil Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Trela, Maciej @ 2010-01-29 14:54 UTC (permalink / raw)
  To: linux-raid@vger.kernel.org, NeilBrown; +Cc: Williams, Dan J, Ciechanowski, Ed


Signed-off-by: Maciej Trela <maciej.trela@intel.com>
---
 drivers/md/raid0.c |  161 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 158 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 77605cd..410d4e9 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -22,6 +22,7 @@
 #include <linux/seq_file.h>
 #include "md.h"
 #include "raid0.h"
+#include "raid5.h"
 
 static void raid0_unplug(struct request_queue *q)
 {
@@ -328,9 +329,13 @@ static int raid0_run(mddev_t *mddev)
 	blk_queue_max_sectors(mddev->queue, mddev->chunk_sectors);
 	mddev->queue->queue_lock = &mddev->queue->__queue_lock;
 
-	ret = create_strip_zones(mddev);
-	if (ret < 0)
-		return ret;
+	/* if private is not null, we are here after takeover */
+	if (mddev->private == NULL)
+	{
+		ret = create_strip_zones(mddev);
+		if (ret < 0)
+			return ret;
+	} 
 
 	/* calculate array device size */
 	md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
@@ -542,6 +547,154 @@ static void raid0_status(struct seq_file *seq, mddev_t *mddev)
 	return;
 }
 
+static raid0_conf_t *setup_conf(mddev_t *mddev)
+{
+	raid0_conf_t *conf;
+	mdk_rdev_t *rdev, **dev;
+	struct strip_zone *zone;
+	int cnt;
+
+	if (mddev->new_level != 0)
+		return ERR_PTR(-EIO);
+	
+	conf = kzalloc(sizeof(raid0_conf_t), GFP_KERNEL);
+	if (conf == NULL)
+		goto abort;
+	
+	conf->nr_strip_zones = 1;		
+	conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
+							   conf->nr_strip_zones, GFP_KERNEL);
+	if (!conf->strip_zone)
+		goto abort;
+	
+	conf->devlist = kzalloc(sizeof(mdk_rdev_t*)*
+							conf->nr_strip_zones*mddev->raid_disks,
+							GFP_KERNEL);
+	if (!conf->devlist)
+		goto abort;
+	
+	/* The first zone must contain all devices, so here we check that
+	 * there is a proper alignment of slots to devices and find them all
+	 */
+	zone = &conf->strip_zone[0];
+	dev = conf->devlist;
+	zone->dev_start = 0;
+	cnt = 0;
+
+	/* initialize device list */
+	list_for_each_entry(rdev, &mddev->disks, same_set) {	
+		dev[cnt] = rdev;
+		cnt++;
+	}
+	
+	if (cnt != mddev->raid_disks) {
+		printk(KERN_ERR "raid0: too few disks (%d of %d) - "
+			   "aborting!\n", cnt, mddev->raid_disks);
+		goto abort;
+	}
+	zone->nb_dev = cnt;
+	zone->zone_end = mddev->array_sectors;
+	return conf;
+
+ abort:
+	if (conf) {
+	        kfree(conf->strip_zone);
+		kfree(conf->devlist);
+		kfree(conf);
+		return ERR_PTR(-EIO);
+	} else
+		return ERR_PTR(-ENOMEM);
+}
+
+static void *raid0_takeover_raid5(mddev_t *mddev)
+{
+	mdk_rdev_t *rdev;
+
+	if (mddev->degraded != 1) {
+		printk("error: raid5 must be degraded! Degraded disks: %d\n", 
+			   mddev->degraded);
+		return ERR_PTR(-EINVAL);
+	}
+	
+	list_for_each_entry(rdev, &mddev->disks, same_set) {	
+		/* check slot number for a disk */
+		if (rdev->raid_disk == mddev->raid_disks-1) {
+		    printk("error: raid5 must have missing parity disk!\n");
+		    return ERR_PTR(-EINVAL);		  
+		}
+	}
+
+	/* Set new parameters */
+	mddev->new_level = 0;
+	mddev->degraded = 0;
+	mddev->raid_disks--;
+	mddev->delta_disks = -1;
+	/* make sure it will be not marked as dirty */
+	mddev->recovery_cp = MaxSector;
+
+	return setup_conf(mddev);
+}
+
+static void *raid0_takeover_raid10(mddev_t *mddev)
+{
+	mdk_rdev_t *rdev;
+
+	/* Check layout: 
+	 *  assuming that far_copies is 1 and disks number is even 
+	 *  also all mirrors must be already degraded
+	 */
+	if ((mddev->layout >> 8) != 1) {
+	    printk(KERN_ERR "error: Raid0 cannot takover layout: %x\n", mddev->layout);
+		return ERR_PTR(-EINVAL);
+	}
+	if (mddev->raid_disks & 1) {
+	    printk(KERN_ERR "error: Raid0 cannot takover Raid10 with odd disk number.\n");
+		return ERR_PTR(-EINVAL);
+	}
+	if (mddev->degraded != (mddev->raid_disks>>1)) {
+	    printk(KERN_ERR "error: All mirrors must be already degraded!\n");
+		return ERR_PTR(-EINVAL);
+	}
+	
+	/* Set new parameters */
+	mddev->new_level = 0;
+	mddev->raid_disks -= mddev->degraded;
+	mddev->delta_disks = -mddev->degraded;
+	mddev->degraded = 0;
+	/* make sure it will be not marked as dirty */
+	mddev->recovery_cp = MaxSector;
+
+	list_for_each_entry(rdev, &mddev->disks, same_set) {	
+		rdev->raid_disk /= 2;
+	}
+
+	return setup_conf(mddev);
+}
+
+static void *raid0_takeover(mddev_t *mddev)
+{
+	/* raid0 can take over:
+	 *  raid5 - providing it is Raid4 layout and one disk is faulty
+	 *  raid10 - assuming we have all necessary active disks
+	 */
+	if (mddev->level == 5) {
+	    if (mddev->layout == ALGORITHM_PARITY_N) {
+	        return raid0_takeover_raid5(mddev);	
+		}
+	    printk("Error: Raid can only takeover Raid5 with layout: %d\n", 
+			   ALGORITHM_PARITY_N);
+	}
+	
+	if (mddev->level == 10)
+	    return raid0_takeover_raid10(mddev);
+	
+	return ERR_PTR(-EINVAL);
+}
+
+static void raid0_quiesce(mddev_t *mddev, int state)
+{
+}
+
 static struct mdk_personality raid0_personality=
 {
 	.name		= "raid0",
@@ -552,6 +705,8 @@ static struct mdk_personality raid0_personality=
 	.stop		= raid0_stop,
 	.status		= raid0_status,
 	.size		= raid0_size,
+	.takeover	= raid0_takeover,	
+	.quiesce	= raid0_quiesce,
 };
 
 static int __init raid0_init (void)
-- 
1.6.3.3




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

* Re: [PATCH 2/3] md: Add support for Raid5->Raid0 and Raid10->Raid0 takeover
  2010-01-29 14:54 [PATCH 2/3] md: Add support for Raid5->Raid0 and Raid10->Raid0 takeover Trela, Maciej
@ 2010-02-01  0:05 ` Neil Brown
  2010-02-03 12:10   ` Trela, Maciej
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Brown @ 2010-02-01  0:05 UTC (permalink / raw)
  To: Trela, Maciej
  Cc: linux-raid@vger.kernel.org, Williams, Dan J, Ciechanowski, Ed

On Fri, 29 Jan 2010 14:54:10 +0000
"Trela, Maciej" <Maciej.Trela@intel.com> wrote:


> +static void *raid0_takeover_raid10(mddev_t *mddev)
> +{
> +	mdk_rdev_t *rdev;
> +
> +	/* Check layout: 
> +	 *  assuming that far_copies is 1 and disks number is even 
> +	 *  also all mirrors must be already degraded
> +	 */
> +	if ((mddev->layout >> 8) != 1) {
> +	    printk(KERN_ERR "error: Raid0 cannot takover layout: %x\n", mddev->layout);
> +		return ERR_PTR(-EINVAL);
> +	}
> +	if (mddev->raid_disks & 1) {
> +	    printk(KERN_ERR "error: Raid0 cannot takover Raid10 with odd disk number.\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +	if (mddev->degraded != (mddev->raid_disks>>1)) {
> +	    printk(KERN_ERR "error: All mirrors must be already degraded!\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +	
> +	/* Set new parameters */
> +	mddev->new_level = 0;
> +	mddev->raid_disks -= mddev->degraded;
> +	mddev->delta_disks = -mddev->degraded;
> +	mddev->degraded = 0;
> +	/* make sure it will be not marked as dirty */
> +	mddev->recovery_cp = MaxSector;
> +
> +	list_for_each_entry(rdev, &mddev->disks, same_set) {	
> +		rdev->raid_disk /= 2;
> +	}


You assume here that near_copies is 2, but you never check for that.

Also - and this applies to raid5 and raid10 - the devices may not be all the
same size.  raid5 and raid10 will just use the size of the smallest device,
but raid0 won't.  For for a seamless conversion, you need to handle the case
that the devices are not the same size.  Either disallow that case, or make
use of the extra space.

NeilBrown



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

* RE: [PATCH 2/3] md: Add support for Raid5->Raid0 and Raid10->Raid0 takeover
  2010-02-01  0:05 ` Neil Brown
@ 2010-02-03 12:10   ` Trela, Maciej
  0 siblings, 0 replies; 3+ messages in thread
From: Trela, Maciej @ 2010-02-03 12:10 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-raid@vger.kernel.org, Williams, Dan J, Ciechanowski, Ed


> You assume here that near_copies is 2, but you never check for that.
> 

Fixed.

> Also - and this applies to raid5 and raid10 - the devices may not be
> all the
> same size.  raid5 and raid10 will just use the size of the smallest
> device,
> but raid0 won't.  For for a seamless conversion, you need to handle the
> case
> that the devices are not the same size.  Either disallow that case, or
> make
> use of the extra space.
> 

I've removed setup_conf() from the original patch.
Now raid0 reuses create_strip_zones() when takeovering from Raid5 and from Raid10,
so multiply zones are supported.
Is it the right solution for the second problem?

Thanks,
Maciek Trela.


Signed-off-by: Maciej Trela <maciej.trela@intel.com>
---
 drivers/md/raid0.c |  116 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 111 insertions(+), 5 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 77605cd..35d1869 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -22,6 +22,7 @@
 #include <linux/seq_file.h>
 #include "md.h"
 #include "raid0.h"
+#include "raid5.h"
 
 static void raid0_unplug(struct request_queue *q)
 {
@@ -87,7 +88,7 @@ static void dump_zones(mddev_t *mddev)
 	printk(KERN_INFO "**********************************\n\n");
 }
 
-static int create_strip_zones(mddev_t *mddev)
+static int create_strip_zones(mddev_t *mddev, void** private_conf)
 {
 	int i, c, err;
 	sector_t curr_zone_end, sectors;
@@ -260,7 +261,9 @@ static int create_strip_zones(mddev_t *mddev)
 			 (mddev->chunk_sectors << 9) * mddev->raid_disks);
 
 	printk(KERN_INFO "raid0: done.\n");
-	mddev->private = conf;
+	if (private_conf)
+		*private_conf = conf;
+
 	return 0;
 abort:
 	kfree(conf->strip_zone);
@@ -328,9 +331,13 @@ static int raid0_run(mddev_t *mddev)
 	blk_queue_max_sectors(mddev->queue, mddev->chunk_sectors);
 	mddev->queue->queue_lock = &mddev->queue->__queue_lock;
 
-	ret = create_strip_zones(mddev);
-	if (ret < 0)
-		return ret;
+	/* if private is not null, we are here after takeover */
+	if (mddev->private == NULL)
+	{
+		ret = create_strip_zones(mddev, &mddev->private);
+		if (ret < 0)
+			return ret;
+	} 
 
 	/* calculate array device size */
 	md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
@@ -542,6 +549,103 @@ static void raid0_status(struct seq_file *seq, mddev_t *mddev)
 	return;
 }
 
+static void *raid0_takeover_raid5(mddev_t *mddev)
+{
+	mdk_rdev_t *rdev;
+	raid0_conf_t *priv_conf;
+
+	if (mddev->degraded != 1) {
+		printk("error: raid5 must be degraded! Degraded disks: %d\n", 
+			   mddev->degraded);
+		return ERR_PTR(-EINVAL);
+	}
+	
+	list_for_each_entry(rdev, &mddev->disks, same_set) {	
+		/* check slot number for a disk */
+		if (rdev->raid_disk == mddev->raid_disks-1) {
+		    printk("error: raid5 must have missing parity disk!\n");
+		    return ERR_PTR(-EINVAL);		  
+		}
+	}
+
+	/* Set new parameters */
+	mddev->new_level = 0;
+	mddev->new_chunk_sectors = mddev->chunk_sectors;
+	mddev->degraded = 0;
+	mddev->raid_disks--;
+	mddev->delta_disks = -1;
+	/* make sure it will be not marked as dirty */
+	mddev->recovery_cp = MaxSector;
+
+	create_strip_zones(mddev, (void**)&priv_conf);
+	return priv_conf;
+}
+
+static void *raid0_takeover_raid10(mddev_t *mddev)
+{
+	mdk_rdev_t *rdev;
+	raid0_conf_t *priv_conf;
+
+	/* Check layout: 
+	 *  - far_copies must be 1
+	 *  - near_copies must be 2
+	 *  - disks number must be even 
+	 *  - all mirrors must be already degraded
+	 */
+	if (mddev->layout != ((1 << 8) + 2)) {
+	    printk(KERN_ERR "error: Raid0 cannot takover layout: %x\n", mddev->layout);
+		return ERR_PTR(-EINVAL);
+	}
+	if (mddev->raid_disks & 1) {
+	    printk(KERN_ERR "error: Raid0 cannot takover Raid10 with odd disk number.\n");
+		return ERR_PTR(-EINVAL);
+	}
+	if (mddev->degraded != (mddev->raid_disks>>1)) {
+	    printk(KERN_ERR "error: All mirrors must be already degraded!\n");
+		return ERR_PTR(-EINVAL);
+	}
+	
+	/* Set new parameters */
+	mddev->new_level = 0;
+	mddev->new_chunk_sectors = mddev->chunk_sectors;
+	mddev->raid_disks -= mddev->degraded;
+	mddev->delta_disks = -mddev->degraded;
+	mddev->degraded = 0;
+	/* make sure it will be not marked as dirty */
+	mddev->recovery_cp = MaxSector;
+
+	list_for_each_entry(rdev, &mddev->disks, same_set) {	
+		rdev->raid_disk /= 2;
+	}
+
+	create_strip_zones(mddev, (void**)&priv_conf);
+	return priv_conf;
+}
+
+static void *raid0_takeover(mddev_t *mddev)
+{
+	/* raid0 can take over:
+	 *  raid5 - providing it is Raid4 layout and one disk is faulty
+	 *  raid10 - assuming we have all necessary active disks
+	 */
+	if (mddev->level == 5) {
+	    if (mddev->layout == ALGORITHM_PARITY_N) {
+	        return raid0_takeover_raid5(mddev);	
+		}
+	    printk("Error: Raid can only takeover Raid5 with layout: %d\n", 
+			   ALGORITHM_PARITY_N);
+	}
+	
+	if (mddev->level == 10)
+	    return raid0_takeover_raid10(mddev);
+	
+	return ERR_PTR(-EINVAL);
+}
+
+static void raid0_quiesce(mddev_t *mddev, int state)
+{
+}
+
 static struct mdk_personality raid0_personality=
 {
 	.name		= "raid0",
@@ -552,6 +656,8 @@ static struct mdk_personality raid0_personality=
 	.stop		= raid0_stop,
 	.status		= raid0_status,
 	.size		= raid0_size,
+	.takeover	= raid0_takeover,	
+	.quiesce	= raid0_quiesce,
 };
 
 static int __init raid0_init (void)
-- 
1.6.3.3


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

end of thread, other threads:[~2010-02-03 12:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-29 14:54 [PATCH 2/3] md: Add support for Raid5->Raid0 and Raid10->Raid0 takeover Trela, Maciej
2010-02-01  0:05 ` Neil Brown
2010-02-03 12:10   ` Trela, Maciej

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