Skip to content

Commit

Permalink
md/raid5: Make is_inactive_blocked() helper
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lsgunth authored and axboe committed Aug 3, 2022
1 parent 5165ed4 commit 3514da5
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions drivers/md/raid5.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,24 @@ static bool has_failed(struct r5conf *conf)
return degraded > conf->max_degraded;
}

/*
* Block until another thread clears R5_INACTIVE_BLOCKED or
* there are fewer than 3/4 the maximum number of active stripes
* and there is an inactive stripe available.
*/
static bool is_inactive_blocked(struct r5conf *conf, int hash)
{
int active = atomic_read(&conf->active_stripes);

if (list_empty(conf->inactive_list + hash))
return false;

if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state))
return true;

return active < (conf->max_nr_stripes * 3 / 4);
}

struct stripe_head *
raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
int previous, int noblock, int noquiesce)
Expand Down Expand Up @@ -796,11 +814,7 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
r5l_wake_reclaim(conf->log, 0);
wait_event_lock_irq(conf->wait_for_stripe,
!list_empty(conf->inactive_list + hash) &&
(atomic_read(&conf->active_stripes)
< (conf->max_nr_stripes * 3 / 4)
|| !test_bit(R5_INACTIVE_BLOCKED,
&conf->cache_state)),
is_inactive_blocked(conf, hash),
*(conf->hash_locks + hash));
clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
goto retry;
Expand Down

0 comments on commit 3514da5

Please sign in to comment.