md/raid5: simplify raid5_compute_sector interface

Rather than passing 'pd_idx' and 'qd_idx' to be filled in, pass
a 'struct stripe_head *' and fill in the relevant fields.  This is
more extensible.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2009-03-31 14:39:38 +11:00
parent d0dabf7e57
commit 911d4ee853

View File

@ -299,14 +299,13 @@ static int grow_buffers(struct stripe_head *sh, int num)
} }
static void raid5_build_block(struct stripe_head *sh, int i); static void raid5_build_block(struct stripe_head *sh, int i);
static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int previous, static void stripe_set_idx(sector_t stripe, raid5_conf_t *conf, int previous,
int *qd_idx); struct stripe_head *sh);
static void init_stripe(struct stripe_head *sh, sector_t sector, int previous) static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
{ {
raid5_conf_t *conf = sh->raid_conf; raid5_conf_t *conf = sh->raid_conf;
int i; int i;
int qd_idx;
BUG_ON(atomic_read(&sh->count) != 0); BUG_ON(atomic_read(&sh->count) != 0);
BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
@ -320,8 +319,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks;
sh->sector = sector; sh->sector = sector;
sh->pd_idx = stripe_to_pdidx(sector, conf, previous, &qd_idx); stripe_set_idx(sector, conf, previous, sh);
sh->qd_idx = qd_idx;
sh->state = 0; sh->state = 0;
@ -1262,12 +1260,13 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
* Output: index of the data and parity disk, and the sector # in them. * Output: index of the data and parity disk, and the sector # in them.
*/ */
static sector_t raid5_compute_sector(raid5_conf_t *conf, sector_t r_sector, static sector_t raid5_compute_sector(raid5_conf_t *conf, sector_t r_sector,
int previous, int previous, int *dd_idx,
int *dd_idx, int *pd_idx, int *qd_idx) struct stripe_head *sh)
{ {
long stripe; long stripe;
unsigned long chunk_number; unsigned long chunk_number;
unsigned int chunk_offset; unsigned int chunk_offset;
int pd_idx, qd_idx;
sector_t new_sector; sector_t new_sector;
int sectors_per_chunk = conf->chunk_size >> 9; int sectors_per_chunk = conf->chunk_size >> 9;
int raid_disks = previous ? conf->previous_raid_disks int raid_disks = previous ? conf->previous_raid_disks
@ -1296,30 +1295,30 @@ static sector_t raid5_compute_sector(raid5_conf_t *conf, sector_t r_sector,
/* /*
* Select the parity disk based on the user selected algorithm. * Select the parity disk based on the user selected algorithm.
*/ */
*qd_idx = ~0; pd_idx = qd_idx = ~0;
switch(conf->level) { switch(conf->level) {
case 4: case 4:
*pd_idx = data_disks; pd_idx = data_disks;
break; break;
case 5: case 5:
switch (conf->algorithm) { switch (conf->algorithm) {
case ALGORITHM_LEFT_ASYMMETRIC: case ALGORITHM_LEFT_ASYMMETRIC:
*pd_idx = data_disks - stripe % raid_disks; pd_idx = data_disks - stripe % raid_disks;
if (*dd_idx >= *pd_idx) if (*dd_idx >= pd_idx)
(*dd_idx)++; (*dd_idx)++;
break; break;
case ALGORITHM_RIGHT_ASYMMETRIC: case ALGORITHM_RIGHT_ASYMMETRIC:
*pd_idx = stripe % raid_disks; pd_idx = stripe % raid_disks;
if (*dd_idx >= *pd_idx) if (*dd_idx >= pd_idx)
(*dd_idx)++; (*dd_idx)++;
break; break;
case ALGORITHM_LEFT_SYMMETRIC: case ALGORITHM_LEFT_SYMMETRIC:
*pd_idx = data_disks - stripe % raid_disks; pd_idx = data_disks - stripe % raid_disks;
*dd_idx = (*pd_idx + 1 + *dd_idx) % raid_disks; *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks;
break; break;
case ALGORITHM_RIGHT_SYMMETRIC: case ALGORITHM_RIGHT_SYMMETRIC:
*pd_idx = stripe % raid_disks; pd_idx = stripe % raid_disks;
*dd_idx = (*pd_idx + 1 + *dd_idx) % raid_disks; *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks;
break; break;
default: default:
printk(KERN_ERR "raid5: unsupported algorithm %d\n", printk(KERN_ERR "raid5: unsupported algorithm %d\n",
@ -1331,32 +1330,32 @@ static sector_t raid5_compute_sector(raid5_conf_t *conf, sector_t r_sector,
/**** FIX THIS ****/ /**** FIX THIS ****/
switch (conf->algorithm) { switch (conf->algorithm) {
case ALGORITHM_LEFT_ASYMMETRIC: case ALGORITHM_LEFT_ASYMMETRIC:
*pd_idx = raid_disks - 1 - (stripe % raid_disks); pd_idx = raid_disks - 1 - (stripe % raid_disks);
*qd_idx = *pd_idx + 1; qd_idx = pd_idx + 1;
if (*pd_idx == raid_disks-1) { if (pd_idx == raid_disks-1) {
(*dd_idx)++; /* Q D D D P */ (*dd_idx)++; /* Q D D D P */
*qd_idx = 0; qd_idx = 0;
} else if (*dd_idx >= *pd_idx) } else if (*dd_idx >= pd_idx)
(*dd_idx) += 2; /* D D P Q D */ (*dd_idx) += 2; /* D D P Q D */
break; break;
case ALGORITHM_RIGHT_ASYMMETRIC: case ALGORITHM_RIGHT_ASYMMETRIC:
*pd_idx = stripe % raid_disks; pd_idx = stripe % raid_disks;
*qd_idx = *pd_idx + 1; qd_idx = pd_idx + 1;
if (*pd_idx == raid_disks-1) { if (pd_idx == raid_disks-1) {
(*dd_idx)++; /* Q D D D P */ (*dd_idx)++; /* Q D D D P */
*qd_idx = 0; qd_idx = 0;
} else if (*dd_idx >= *pd_idx) } else if (*dd_idx >= pd_idx)
(*dd_idx) += 2; /* D D P Q D */ (*dd_idx) += 2; /* D D P Q D */
break; break;
case ALGORITHM_LEFT_SYMMETRIC: case ALGORITHM_LEFT_SYMMETRIC:
*pd_idx = raid_disks - 1 - (stripe % raid_disks); pd_idx = raid_disks - 1 - (stripe % raid_disks);
*qd_idx = (*pd_idx + 1) % raid_disks; qd_idx = (pd_idx + 1) % raid_disks;
*dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks;
break; break;
case ALGORITHM_RIGHT_SYMMETRIC: case ALGORITHM_RIGHT_SYMMETRIC:
*pd_idx = stripe % raid_disks; pd_idx = stripe % raid_disks;
*qd_idx = (*pd_idx + 1) % raid_disks; qd_idx = (pd_idx + 1) % raid_disks;
*dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks;
break; break;
default: default:
printk(KERN_CRIT "raid6: unsupported algorithm %d\n", printk(KERN_CRIT "raid6: unsupported algorithm %d\n",
@ -1365,6 +1364,10 @@ static sector_t raid5_compute_sector(raid5_conf_t *conf, sector_t r_sector,
break; break;
} }
if (sh) {
sh->pd_idx = pd_idx;
sh->qd_idx = qd_idx;
}
/* /*
* Finally, compute the new sector number * Finally, compute the new sector number
*/ */
@ -1382,8 +1385,9 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
int sectors_per_chunk = conf->chunk_size >> 9; int sectors_per_chunk = conf->chunk_size >> 9;
sector_t stripe; sector_t stripe;
int chunk_offset; int chunk_offset;
int chunk_number, dummy1, dummy2, dummy3, dd_idx = i; int chunk_number, dummy1, dd_idx = i;
sector_t r_sector; sector_t r_sector;
struct stripe_head sh2;
chunk_offset = sector_div(new_sector, sectors_per_chunk); chunk_offset = sector_div(new_sector, sectors_per_chunk);
@ -1446,8 +1450,9 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
check = raid5_compute_sector(conf, r_sector, check = raid5_compute_sector(conf, r_sector,
(raid_disks != conf->raid_disks), (raid_disks != conf->raid_disks),
&dummy1, &dummy2, &dummy3); &dummy1, &sh2);
if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) { if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx
|| sh2.qd_idx != sh->qd_idx) {
printk(KERN_ERR "compute_blocknr: map not correct\n"); printk(KERN_ERR "compute_blocknr: map not correct\n");
return 0; return 0;
} }
@ -1843,11 +1848,11 @@ static int page_is_zero(struct page *p)
memcmp(a, a+4, STRIPE_SIZE-4)==0); memcmp(a, a+4, STRIPE_SIZE-4)==0);
} }
static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int previous, static void stripe_set_idx(sector_t stripe, raid5_conf_t *conf, int previous,
int *qd_idxp) struct stripe_head *sh)
{ {
int sectors_per_chunk = conf->chunk_size >> 9; int sectors_per_chunk = conf->chunk_size >> 9;
int pd_idx, dd_idx; int dd_idx;
int chunk_offset = sector_div(stripe, sectors_per_chunk); int chunk_offset = sector_div(stripe, sectors_per_chunk);
int disks = previous ? conf->previous_raid_disks : conf->raid_disks; int disks = previous ? conf->previous_raid_disks : conf->raid_disks;
@ -1855,8 +1860,7 @@ static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int previous,
stripe * (disks - conf->max_degraded) stripe * (disks - conf->max_degraded)
*sectors_per_chunk + chunk_offset, *sectors_per_chunk + chunk_offset,
previous, previous,
&dd_idx, &pd_idx, qd_idxp); &dd_idx, sh);
return pd_idx;
} }
static void static void
@ -2514,13 +2518,12 @@ static void handle_stripe_expansion(raid5_conf_t *conf, struct stripe_head *sh,
clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); clear_bit(STRIPE_EXPAND_SOURCE, &sh->state);
for (i = 0; i < sh->disks; i++) for (i = 0; i < sh->disks; i++)
if (i != sh->pd_idx && (!r6s || i != r6s->qd_idx)) { if (i != sh->pd_idx && (!r6s || i != r6s->qd_idx)) {
int dd_idx, pd_idx, qd_idx, j; int dd_idx, j;
struct stripe_head *sh2; struct stripe_head *sh2;
sector_t bn = compute_blocknr(sh, i); sector_t bn = compute_blocknr(sh, i);
sector_t s = sector_t s = raid5_compute_sector(conf, bn, 0,
raid5_compute_sector(conf, bn, 0, &dd_idx, NULL);
&dd_idx, &pd_idx, &qd_idx);
sh2 = get_active_stripe(conf, s, 0, 1); sh2 = get_active_stripe(conf, s, 0, 1);
if (sh2 == NULL) if (sh2 == NULL)
/* so far only the early blocks of this stripe /* so far only the early blocks of this stripe
@ -2804,11 +2807,9 @@ static bool handle_stripe5(struct stripe_head *sh)
if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) &&
!sh->reconstruct_state) { !sh->reconstruct_state) {
int qd_idx;
/* Need to write out all blocks after computing parity */ /* Need to write out all blocks after computing parity */
sh->disks = conf->raid_disks; sh->disks = conf->raid_disks;
sh->pd_idx = stripe_to_pdidx(sh->sector, conf, 0, &qd_idx); stripe_set_idx(sh->sector, conf, 0, sh);
sh->qd_idx = qd_idx;
schedule_reconstruction5(sh, &s, 1, 1); schedule_reconstruction5(sh, &s, 1, 1);
} else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) {
clear_bit(STRIPE_EXPAND_READY, &sh->state); clear_bit(STRIPE_EXPAND_READY, &sh->state);
@ -3025,10 +3026,8 @@ static bool handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state)) { if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state)) {
/* Need to write out all blocks after computing P&Q */ /* Need to write out all blocks after computing P&Q */
int qd_idx;
sh->disks = conf->raid_disks; sh->disks = conf->raid_disks;
sh->pd_idx = stripe_to_pdidx(sh->sector, conf, 0, &qd_idx); stripe_set_idx(sh->sector, conf, 0, sh);
sh->qd_idx = qd_idx;
compute_parity6(sh, RECONSTRUCT_WRITE); compute_parity6(sh, RECONSTRUCT_WRITE);
for (i = conf->raid_disks ; i-- ; ) { for (i = conf->raid_disks ; i-- ; ) {
set_bit(R5_LOCKED, &sh->dev[i].flags); set_bit(R5_LOCKED, &sh->dev[i].flags);
@ -3300,7 +3299,7 @@ static int chunk_aligned_read(struct request_queue *q, struct bio * raid_bio)
{ {
mddev_t *mddev = q->queuedata; mddev_t *mddev = q->queuedata;
raid5_conf_t *conf = mddev_to_conf(mddev); raid5_conf_t *conf = mddev_to_conf(mddev);
unsigned int dd_idx, pd_idx, qd_idx; unsigned int dd_idx;
struct bio* align_bi; struct bio* align_bi;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
@ -3325,7 +3324,7 @@ static int chunk_aligned_read(struct request_queue *q, struct bio * raid_bio)
*/ */
align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector,
0, 0,
&dd_idx, &pd_idx, &qd_idx); &dd_idx, NULL);
rcu_read_lock(); rcu_read_lock();
rdev = rcu_dereference(conf->disks[dd_idx].rdev); rdev = rcu_dereference(conf->disks[dd_idx].rdev);
@ -3417,7 +3416,7 @@ static int make_request(struct request_queue *q, struct bio * bi)
{ {
mddev_t *mddev = q->queuedata; mddev_t *mddev = q->queuedata;
raid5_conf_t *conf = mddev_to_conf(mddev); raid5_conf_t *conf = mddev_to_conf(mddev);
int dd_idx, pd_idx, qd_idx; int dd_idx;
sector_t new_sector; sector_t new_sector;
sector_t logical_sector, last_sector; sector_t logical_sector, last_sector;
struct stripe_head *sh; struct stripe_head *sh;
@ -3484,7 +3483,7 @@ static int make_request(struct request_queue *q, struct bio * bi)
new_sector = raid5_compute_sector(conf, logical_sector, new_sector = raid5_compute_sector(conf, logical_sector,
previous, previous,
&dd_idx, &pd_idx, &qd_idx); &dd_idx, NULL);
pr_debug("raid5: make_request, sector %llu logical %llu\n", pr_debug("raid5: make_request, sector %llu logical %llu\n",
(unsigned long long)new_sector, (unsigned long long)new_sector,
(unsigned long long)logical_sector); (unsigned long long)logical_sector);
@ -3572,7 +3571,6 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
*/ */
raid5_conf_t *conf = (raid5_conf_t *) mddev->private; raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
struct stripe_head *sh; struct stripe_head *sh;
int pd_idx, qd_idx;
sector_t first_sector, last_sector; sector_t first_sector, last_sector;
int raid_disks = conf->previous_raid_disks; int raid_disks = conf->previous_raid_disks;
int data_disks = raid_disks - conf->max_degraded; int data_disks = raid_disks - conf->max_degraded;
@ -3662,11 +3660,11 @@ static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped
*/ */
first_sector = first_sector =
raid5_compute_sector(conf, sector_nr*(new_data_disks), raid5_compute_sector(conf, sector_nr*(new_data_disks),
1, &dd_idx, &pd_idx, &qd_idx); 1, &dd_idx, NULL);
last_sector = last_sector =
raid5_compute_sector(conf, ((sector_nr+conf->chunk_size/512) raid5_compute_sector(conf, ((sector_nr+conf->chunk_size/512)
*(new_data_disks) - 1), *(new_data_disks) - 1),
1, &dd_idx, &pd_idx, &qd_idx); 1, &dd_idx, NULL);
if (last_sector >= mddev->dev_sectors) if (last_sector >= mddev->dev_sectors)
last_sector = mddev->dev_sectors - 1; last_sector = mddev->dev_sectors - 1;
while (first_sector <= last_sector) { while (first_sector <= last_sector) {
@ -3801,7 +3799,7 @@ static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
* it will be only one 'dd_idx' and only need one call to raid5_compute_sector. * it will be only one 'dd_idx' and only need one call to raid5_compute_sector.
*/ */
struct stripe_head *sh; struct stripe_head *sh;
int dd_idx, pd_idx, qd_idx; int dd_idx;
sector_t sector, logical_sector, last_sector; sector_t sector, logical_sector, last_sector;
int scnt = 0; int scnt = 0;
int remaining; int remaining;
@ -3809,7 +3807,7 @@ static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
sector = raid5_compute_sector(conf, logical_sector, sector = raid5_compute_sector(conf, logical_sector,
0, &dd_idx, &pd_idx, &qd_idx); 0, &dd_idx, NULL);
last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9); last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9);
for (; logical_sector < last_sector; for (; logical_sector < last_sector;