Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 197479
b: refs/heads/master
c: 9af204c
h: refs/heads/master
i:
  197477: f8ffb08
  197475: d255dee
  197471: 76eedc1
v: v3
  • Loading branch information
Trela, Maciej authored and NeilBrown committed May 18, 2010
1 parent 9201e48 commit bf26f77
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 54071b3808ee3dc8624d9d6f1b06c4fd5308fa3b
refs/heads/master: 9af204cf720cedf369cf823bbd806c350201f7ea
7 changes: 7 additions & 0 deletions trunk/drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,13 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
mddev->layout = mddev->new_layout;
mddev->chunk_sectors = mddev->new_chunk_sectors;
mddev->delta_disks = 0;
if (mddev->pers->sync_request == NULL) {
/* this is now an array without redundancy, so
* it must always be in_sync
*/
mddev->in_sync = 1;
del_timer_sync(&mddev->safemode_timer);
}
pers->run(mddev);
mddev_resume(mddev);
set_bit(MD_CHANGE_DEVS, &mddev->flags);
Expand Down
125 changes: 119 additions & 6 deletions trunk/drivers/md/raid0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -90,7 +91,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, raid0_conf_t **private_conf)
{
int i, c, err;
sector_t curr_zone_end, sectors;
Expand Down Expand Up @@ -164,6 +165,10 @@ static int create_strip_zones(mddev_t *mddev)
list_for_each_entry(rdev1, &mddev->disks, same_set) {
int j = rdev1->raid_disk;

if (mddev->level == 10)
/* taking over a raid10-n2 array */
j /= 2;

if (j < 0 || j >= mddev->raid_disks) {
printk(KERN_ERR "raid0: bad disk number %d - "
"aborting!\n", j);
Expand Down Expand Up @@ -264,13 +269,14 @@ static int create_strip_zones(mddev_t *mddev)
(mddev->chunk_sectors << 9) * mddev->raid_disks);

printk(KERN_INFO "raid0: done.\n");
mddev->private = conf;
*private_conf = conf;

return 0;
abort:
kfree(conf->strip_zone);
kfree(conf->devlist);
kfree(conf);
mddev->private = NULL;
*private_conf = NULL;
return err;
}

Expand Down Expand Up @@ -321,6 +327,7 @@ static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks)

static int raid0_run(mddev_t *mddev)
{
raid0_conf_t *conf;
int ret;

if (mddev->chunk_sectors == 0) {
Expand All @@ -332,9 +339,20 @@ static int raid0_run(mddev_t *mddev)
blk_queue_max_hw_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, &conf);
if (ret < 0)
return ret;
mddev->private = conf;
}
conf = mddev->private;
if (conf->scale_raid_disks) {
int i;
for (i=0; i < conf->strip_zone[0].nb_dev; i++)
conf->devlist[i]->raid_disk /= conf->scale_raid_disks;
/* FIXME update sysfs rd links */
}

/* calculate array device size */
md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
Expand Down Expand Up @@ -548,6 +566,99 @@ 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(KERN_ERR "md: 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(KERN_ERR "md: 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->raid_disks--;
mddev->delta_disks = -1;
/* make sure it will be not marked as dirty */
mddev->recovery_cp = MaxSector;

create_strip_zones(mddev, &priv_conf);
return priv_conf;
}

static void *raid0_takeover_raid10(mddev_t *mddev)
{
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 "md: Raid0 cannot takover layout: %x\n",
mddev->layout);
return ERR_PTR(-EINVAL);
}
if (mddev->raid_disks & 1) {
printk(KERN_ERR "md: Raid0 cannot takover Raid10 with odd disk number.\n");
return ERR_PTR(-EINVAL);
}
if (mddev->degraded != (mddev->raid_disks>>1)) {
printk(KERN_ERR "md: 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->delta_disks = - mddev->raid_disks / 2;
mddev->raid_disks += mddev->delta_disks;
mddev->degraded = 0;
/* make sure it will be not marked as dirty */
mddev->recovery_cp = MaxSector;

create_strip_zones(mddev, &priv_conf);
priv_conf->scale_raid_disks = 2;
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(KERN_ERR "md: 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",
Expand All @@ -558,6 +669,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)
Expand Down
3 changes: 3 additions & 0 deletions trunk/drivers/md/raid0.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ struct raid0_private_data
struct strip_zone *strip_zone;
mdk_rdev_t **devlist; /* lists of rdevs, pointed to by strip_zone->dev */
int nr_strip_zones;
int scale_raid_disks; /* divide rdev->raid_disks by this in run()
* to handle conversion from raid10
*/
};

typedef struct raid0_private_data raid0_conf_t;
Expand Down

0 comments on commit bf26f77

Please sign in to comment.