Skip to content

Commit d64e8e8

Browse files
author
Kent Overstreet
committed
bcachefs: Refactor bch2_run_recovery_passes()
Don't use a continue; this simplifies the next patch where run_recovery_passes() will be responsible for waking up copygc and rebalance at the appropriate time. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 10e42b6 commit d64e8e8

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

fs/bcachefs/recovery_passes.c

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "journal.h"
1313
#include "lru.h"
1414
#include "logged_ops.h"
15+
#include "movinggc.h"
1516
#include "rebalance.h"
1617
#include "recovery.h"
1718
#include "recovery_passes.h"
@@ -262,49 +263,45 @@ int bch2_run_recovery_passes(struct bch_fs *c)
262263
*/
263264
c->opts.recovery_passes_exclude &= ~BCH_RECOVERY_PASS_set_may_go_rw;
264265

265-
while (c->curr_recovery_pass < ARRAY_SIZE(recovery_pass_fns) && !ret) {
266-
c->next_recovery_pass = c->curr_recovery_pass + 1;
266+
spin_lock_irq(&c->recovery_pass_lock);
267267

268-
spin_lock_irq(&c->recovery_pass_lock);
268+
while (c->curr_recovery_pass < ARRAY_SIZE(recovery_pass_fns) && !ret) {
269269
unsigned pass = c->curr_recovery_pass;
270270

271+
c->next_recovery_pass = pass + 1;
272+
271273
if (c->opts.recovery_pass_last &&
272-
c->curr_recovery_pass > c->opts.recovery_pass_last) {
273-
spin_unlock_irq(&c->recovery_pass_lock);
274+
c->curr_recovery_pass > c->opts.recovery_pass_last)
274275
break;
275-
}
276276

277-
if (!should_run_recovery_pass(c, pass)) {
278-
c->curr_recovery_pass++;
279-
c->recovery_pass_done = max(c->recovery_pass_done, pass);
277+
if (should_run_recovery_pass(c, pass)) {
280278
spin_unlock_irq(&c->recovery_pass_lock);
281-
continue;
282-
}
283-
spin_unlock_irq(&c->recovery_pass_lock);
284-
285-
ret = bch2_run_recovery_pass(c, pass) ?:
286-
bch2_journal_flush(&c->journal);
287-
288-
if (!ret && !test_bit(BCH_FS_error, &c->flags))
289-
bch2_clear_recovery_pass_required(c, pass);
290-
291-
spin_lock_irq(&c->recovery_pass_lock);
292-
if (c->next_recovery_pass < c->curr_recovery_pass) {
293-
/*
294-
* bch2_run_explicit_recovery_pass() was called: we
295-
* can't always catch -BCH_ERR_restart_recovery because
296-
* it may have been called from another thread (btree
297-
* node read completion)
298-
*/
299-
ret = 0;
300-
c->recovery_passes_complete &= ~(~0ULL << c->curr_recovery_pass);
301-
} else {
302-
c->recovery_passes_complete |= BIT_ULL(pass);
303-
c->recovery_pass_done = max(c->recovery_pass_done, pass);
279+
ret = bch2_run_recovery_pass(c, pass) ?:
280+
bch2_journal_flush(&c->journal);
281+
282+
if (!ret && !test_bit(BCH_FS_error, &c->flags))
283+
bch2_clear_recovery_pass_required(c, pass);
284+
spin_lock_irq(&c->recovery_pass_lock);
285+
286+
if (c->next_recovery_pass < c->curr_recovery_pass) {
287+
/*
288+
* bch2_run_explicit_recovery_pass() was called: we
289+
* can't always catch -BCH_ERR_restart_recovery because
290+
* it may have been called from another thread (btree
291+
* node read completion)
292+
*/
293+
ret = 0;
294+
c->recovery_passes_complete &= ~(~0ULL << c->curr_recovery_pass);
295+
} else {
296+
c->recovery_passes_complete |= BIT_ULL(pass);
297+
c->recovery_pass_done = max(c->recovery_pass_done, pass);
298+
}
304299
}
300+
305301
c->curr_recovery_pass = c->next_recovery_pass;
306-
spin_unlock_irq(&c->recovery_pass_lock);
307302
}
308303

304+
spin_unlock_irq(&c->recovery_pass_lock);
305+
309306
return ret;
310307
}

0 commit comments

Comments
 (0)