Skip to content

Commit 3514da5

Browse files
lsgunthaxboe
authored andcommitted
md/raid5: Make is_inactive_blocked() helper
The logic to wait_for_stripe is difficult to parse being on so many lines and with confusing operator precedence. Move it to a helper function to make it easier to read. No functional changes intended. Signed-off-by: Logan Gunthorpe <[email protected]> Signed-off-by: Song Liu <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5165ed4 commit 3514da5

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

drivers/md/raid5.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,24 @@ static bool has_failed(struct r5conf *conf)
755755
return degraded > conf->max_degraded;
756756
}
757757

758+
/*
759+
* Block until another thread clears R5_INACTIVE_BLOCKED or
760+
* there are fewer than 3/4 the maximum number of active stripes
761+
* and there is an inactive stripe available.
762+
*/
763+
static bool is_inactive_blocked(struct r5conf *conf, int hash)
764+
{
765+
int active = atomic_read(&conf->active_stripes);
766+
767+
if (list_empty(conf->inactive_list + hash))
768+
return false;
769+
770+
if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state))
771+
return true;
772+
773+
return active < (conf->max_nr_stripes * 3 / 4);
774+
}
775+
758776
struct stripe_head *
759777
raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
760778
int previous, int noblock, int noquiesce)
@@ -796,11 +814,7 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
796814
set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
797815
r5l_wake_reclaim(conf->log, 0);
798816
wait_event_lock_irq(conf->wait_for_stripe,
799-
!list_empty(conf->inactive_list + hash) &&
800-
(atomic_read(&conf->active_stripes)
801-
< (conf->max_nr_stripes * 3 / 4)
802-
|| !test_bit(R5_INACTIVE_BLOCKED,
803-
&conf->cache_state)),
817+
is_inactive_blocked(conf, hash),
804818
*(conf->hash_locks + hash));
805819
clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
806820
goto retry;

0 commit comments

Comments
 (0)