Skip to content

Commit 5165ed4

Browse files
lsgunthaxboe
authored andcommitted
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: Logan Gunthorpe <[email protected]> Signed-off-by: Song Liu <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c55ddd9 commit 5165ed4

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

drivers/md/raid5.c

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -766,41 +766,46 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
766766

767767
spin_lock_irq(conf->hash_locks + hash);
768768

769-
do {
770-
wait_event_lock_irq(conf->wait_for_quiescent,
771-
conf->quiesce == 0 || noquiesce,
772-
*(conf->hash_locks + hash));
773-
sh = find_get_stripe(conf, sector, conf->generation - previous,
774-
hash);
775-
if (sh)
776-
break;
769+
retry:
770+
wait_event_lock_irq(conf->wait_for_quiescent,
771+
conf->quiesce == 0 || noquiesce,
772+
*(conf->hash_locks + hash));
773+
sh = find_get_stripe(conf, sector, conf->generation - previous, hash);
774+
if (sh)
775+
goto out;
777776

778-
if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) {
779-
sh = get_free_stripe(conf, hash);
780-
if (!sh && !test_bit(R5_DID_ALLOC, &conf->cache_state))
781-
set_bit(R5_ALLOC_MORE, &conf->cache_state);
782-
}
783-
if (noblock && !sh)
784-
break;
777+
if (test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state))
778+
goto wait_for_stripe;
785779

780+
sh = get_free_stripe(conf, hash);
781+
if (sh) {
786782
r5c_check_stripe_cache_usage(conf);
787-
if (!sh) {
788-
set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
789-
r5l_wake_reclaim(conf->log, 0);
790-
wait_event_lock_irq(conf->wait_for_stripe,
791-
!list_empty(conf->inactive_list + hash) &&
792-
(atomic_read(&conf->active_stripes)
793-
< (conf->max_nr_stripes * 3 / 4)
794-
|| !test_bit(R5_INACTIVE_BLOCKED,
795-
&conf->cache_state)),
796-
*(conf->hash_locks + hash));
797-
clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
798-
} else {
799-
init_stripe(sh, sector, previous);
800-
atomic_inc(&sh->count);
801-
}
802-
} while (sh == NULL);
783+
init_stripe(sh, sector, previous);
784+
atomic_inc(&sh->count);
785+
goto out;
786+
}
803787

788+
if (!test_bit(R5_DID_ALLOC, &conf->cache_state))
789+
set_bit(R5_ALLOC_MORE, &conf->cache_state);
790+
791+
wait_for_stripe:
792+
if (noblock)
793+
goto out;
794+
795+
r5c_check_stripe_cache_usage(conf);
796+
set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
797+
r5l_wake_reclaim(conf->log, 0);
798+
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)),
804+
*(conf->hash_locks + hash));
805+
clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state);
806+
goto retry;
807+
808+
out:
804809
spin_unlock_irq(conf->hash_locks + hash);
805810
return sh;
806811
}

0 commit comments

Comments
 (0)