Skip to content

Commit 808c680

Browse files
author
Kent Overstreet
committed
bcachefs: Add persistent identifiers for recovery passes
The next patch will start to refer to recovery passes from the superblock; naturally, we now need identifiers that don't change, since the existing enum is in the order in which they are run and is not fixed. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 560661d commit 808c680

File tree

3 files changed

+84
-39
lines changed

3 files changed

+84
-39
lines changed

fs/bcachefs/recovery.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct bch_fs *c)
481481
}
482482

483483
const char * const bch2_recovery_passes[] = {
484-
#define x(_fn, _when) #_fn,
484+
#define x(_fn, ...) #_fn,
485485
BCH_RECOVERY_PASSES()
486486
#undef x
487487
NULL
@@ -504,11 +504,41 @@ struct recovery_pass_fn {
504504
};
505505

506506
static struct recovery_pass_fn recovery_pass_fns[] = {
507-
#define x(_fn, _when) { .fn = bch2_##_fn, .when = _when },
507+
#define x(_fn, _id, _when) { .fn = bch2_##_fn, .when = _when },
508508
BCH_RECOVERY_PASSES()
509509
#undef x
510510
};
511511

512+
u64 bch2_recovery_passes_to_stable(u64 v)
513+
{
514+
static const u8 map[] = {
515+
#define x(n, id, ...) [BCH_RECOVERY_PASS_##n] = BCH_RECOVERY_PASS_STABLE_##n,
516+
BCH_RECOVERY_PASSES()
517+
#undef x
518+
};
519+
520+
u64 ret = 0;
521+
for (unsigned i = 0; i < ARRAY_SIZE(map); i++)
522+
if (v & BIT_ULL(i))
523+
ret |= BIT_ULL(map[i]);
524+
return ret;
525+
}
526+
527+
u64 bch2_recovery_passes_from_stable(u64 v)
528+
{
529+
static const u8 map[] = {
530+
#define x(n, id, ...) [BCH_RECOVERY_PASS_STABLE_##n] = BCH_RECOVERY_PASS_##n,
531+
BCH_RECOVERY_PASSES()
532+
#undef x
533+
};
534+
535+
u64 ret = 0;
536+
for (unsigned i = 0; i < ARRAY_SIZE(map); i++)
537+
if (v & BIT_ULL(i))
538+
ret |= BIT_ULL(map[i]);
539+
return ret;
540+
}
541+
512542
static void check_version_upgrade(struct bch_fs *c)
513543
{
514544
unsigned latest_compatible = bch2_latest_compatible_version(c->sb.version);

fs/bcachefs/recovery.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
extern const char * const bch2_recovery_passes[];
66

7+
u64 bch2_recovery_passes_to_stable(u64 v);
8+
u64 bch2_recovery_passes_from_stable(u64 v);
9+
710
/*
811
* For when we need to rewind recovery passes and run a pass we skipped:
912
*/

fs/bcachefs/recovery_types.h

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,57 @@
77
#define PASS_UNCLEAN BIT(2)
88
#define PASS_ALWAYS BIT(3)
99

10-
#define BCH_RECOVERY_PASSES() \
11-
x(alloc_read, PASS_ALWAYS) \
12-
x(stripes_read, PASS_ALWAYS) \
13-
x(initialize_subvolumes, 0) \
14-
x(snapshots_read, PASS_ALWAYS) \
15-
x(check_topology, 0) \
16-
x(check_allocations, PASS_FSCK) \
17-
x(trans_mark_dev_sbs, PASS_ALWAYS|PASS_SILENT) \
18-
x(fs_journal_alloc, PASS_ALWAYS|PASS_SILENT) \
19-
x(set_may_go_rw, PASS_ALWAYS|PASS_SILENT) \
20-
x(journal_replay, PASS_ALWAYS) \
21-
x(check_alloc_info, PASS_FSCK) \
22-
x(check_lrus, PASS_FSCK) \
23-
x(check_btree_backpointers, PASS_FSCK) \
24-
x(check_backpointers_to_extents,PASS_FSCK) \
25-
x(check_extents_to_backpointers,PASS_FSCK) \
26-
x(check_alloc_to_lru_refs, PASS_FSCK) \
27-
x(fs_freespace_init, PASS_ALWAYS|PASS_SILENT) \
28-
x(bucket_gens_init, 0) \
29-
x(check_snapshot_trees, PASS_FSCK) \
30-
x(check_snapshots, PASS_FSCK) \
31-
x(check_subvols, PASS_FSCK) \
32-
x(delete_dead_snapshots, PASS_FSCK) \
33-
x(fs_upgrade_for_subvolumes, 0) \
34-
x(resume_logged_ops, PASS_ALWAYS) \
35-
x(check_inodes, PASS_FSCK) \
36-
x(check_extents, PASS_FSCK) \
37-
x(check_indirect_extents, PASS_FSCK) \
38-
x(check_dirents, PASS_FSCK) \
39-
x(check_xattrs, PASS_FSCK) \
40-
x(check_root, PASS_FSCK) \
41-
x(check_directory_structure, PASS_FSCK) \
42-
x(check_nlinks, PASS_FSCK) \
43-
x(delete_dead_inodes, PASS_FSCK|PASS_UNCLEAN) \
44-
x(fix_reflink_p, 0) \
45-
x(set_fs_needs_rebalance, 0) \
10+
/*
11+
* Passes may be reordered, but the second field is a persistent identifier and
12+
* must never change:
13+
*/
14+
#define BCH_RECOVERY_PASSES() \
15+
x(alloc_read, 0, PASS_ALWAYS) \
16+
x(stripes_read, 1, PASS_ALWAYS) \
17+
x(initialize_subvolumes, 2, 0) \
18+
x(snapshots_read, 3, PASS_ALWAYS) \
19+
x(check_topology, 4, 0) \
20+
x(check_allocations, 5, PASS_FSCK) \
21+
x(trans_mark_dev_sbs, 6, PASS_ALWAYS|PASS_SILENT) \
22+
x(fs_journal_alloc, 7, PASS_ALWAYS|PASS_SILENT) \
23+
x(set_may_go_rw, 8, PASS_ALWAYS|PASS_SILENT) \
24+
x(journal_replay, 9, PASS_ALWAYS) \
25+
x(check_alloc_info, 10, PASS_FSCK) \
26+
x(check_lrus, 11, PASS_FSCK) \
27+
x(check_btree_backpointers, 12, PASS_FSCK) \
28+
x(check_backpointers_to_extents, 13, PASS_FSCK) \
29+
x(check_extents_to_backpointers, 14, PASS_FSCK) \
30+
x(check_alloc_to_lru_refs, 15, PASS_FSCK) \
31+
x(fs_freespace_init, 16, PASS_ALWAYS|PASS_SILENT) \
32+
x(bucket_gens_init, 17, 0) \
33+
x(check_snapshot_trees, 18, PASS_FSCK) \
34+
x(check_snapshots, 19, PASS_FSCK) \
35+
x(check_subvols, 20, PASS_FSCK) \
36+
x(delete_dead_snapshots, 21, PASS_FSCK) \
37+
x(fs_upgrade_for_subvolumes, 22, 0) \
38+
x(resume_logged_ops, 23, PASS_ALWAYS) \
39+
x(check_inodes, 24, PASS_FSCK) \
40+
x(check_extents, 25, PASS_FSCK) \
41+
x(check_indirect_extents, 26, PASS_FSCK) \
42+
x(check_dirents, 27, PASS_FSCK) \
43+
x(check_xattrs, 28, PASS_FSCK) \
44+
x(check_root, 29, PASS_FSCK) \
45+
x(check_directory_structure, 30, PASS_FSCK) \
46+
x(check_nlinks, 31, PASS_FSCK) \
47+
x(delete_dead_inodes, 32, PASS_FSCK|PASS_UNCLEAN) \
48+
x(fix_reflink_p, 33, 0) \
49+
x(set_fs_needs_rebalance, 34, 0) \
4650

51+
/* We normally enumerate recovery passes in the order we run them: */
4752
enum bch_recovery_pass {
48-
#define x(n, when) BCH_RECOVERY_PASS_##n,
53+
#define x(n, id, when) BCH_RECOVERY_PASS_##n,
54+
BCH_RECOVERY_PASSES()
55+
#undef x
56+
};
57+
58+
/* But we also need stable identifiers that can be used in the superblock */
59+
enum bch_recovery_pass_stable {
60+
#define x(n, id, when) BCH_RECOVERY_PASS_STABLE_##n = id,
4961
BCH_RECOVERY_PASSES()
5062
#undef x
5163
};

0 commit comments

Comments
 (0)