xref: /linux/fs/bcachefs/recovery_passes_format.h (revision ff0905bbf991f4337b5ebc19c0d43525ebb0d96b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_RECOVERY_PASSES_FORMAT_H
3 #define _BCACHEFS_RECOVERY_PASSES_FORMAT_H
4 
5 #define PASS_SILENT		BIT(0)
6 #define PASS_FSCK		BIT(1)
7 #define PASS_UNCLEAN		BIT(2)
8 #define PASS_ALWAYS		BIT(3)
9 #define PASS_ONLINE		BIT(4)
10 #define PASS_ALLOC		BIT(5)
11 #define PASS_FSCK_ALLOC		(PASS_FSCK|PASS_ALLOC)
12 
13 #ifdef CONFIG_BCACHEFS_DEBUG
14 #define PASS_FSCK_DEBUG		BIT(1)
15 #else
16 #define PASS_FSCK_DEBUG		0
17 #endif
18 
19 /*
20  * Passes may be reordered, but the second field is a persistent identifier and
21  * must never change:
22  */
23 #define BCH_RECOVERY_PASSES()								\
24 	x(recovery_pass_empty,			41, PASS_SILENT)			\
25 	x(scan_for_btree_nodes,			37, 0)					\
26 	x(check_topology,			 4, 0)					\
27 	x(accounting_read,			39, PASS_ALWAYS)			\
28 	x(alloc_read,				 0, PASS_ALWAYS)			\
29 	x(stripes_read,				 1, 0)					\
30 	x(initialize_subvolumes,		 2, 0)					\
31 	x(snapshots_read,			 3, PASS_ALWAYS)			\
32 	x(check_allocations,			 5, PASS_FSCK_ALLOC)			\
33 	x(trans_mark_dev_sbs,			 6, PASS_ALWAYS|PASS_SILENT|PASS_ALLOC)	\
34 	x(fs_journal_alloc,			 7, PASS_ALWAYS|PASS_SILENT|PASS_ALLOC)	\
35 	x(set_may_go_rw,			 8, PASS_ALWAYS|PASS_SILENT)		\
36 	x(journal_replay,			 9, PASS_ALWAYS)			\
37 	x(check_alloc_info,			10, PASS_ONLINE|PASS_FSCK_ALLOC)	\
38 	x(check_lrus,				11, PASS_ONLINE|PASS_FSCK_ALLOC)	\
39 	x(check_btree_backpointers,		12, PASS_ONLINE|PASS_FSCK_ALLOC)	\
40 	x(check_backpointers_to_extents,	13, PASS_ONLINE|PASS_FSCK_DEBUG)	\
41 	x(check_extents_to_backpointers,	14, PASS_ONLINE|PASS_FSCK_ALLOC)	\
42 	x(check_alloc_to_lru_refs,		15, PASS_ONLINE|PASS_FSCK_ALLOC)	\
43 	x(fs_freespace_init,			16, PASS_ALWAYS|PASS_SILENT)		\
44 	x(bucket_gens_init,			17, 0)					\
45 	x(reconstruct_snapshots,		38, 0)					\
46 	x(check_snapshot_trees,			18, PASS_ONLINE|PASS_FSCK)		\
47 	x(check_snapshots,			19, PASS_ONLINE|PASS_FSCK)		\
48 	x(check_subvols,			20, PASS_ONLINE|PASS_FSCK)		\
49 	x(check_subvol_children,		35, PASS_ONLINE|PASS_FSCK)		\
50 	x(delete_dead_snapshots,		21, PASS_ONLINE|PASS_FSCK)		\
51 	x(fs_upgrade_for_subvolumes,		22, 0)					\
52 	x(check_inodes,				24, PASS_FSCK)				\
53 	x(check_extents,			25, PASS_FSCK)				\
54 	x(check_indirect_extents,		26, PASS_ONLINE|PASS_FSCK)		\
55 	x(check_dirents,			27, PASS_FSCK)				\
56 	x(check_xattrs,				28, PASS_FSCK)				\
57 	x(check_root,				29, PASS_ONLINE|PASS_FSCK)		\
58 	x(check_unreachable_inodes,		40, PASS_FSCK)				\
59 	x(check_subvolume_structure,		36, PASS_ONLINE|PASS_FSCK)		\
60 	x(check_directory_structure,		30, PASS_ONLINE|PASS_FSCK)		\
61 	x(check_nlinks,				31, PASS_FSCK)				\
62 	x(check_rebalance_work,			43, PASS_ONLINE|PASS_FSCK)		\
63 	x(resume_logged_ops,			23, PASS_ALWAYS)			\
64 	x(delete_dead_inodes,			32, PASS_ALWAYS)			\
65 	x(fix_reflink_p,			33, 0)					\
66 	x(set_fs_needs_rebalance,		34, 0)					\
67 	x(lookup_root_inode,			42, PASS_ALWAYS|PASS_SILENT)
68 
69 /* We normally enumerate recovery passes in the order we run them: */
70 enum bch_recovery_pass {
71 #define x(n, id, when)	BCH_RECOVERY_PASS_##n,
72 	BCH_RECOVERY_PASSES()
73 #undef x
74 	BCH_RECOVERY_PASS_NR
75 };
76 
77 /* But we also need stable identifiers that can be used in the superblock */
78 enum bch_recovery_pass_stable {
79 #define x(n, id, when)	BCH_RECOVERY_PASS_STABLE_##n = id,
80 	BCH_RECOVERY_PASSES()
81 #undef x
82 };
83 
84 struct recovery_pass_entry {
85 	__le64			last_run;
86 	__le32			last_runtime;
87 	__le32			flags;
88 };
89 
90 LE32_BITMASK(BCH_RECOVERY_PASS_NO_RATELIMIT,	struct recovery_pass_entry, flags, 0, 1)
91 
92 struct bch_sb_field_recovery_passes {
93 	struct bch_sb_field	field;
94 	struct recovery_pass_entry start[];
95 };
96 
97 static inline unsigned
recovery_passes_nr_entries(struct bch_sb_field_recovery_passes * r)98 recovery_passes_nr_entries(struct bch_sb_field_recovery_passes *r)
99 {
100 	return r
101 		? ((vstruct_end(&r->field) - (void *) &r->start[0]) /
102 		   sizeof(struct recovery_pass_entry))
103 		: 0;
104 }
105 
106 #endif /* _BCACHEFS_RECOVERY_PASSES_FORMAT_H */
107