Skip to content

Commit a2ffab0

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_require_recovery_pass()
Add a helper for requiring that a recovery pass has already run: either run it directly, if we're still in recovery, or if we're not in recovery check if it has run recently and schedule it if it hasn't. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 09b9c72 commit a2ffab0

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

fs/bcachefs/errcode.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@
182182
x(BCH_ERR_fsck, fsck_errors_not_fixed) \
183183
x(BCH_ERR_fsck, fsck_repair_unimplemented) \
184184
x(BCH_ERR_fsck, fsck_repair_impossible) \
185-
x(EINVAL, restart_recovery) \
186-
x(EINVAL, cannot_rewind_recovery) \
185+
x(EINVAL, recovery_will_run) \
186+
x(BCH_ERR_recovery_will_run, restart_recovery) \
187+
x(BCH_ERR_recovery_will_run, cannot_rewind_recovery) \
188+
x(BCH_ERR_recovery_will_run, recovery_pass_will_run) \
187189
x(0, data_update_done) \
190+
x(0, bkey_was_deleted) \
188191
x(BCH_ERR_data_update_done, data_update_done_would_block) \
189192
x(BCH_ERR_data_update_done, data_update_done_unwritten) \
190193
x(BCH_ERR_data_update_done, data_update_done_no_writes_needed) \

fs/bcachefs/recovery_passes.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,35 @@ int bch2_run_explicit_recovery_pass(struct bch_fs *c,
384384
return ret;
385385
}
386386

387+
/*
388+
* Returns 0 if @pass has run recently, otherwise one of
389+
* -BCH_ERR_restart_recovery
390+
* -BCH_ERR_recovery_pass_will_run
391+
*/
392+
int bch2_require_recovery_pass(struct bch_fs *c,
393+
struct printbuf *out,
394+
enum bch_recovery_pass pass)
395+
{
396+
if (test_bit(BCH_FS_in_recovery, &c->flags) &&
397+
c->recovery.passes_complete & BIT_ULL(pass))
398+
return 0;
399+
400+
guard(mutex)(&c->sb_lock);
401+
402+
if (bch2_recovery_pass_want_ratelimit(c, pass))
403+
return 0;
404+
405+
enum bch_run_recovery_pass_flags flags = 0;
406+
int ret = 0;
407+
408+
if (recovery_pass_needs_set(c, pass, &flags)) {
409+
ret = __bch2_run_explicit_recovery_pass(c, out, pass, flags);
410+
bch2_write_super(c);
411+
}
412+
413+
return ret ?: bch_err_throw(c, recovery_pass_will_run);
414+
}
415+
387416
int bch2_run_print_explicit_recovery_pass(struct bch_fs *c, enum bch_recovery_pass pass)
388417
{
389418
enum bch_run_recovery_pass_flags flags = RUN_RECOVERY_PASS_nopersistent;

fs/bcachefs/recovery_passes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ int bch2_run_explicit_recovery_pass(struct bch_fs *, struct printbuf *,
2424
enum bch_recovery_pass,
2525
enum bch_run_recovery_pass_flags);
2626

27+
int bch2_require_recovery_pass(struct bch_fs *, struct printbuf *,
28+
enum bch_recovery_pass);
29+
2730
int bch2_run_online_recovery_passes(struct bch_fs *, u64);
2831
int bch2_run_recovery_passes(struct bch_fs *, enum bch_recovery_pass);
2932

0 commit comments

Comments
 (0)