Commit a8bb304c authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Jens Axboe

md/raid5: Factor out ahead_of_reshape() function

There are a few uses of an ugly ternary operator in raid5_make_request()
to check if a sector is a head of a reshape sector.

Factor this out into a simple helper called ahead_of_reshape().

No functional changes intended.
Suggested-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 6e3f50d3
...@@ -5785,6 +5785,13 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi) ...@@ -5785,6 +5785,13 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
bio_endio(bi); bio_endio(bi);
} }
static bool ahead_of_reshape(struct mddev *mddev, sector_t sector,
sector_t reshape_sector)
{
return mddev->reshape_backwards ? sector < reshape_sector :
sector >= reshape_sector;
}
static bool raid5_make_request(struct mddev *mddev, struct bio * bi) static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
{ {
struct r5conf *conf = mddev->private; struct r5conf *conf = mddev->private;
...@@ -5841,9 +5848,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5841,9 +5848,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
/* Bail out if conflicts with reshape and REQ_NOWAIT is set */ /* Bail out if conflicts with reshape and REQ_NOWAIT is set */
if ((bi->bi_opf & REQ_NOWAIT) && if ((bi->bi_opf & REQ_NOWAIT) &&
(conf->reshape_progress != MaxSector) && (conf->reshape_progress != MaxSector) &&
(mddev->reshape_backwards !ahead_of_reshape(mddev, logical_sector, conf->reshape_progress) &&
? (logical_sector >= conf->reshape_progress && logical_sector < conf->reshape_safe) ahead_of_reshape(mddev, logical_sector, conf->reshape_safe)) {
: (logical_sector >= conf->reshape_safe && logical_sector < conf->reshape_progress))) {
bio_wouldblock_error(bi); bio_wouldblock_error(bi);
if (rw == WRITE) if (rw == WRITE)
md_write_end(mddev); md_write_end(mddev);
...@@ -5872,14 +5878,12 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5872,14 +5878,12 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
* to check again. * to check again.
*/ */
spin_lock_irq(&conf->device_lock); spin_lock_irq(&conf->device_lock);
if (mddev->reshape_backwards if (ahead_of_reshape(mddev, logical_sector,
? logical_sector < conf->reshape_progress conf->reshape_progress)) {
: logical_sector >= conf->reshape_progress) {
previous = 1; previous = 1;
} else { } else {
if (mddev->reshape_backwards if (ahead_of_reshape(mddev, logical_sector,
? logical_sector < conf->reshape_safe conf->reshape_safe)) {
: logical_sector >= conf->reshape_safe) {
spin_unlock_irq(&conf->device_lock); spin_unlock_irq(&conf->device_lock);
schedule(); schedule();
do_prepare = true; do_prepare = true;
...@@ -5910,9 +5914,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -5910,9 +5914,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
*/ */
int must_retry = 0; int must_retry = 0;
spin_lock_irq(&conf->device_lock); spin_lock_irq(&conf->device_lock);
if (mddev->reshape_backwards if (!ahead_of_reshape(mddev, logical_sector,
? logical_sector >= conf->reshape_progress conf->reshape_progress))
: logical_sector < conf->reshape_progress)
/* mismatch, need to try again */ /* mismatch, need to try again */
must_retry = 1; must_retry = 1;
spin_unlock_irq(&conf->device_lock); spin_unlock_irq(&conf->device_lock);
......
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