Commit 5165ed40 authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Jens Axboe

md/raid5: Refactor raid5_get_active_stripe()

Refactor the raid5_get_active_stripe() to read more linearly in
the order it's typically executed.

The init_stripe() call is called if a free stripe is found and the
function is exited early which removes a lot of if (sh) checks and
unindents the following code.

Remove the while loop in favour of the 'goto retry' pattern, which
reduces indentation further. And use a 'goto wait_for_stripe' instead
of an additional indent seeing it is the unusual path and this makes
the code easier to read.

No functional changes intended. Will make subsequent changes
in patches easier to understand.
Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent c55ddd90
...@@ -766,25 +766,33 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector, ...@@ -766,25 +766,33 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
spin_lock_irq(conf->hash_locks + hash); spin_lock_irq(conf->hash_locks + hash);
do { retry:
wait_event_lock_irq(conf->wait_for_quiescent, wait_event_lock_irq(conf->wait_for_quiescent,
conf->quiesce == 0 || noquiesce, conf->quiesce == 0 || noquiesce,
*(conf->hash_locks + hash)); *(conf->hash_locks + hash));
sh = find_get_stripe(conf, sector, conf->generation - previous, sh = find_get_stripe(conf, sector, conf->generation - previous, hash);
hash);
if (sh) if (sh)
break; goto out;
if (test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state))
goto wait_for_stripe;
if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) {
sh = get_free_stripe(conf, hash); sh = get_free_stripe(conf, hash);
if (!sh && !test_bit(R5_DID_ALLOC, &conf->cache_state)) if (sh) {
set_bit(R5_ALLOC_MORE, &conf->cache_state); r5c_check_stripe_cache_usage(conf);
init_stripe(sh, sector, previous);
atomic_inc(&sh->count);
goto out;
} }
if (noblock && !sh)
break; if (!test_bit(R5_DID_ALLOC, &conf->cache_state))
set_bit(R5_ALLOC_MORE, &conf->cache_state);
wait_for_stripe:
if (noblock)
goto out;
r5c_check_stripe_cache_usage(conf); r5c_check_stripe_cache_usage(conf);
if (!sh) {
set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
r5l_wake_reclaim(conf->log, 0); r5l_wake_reclaim(conf->log, 0);
wait_event_lock_irq(conf->wait_for_stripe, wait_event_lock_irq(conf->wait_for_stripe,
...@@ -795,12 +803,9 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector, ...@@ -795,12 +803,9 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
&conf->cache_state)), &conf->cache_state)),
*(conf->hash_locks + hash)); *(conf->hash_locks + hash));
clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
} else { goto retry;
init_stripe(sh, sector, previous);
atomic_inc(&sh->count);
}
} while (sh == NULL);
out:
spin_unlock_irq(conf->hash_locks + hash); spin_unlock_irq(conf->hash_locks + hash);
return sh; return sh;
} }
......
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