Skip to content

Commit 4f19a60

Browse files
author
Kent Overstreet
committed
bcachefs: Options for recovery_passes, recovery_passes_exclude
This adds mount options for specifying recovery passes to run, or exclude; the immediate need for this is that backpointers fsck is having trouble completing, so we need a way to skip it. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent ff7f756 commit 4f19a60

8 files changed

Lines changed: 33 additions & 20 deletions

File tree

fs/bcachefs/bcachefs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,6 @@ struct bch_fs {
10451045
* for signaling to the toplevel code which pass we want to run now.
10461046
*/
10471047
enum bch_recovery_pass curr_recovery_pass;
1048-
/* bitmap of explicitly enabled recovery passes: */
1049-
u64 recovery_passes_explicit;
10501048
/* bitmask of recovery passes that we actually ran */
10511049
u64 recovery_passes_complete;
10521050
/* never rewinds version of curr_recovery_pass */

fs/bcachefs/btree_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
16661666
bch2_btree_pos_to_text(&buf, c, b);
16671667
bch_err_ratelimited(c, "%s", buf.buf);
16681668

1669-
if (c->recovery_passes_explicit & BIT_ULL(BCH_RECOVERY_PASS_check_topology) &&
1669+
if (c->opts.recovery_passes & BIT_ULL(BCH_RECOVERY_PASS_check_topology) &&
16701670
c->curr_recovery_pass > BCH_RECOVERY_PASS_check_topology)
16711671
bch2_fatal_error(c);
16721672

fs/bcachefs/btree_update_interior.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
146146
printbuf_exit(&buf);
147147
return ret;
148148
topology_repair:
149-
if ((c->recovery_passes_explicit & BIT_ULL(BCH_RECOVERY_PASS_check_topology)) &&
149+
if ((c->opts.recovery_passes & BIT_ULL(BCH_RECOVERY_PASS_check_topology)) &&
150150
c->curr_recovery_pass > BCH_RECOVERY_PASS_check_topology) {
151151
bch2_inconsistent_error(c);
152152
ret = -BCH_ERR_btree_need_topology_repair;

fs/bcachefs/opts.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ void bch2_opt_to_text(struct printbuf *out,
432432
else
433433
prt_str(out, opt->choices[v]);
434434
break;
435+
case BCH_OPT_BITFIELD:
436+
prt_bitflags(out, opt->choices, v);
437+
break;
435438
case BCH_OPT_FN:
436439
opt->fn.to_text(out, c, sb, v);
437440
break;

fs/bcachefs/opts.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,16 @@ enum fsck_err_opts {
373373
OPT_BOOL(), \
374374
BCH2_NO_SB_OPT, false, \
375375
NULL, "Exit recovery immediately prior to journal replay")\
376+
x(recovery_passes, u64, \
377+
OPT_FS|OPT_MOUNT, \
378+
OPT_BITFIELD(bch2_recovery_passes), \
379+
BCH2_NO_SB_OPT, 0, \
380+
NULL, "Recovery passes to run explicitly") \
381+
x(recovery_passes_exclude, u64, \
382+
OPT_FS|OPT_MOUNT, \
383+
OPT_BITFIELD(bch2_recovery_passes), \
384+
BCH2_NO_SB_OPT, 0, \
385+
NULL, "Recovery passes to exclude") \
376386
x(recovery_pass_last, u8, \
377387
OPT_FS|OPT_MOUNT, \
378388
OPT_STR_NOLIMIT(bch2_recovery_passes), \

fs/bcachefs/recovery.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void bch2_reconstruct_alloc(struct bch_fs *c)
9797
bch2_write_super(c);
9898
mutex_unlock(&c->sb_lock);
9999

100-
c->recovery_passes_explicit |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
100+
c->opts.recovery_passes |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
101101

102102

103103
bch2_shoot_down_journal_keys(c, BTREE_ID_alloc,
@@ -525,17 +525,17 @@ static int read_btree_roots(struct bch_fs *c)
525525
"error reading btree root %s l=%u: %s",
526526
bch2_btree_id_str(i), r->level, bch2_err_str(ret))) {
527527
if (btree_id_is_alloc(i)) {
528-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_allocations);
529-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_info);
530-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_lrus);
531-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_extents_to_backpointers);
532-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_to_lru_refs);
528+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_allocations);
529+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_info);
530+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_lrus);
531+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_extents_to_backpointers);
532+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_to_lru_refs);
533533
c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
534534
r->error = 0;
535-
} else if (!(c->recovery_passes_explicit & BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes))) {
535+
} else if (!(c->opts.recovery_passes & BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes))) {
536536
bch_info(c, "will run btree node scan");
537-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes);
538-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
537+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes);
538+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
539539
}
540540

