Commit c8ac1803 authored by NeilBrown's avatar NeilBrown

md/raid5: unite handle_stripe_dirtying5 and handle_stripe_dirtying6

RAID6 is only allowed to choose 'reconstruct-write' while RAID5 is
also allow 'read-modify-write'
Apart from this difference, handle_stripe_dirtying[56] are nearly
identical.  So resolve these differences and create just one function.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Reviewed-by: default avatarNamhyung Kim <namhyung@gmail.com>
parent 93b3dbce
...@@ -2468,11 +2468,19 @@ static void handle_stripe_clean_event(raid5_conf_t *conf, ...@@ -2468,11 +2468,19 @@ static void handle_stripe_clean_event(raid5_conf_t *conf,
md_wakeup_thread(conf->mddev->thread); md_wakeup_thread(conf->mddev->thread);
} }
static void handle_stripe_dirtying5(raid5_conf_t *conf, static void handle_stripe_dirtying(raid5_conf_t *conf,
struct stripe_head *sh, struct stripe_head_state *s, int disks) struct stripe_head *sh,
struct stripe_head_state *s,
int disks)
{ {
int rmw = 0, rcw = 0, i; int rmw = 0, rcw = 0, i;
for (i = disks; i--; ) { if (conf->max_degraded == 2) {
/* RAID6 requires 'rcw' in current implementation
* Calculate the real rcw later - for now fake it
* look like rcw is cheaper
*/
rcw = 1; rmw = 2;
} else for (i = disks; i--; ) {
/* would I have to read this buffer for read_modify_write */ /* would I have to read this buffer for read_modify_write */
struct r5dev *dev = &sh->dev[i]; struct r5dev *dev = &sh->dev[i];
if ((dev->towrite || i == sh->pd_idx) && if ((dev->towrite || i == sh->pd_idx) &&
...@@ -2519,16 +2527,19 @@ static void handle_stripe_dirtying5(raid5_conf_t *conf, ...@@ -2519,16 +2527,19 @@ static void handle_stripe_dirtying5(raid5_conf_t *conf,
} }
} }
} }
if (rcw <= rmw && rcw > 0) if (rcw <= rmw && rcw > 0) {
/* want reconstruct write, but need to get some data */ /* want reconstruct write, but need to get some data */
rcw = 0;
for (i = disks; i--; ) { for (i = disks; i--; ) {
struct r5dev *dev = &sh->dev[i]; struct r5dev *dev = &sh->dev[i];
if (!test_bit(R5_OVERWRITE, &dev->flags) && if (!test_bit(R5_OVERWRITE, &dev->flags) &&
i != sh->pd_idx && i != sh->pd_idx && i != sh->qd_idx &&
!test_bit(R5_LOCKED, &dev->flags) && !test_bit(R5_LOCKED, &dev->flags) &&
!(test_bit(R5_UPTODATE, &dev->flags) || !(test_bit(R5_UPTODATE, &dev->flags) ||
test_bit(R5_Wantcompute, &dev->flags)) && test_bit(R5_Wantcompute, &dev->flags))) {
test_bit(R5_Insync, &dev->flags)) { rcw++;
if (!test_bit(R5_Insync, &dev->flags))
continue; /* it's a failed drive */
if ( if (
test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
pr_debug("Read_old block " pr_debug("Read_old block "
...@@ -2542,6 +2553,7 @@ static void handle_stripe_dirtying5(raid5_conf_t *conf, ...@@ -2542,6 +2553,7 @@ static void handle_stripe_dirtying5(raid5_conf_t *conf,
} }
} }
} }
}
/* now if nothing is locked, and if we have enough data, /* now if nothing is locked, and if we have enough data,
* we can start a write request * we can start a write request
*/ */
...@@ -2558,53 +2570,6 @@ static void handle_stripe_dirtying5(raid5_conf_t *conf, ...@@ -2558,53 +2570,6 @@ static void handle_stripe_dirtying5(raid5_conf_t *conf,
schedule_reconstruction(sh, s, rcw == 0, 0); schedule_reconstruction(sh, s, rcw == 0, 0);
} }
static void handle_stripe_dirtying6(raid5_conf_t *conf,
struct stripe_head *sh, struct stripe_head_state *s,
int disks)
{
int rcw = 0, pd_idx = sh->pd_idx, i;
int qd_idx = sh->qd_idx;
set_bit(STRIPE_HANDLE, &sh->state);
for (i = disks; i--; ) {
struct r5dev *dev = &sh->dev[i];
/* check if we haven't enough data */
if (!test_bit(R5_OVERWRITE, &dev->flags) &&
i != pd_idx && i != qd_idx &&
!test_bit(R5_LOCKED, &dev->flags) &&
!(test_bit(R5_UPTODATE, &dev->flags) ||
test_bit(R5_Wantcompute, &dev->flags))) {
rcw++;
if (!test_bit(R5_Insync, &dev->flags))
continue; /* it's a failed drive */
if (
test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
pr_debug("Read_old stripe %llu "
"block %d for Reconstruct\n",
(unsigned long long)sh->sector, i);
set_bit(R5_LOCKED, &dev->flags);
set_bit(R5_Wantread, &dev->flags);
s->locked++;
} else {
pr_debug("Request delayed stripe %llu "
"block %d for Reconstruct\n",
(unsigned long long)sh->sector, i);
set_bit(STRIPE_DELAYED, &sh->state);
set_bit(STRIPE_HANDLE, &sh->state);
}
}
}
/* now if nothing is locked, and if we have enough data, we can start a
* write request
*/
if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) &&
s->locked == 0 && rcw == 0 &&
!test_bit(STRIPE_BIT_DELAY, &sh->state)) {
schedule_reconstruction(sh, s, 1, 0);
}
}
static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh, static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh,
struct stripe_head_state *s, int disks) struct stripe_head_state *s, int disks)
{ {
...@@ -3099,7 +3064,7 @@ static int handle_stripe5(struct stripe_head *sh, struct stripe_head_state *s) ...@@ -3099,7 +3064,7 @@ static int handle_stripe5(struct stripe_head *sh, struct stripe_head_state *s)
* block. * block.
*/ */
if (s->to_write && !sh->reconstruct_state && !sh->check_state) if (s->to_write && !sh->reconstruct_state && !sh->check_state)
handle_stripe_dirtying5(conf, sh, s, disks); handle_stripe_dirtying(conf, sh, s, disks);
/* maybe we need to check and possibly fix the parity for this stripe /* maybe we need to check and possibly fix the parity for this stripe
* Any reads will already have been scheduled, so we just see if enough * Any reads will already have been scheduled, so we just see if enough
...@@ -3288,7 +3253,7 @@ static int handle_stripe6(struct stripe_head *sh, struct stripe_head_state *s) ...@@ -3288,7 +3253,7 @@ static int handle_stripe6(struct stripe_head *sh, struct stripe_head_state *s)
* block. * block.
*/ */
if (s->to_write && !sh->reconstruct_state && !sh->check_state) if (s->to_write && !sh->reconstruct_state && !sh->check_state)
handle_stripe_dirtying6(conf, sh, s, disks); handle_stripe_dirtying(conf, sh, s, disks);
/* maybe we need to check and possibly fix the parity for this stripe /* maybe we need to check and possibly fix the parity for this stripe
* Any reads will already have been scheduled, so we just see if enough * Any reads will already have been scheduled, so we just see if enough
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment