Commit 27fb7010 authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Jens Axboe

md/raid5: Refactor raid5_make_request loop

Break immediately if raid5_get_active_stripe() returns NULL and deindent
the rest of the loop. Annotate this check with an unlikely().

This makes the code easier to read and reduces the indentation level.

No functional changes intended.
Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarGuoqing Jiang <guoqing.jiang@linux.dev>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent a8bb304c
...@@ -5902,7 +5902,12 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5902,7 +5902,12 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
sh = raid5_get_active_stripe(conf, new_sector, previous, sh = raid5_get_active_stripe(conf, new_sector, previous,
(bi->bi_opf & REQ_RAHEAD), 0); (bi->bi_opf & REQ_RAHEAD), 0);
if (sh) { if (unlikely(!sh)) {
/* cannot get stripe, just give-up */
bi->bi_status = BLK_STS_IOERR;
break;
}
if (unlikely(previous)) { if (unlikely(previous)) {
/* expansion might have moved on while waiting for a /* expansion might have moved on while waiting for a
* stripe, so we must do the range check again. * stripe, so we must do the range check again.
...@@ -5926,19 +5931,18 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5926,19 +5931,18 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
goto retry; goto retry;
} }
} }
if (read_seqcount_retry(&conf->gen_lock, seq)) { if (read_seqcount_retry(&conf->gen_lock, seq)) {
/* Might have got the wrong stripe_head /* Might have got the wrong stripe_head by accident */
* by accident
*/
raid5_release_stripe(sh); raid5_release_stripe(sh);
goto retry; goto retry;
} }
if (test_bit(STRIPE_EXPANDING, &sh->state) || if (test_bit(STRIPE_EXPANDING, &sh->state) ||
!add_stripe_bio(sh, bi, dd_idx, rw, previous)) { !add_stripe_bio(sh, bi, dd_idx, rw, previous)) {
/* Stripe is busy expanding or /*
* add failed due to overlap. Flush everything * Stripe is busy expanding or add failed due to
* and wait a while * overlap. Flush everything and wait a while.
*/ */
md_wakeup_thread(mddev->thread); md_wakeup_thread(mddev->thread);
raid5_release_stripe(sh); raid5_release_stripe(sh);
...@@ -5946,6 +5950,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5946,6 +5950,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
do_prepare = true; do_prepare = true;
goto retry; goto retry;
} }
if (do_flush) { if (do_flush) {
set_bit(STRIPE_R5C_PREFLUSH, &sh->state); set_bit(STRIPE_R5C_PREFLUSH, &sh->state);
/* we only need flush for one stripe */ /* we only need flush for one stripe */
...@@ -5958,12 +5963,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5958,12 +5963,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
(bi->bi_opf & REQ_SYNC) && (bi->bi_opf & REQ_SYNC) &&
!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
atomic_inc(&conf->preread_active_stripes); atomic_inc(&conf->preread_active_stripes);
release_stripe_plug(mddev, sh); release_stripe_plug(mddev, sh);
} else {
/* cannot get stripe for read-ahead, just give-up */
bi->bi_status = BLK_STS_IOERR;
break;
}
} }
finish_wait(&conf->wait_for_overlap, &w); finish_wait(&conf->wait_for_overlap, &w);
......
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