541541
ret = 0;
@@ -706,14 +706,14 @@ int bch2_fs_recovery(struct bch_fs *c)
706706
if (check_version_upgrade(c))
707707
write_sb = true;
708708

709-
c->recovery_passes_explicit |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
709+
c->opts.recovery_passes |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
710710

711711
if (write_sb)
712712
bch2_write_super(c);
713713
mutex_unlock(&c->sb_lock);
714714

715715
if (c->opts.fsck && IS_ENABLED(CONFIG_BCACHEFS_DEBUG))
716-
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
716+
c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
717717

718718
if (c->opts.fsck)
719719
set_bit(BCH_FS_fsck_running, &c->flags);

fs/bcachefs/recovery_passes.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int bch2_set_may_go_rw(struct bch_fs *c)
4040

4141
set_bit(BCH_FS_may_go_rw, &c->flags);
4242

43-
if (keys->nr || c->opts.fsck || !c->sb.clean || c->recovery_passes_explicit)
43+
if (keys->nr || c->opts.fsck || !c->sb.clean || c->opts.recovery_passes)
4444
return bch2_fs_read_write_early(c);
4545
return 0;
4646
}
@@ -97,14 +97,14 @@ u64 bch2_recovery_passes_from_stable(u64 v)
9797
int bch2_run_explicit_recovery_pass(struct bch_fs *c,
9898
enum bch_recovery_pass pass)
9999
{
100-
if (c->recovery_passes_explicit & BIT_ULL(pass))
100+
if (c->opts.recovery_passes & BIT_ULL(pass))
101101
return 0;
102102

103103
bch_info(c, "running explicit recovery pass %s (%u), currently at %s (%u)",
104104
bch2_recovery_passes[pass], pass,
105105
bch2_recovery_passes[c->curr_recovery_pass], c->curr_recovery_pass);
106106

107-
c->recovery_passes_explicit |= BIT_ULL(pass);
107+
c->opts.recovery_passes |= BIT_ULL(pass);
108108

109109
if (c->curr_recovery_pass >= pass) {
110110
c->curr_recovery_pass = pass;
@@ -161,7 +161,9 @@ static bool should_run_recovery_pass(struct bch_fs *c, enum bch_recovery_pass pa
161161
{
162162
struct recovery_pass_fn *p = recovery_pass_fns + pass;
163163

164-
if (c->recovery_passes_explicit & BIT_ULL(pass))
164+
if (c->opts.recovery_passes_exclude & BIT_ULL(pass))
165+
return false;
166+
if (c->opts.recovery_passes & BIT_ULL(pass))
165167
return true;
166168
if ((p->when & PASS_FSCK) && c->opts.fsck)
167169
return true;

fs/bcachefs/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ u64 bch2_read_flag_list(const char *opt, const char * const list[])
214214

215215
s = strim(d);
216216

217-
while ((p = strsep(&s, ","))) {
217+
while ((p = strsep(&s, ",;"))) {
218218
int flag = match_string(list, -1, p);
219219

220220
if (flag < 0) {

0 commit comments

Comments
 (0)