xref: /linux/fs/bcachefs/recovery_passes_format.h (revision ff0905bbf991f4337b5ebc19c0d43525ebb0d96b)
120a4b7f3SKent Overstreet /* SPDX-License-Identifier: GPL-2.0 */
220a4b7f3SKent Overstreet #ifndef _BCACHEFS_RECOVERY_PASSES_FORMAT_H
320a4b7f3SKent Overstreet #define _BCACHEFS_RECOVERY_PASSES_FORMAT_H
420a4b7f3SKent Overstreet 
520a4b7f3SKent Overstreet #define PASS_SILENT		BIT(0)
620a4b7f3SKent Overstreet #define PASS_FSCK		BIT(1)
720a4b7f3SKent Overstreet #define PASS_UNCLEAN		BIT(2)
820a4b7f3SKent Overstreet #define PASS_ALWAYS		BIT(3)
920a4b7f3SKent Overstreet #define PASS_ONLINE		BIT(4)
1020a4b7f3SKent Overstreet #define PASS_ALLOC		BIT(5)
1120a4b7f3SKent Overstreet #define PASS_FSCK_ALLOC		(PASS_FSCK|PASS_ALLOC)
1220a4b7f3SKent Overstreet 
1320a4b7f3SKent Overstreet #ifdef CONFIG_BCACHEFS_DEBUG
1420a4b7f3SKent Overstreet #define PASS_FSCK_DEBUG		BIT(1)
1520a4b7f3SKent Overstreet #else
1620a4b7f3SKent Overstreet #define PASS_FSCK_DEBUG		0
1720a4b7f3SKent Overstreet #endif
1820a4b7f3SKent Overstreet 
1920a4b7f3SKent Overstreet /*
2020a4b7f3SKent Overstreet  * Passes may be reordered, but the second field is a persistent identifier and
2120a4b7f3SKent Overstreet  * must never change:
2220a4b7f3SKent Overstreet  */
2320a4b7f3SKent Overstreet #define BCH_RECOVERY_PASSES()								\
2420a4b7f3SKent Overstreet 	x(recovery_pass_empty,			41, PASS_SILENT)			\
2520a4b7f3SKent Overstreet 	x(scan_for_btree_nodes,			37, 0)					\
2620a4b7f3SKent Overstreet 	x(check_topology,			 4, 0)					\
2720a4b7f3SKent Overstreet 	x(accounting_read,			39, PASS_ALWAYS)			\
2820a4b7f3SKent Overstreet 	x(alloc_read,				 0, PASS_ALWAYS)			\
2920a4b7f3SKent Overstreet 	x(stripes_read,				 1, 0)					\
3020a4b7f3SKent Overstreet 	x(initialize_subvolumes,		 2, 0)					\
3120a4b7f3SKent Overstreet 	x(snapshots_read,			 3, PASS_ALWAYS)			\
3220a4b7f3SKent Overstreet 	x(check_allocations,			 5, PASS_FSCK_ALLOC)			\
3320a4b7f3SKent Overstreet 	x(trans_mark_dev_sbs,			 6, PASS_ALWAYS|PASS_SILENT|PASS_ALLOC)	\
3420a4b7f3SKent Overstreet 	x(fs_journal_alloc,			 7, PASS_ALWAYS|PASS_SILENT|PASS_ALLOC)	\
3520a4b7f3SKent Overstreet 	x(set_may_go_rw,			 8, PASS_ALWAYS|PASS_SILENT)		\
3620a4b7f3SKent Overstreet 	x(journal_replay,			 9, PASS_ALWAYS)			\
3720a4b7f3SKent Overstreet 	x(check_alloc_info,			10, PASS_ONLINE|PASS_FSCK_ALLOC)	\
3820a4b7f3SKent Overstreet 	x(check_lrus,				11, PASS_ONLINE|PASS_FSCK_ALLOC)	\
3920a4b7f3SKent Overstreet 	x(check_btree_backpointers,		12, PASS_ONLINE|PASS_FSCK_ALLOC)	\
4020a4b7f3SKent Overstreet 	x(check_backpointers_to_extents,	13, PASS_ONLINE|PASS_FSCK_DEBUG)	\
4120a4b7f3SKent Overstreet 	x(check_extents_to_backpointers,	14, PASS_ONLINE|PASS_FSCK_ALLOC)	\
4220a4b7f3SKent Overstreet 	x(check_alloc_to_lru_refs,		15, PASS_ONLINE|PASS_FSCK_ALLOC)	\
4320a4b7f3SKent Overstreet 	x(fs_freespace_init,			16, PASS_ALWAYS|PASS_SILENT)		\
4420a4b7f3SKent Overstreet 	x(bucket_gens_init,			17, 0)					\
4520a4b7f3SKent Overstreet 	x(reconstruct_snapshots,		38, 0)					\
4620a4b7f3SKent Overstreet 	x(check_snapshot_trees,			18, PASS_ONLINE|PASS_FSCK)		\
4720a4b7f3SKent Overstreet 	x(check_snapshots,			19, PASS_ONLINE|PASS_FSCK)		\
4820a4b7f3SKent Overstreet 	x(check_subvols,			20, PASS_ONLINE|PASS_FSCK)		\
4920a4b7f3SKent Overstreet 	x(check_subvol_children,		35, PASS_ONLINE|PASS_FSCK)		\
5020a4b7f3SKent Overstreet 	x(delete_dead_snapshots,		21, PASS_ONLINE|PASS_FSCK)		\
5120a4b7f3SKent Overstreet 	x(fs_upgrade_for_subvolumes,		22, 0)					\
5220a4b7f3SKent Overstreet 	x(check_inodes,				24, PASS_FSCK)				\
5320a4b7f3SKent Overstreet 	x(check_extents,			25, PASS_FSCK)				\
5420a4b7f3SKent Overstreet 	x(check_indirect_extents,		26, PASS_ONLINE|PASS_FSCK)		\
5520a4b7f3SKent Overstreet 	x(check_dirents,			27, PASS_FSCK)				\
5620a4b7f3SKent Overstreet 	x(check_xattrs,				28, PASS_FSCK)				\
5720a4b7f3SKent Overstreet 	x(check_root,				29, PASS_ONLINE|PASS_FSCK)		\
5820a4b7f3SKent Overstreet 	x(check_unreachable_inodes,		40, PASS_FSCK)				\
5920a4b7f3SKent Overstreet 	x(check_subvolume_structure,		36, PASS_ONLINE|PASS_FSCK)		\
6020a4b7f3SKent Overstreet 	x(check_directory_structure,		30, PASS_ONLINE|PASS_FSCK)		\
6120a4b7f3SKent Overstreet 	x(check_nlinks,				31, PASS_FSCK)				\
6220a4b7f3SKent Overstreet 	x(check_rebalance_work,			43, PASS_ONLINE|PASS_FSCK)		\
6320a4b7f3SKent Overstreet 	x(resume_logged_ops,			23, PASS_ALWAYS)			\
6420a4b7f3SKent Overstreet 	x(delete_dead_inodes,			32, PASS_ALWAYS)			\
6520a4b7f3SKent Overstreet 	x(fix_reflink_p,			33, 0)					\
6620a4b7f3SKent Overstreet 	x(set_fs_needs_rebalance,		34, 0)					\
6720a4b7f3SKent Overstreet 	x(lookup_root_inode,			42, PASS_ALWAYS|PASS_SILENT)
6820a4b7f3SKent Overstreet 
6920a4b7f3SKent Overstreet /* We normally enumerate recovery passes in the order we run them: */
7020a4b7f3SKent Overstreet enum bch_recovery_pass {
7120a4b7f3SKent Overstreet #define x(n, id, when)	BCH_RECOVERY_PASS_##n,
7220a4b7f3SKent Overstreet 	BCH_RECOVERY_PASSES()
7320a4b7f3SKent Overstreet #undef x
7420a4b7f3SKent Overstreet 	BCH_RECOVERY_PASS_NR
7520a4b7f3SKent Overstreet };
7620a4b7f3SKent Overstreet 
7720a4b7f3SKent Overstreet /* But we also need stable identifiers that can be used in the superblock */
7820a4b7f3SKent Overstreet enum bch_recovery_pass_stable {
7920a4b7f3SKent Overstreet #define x(n, id, when)	BCH_RECOVERY_PASS_STABLE_##n = id,
8020a4b7f3SKent Overstreet 	BCH_RECOVERY_PASSES()
8120a4b7f3SKent Overstreet #undef x
8220a4b7f3SKent Overstreet };
8320a4b7f3SKent Overstreet 
84e21f9977SKent Overstreet struct recovery_pass_entry {
85e21f9977SKent Overstreet 	__le64			last_run;
86e21f9977SKent Overstreet 	__le32			last_runtime;
87e21f9977SKent Overstreet 	__le32			flags;
88e21f9977SKent Overstreet };
89e21f9977SKent Overstreet 
90*0942b852SKent Overstreet LE32_BITMASK(BCH_RECOVERY_PASS_NO_RATELIMIT,	struct recovery_pass_entry, flags, 0, 1)
91*0942b852SKent Overstreet 
92e21f9977SKent Overstreet struct bch_sb_field_recovery_passes {
93e21f9977SKent Overstreet 	struct bch_sb_field	field;
94e21f9977SKent Overstreet 	struct recovery_pass_entry start[];
95e21f9977SKent Overstreet };
96e21f9977SKent Overstreet 
97e21f9977SKent Overstreet static inline unsigned
recovery_passes_nr_entries(struct bch_sb_field_recovery_passes * r)98e21f9977SKent Overstreet recovery_passes_nr_entries(struct bch_sb_field_recovery_passes *r)
99e21f9977SKent Overstreet {
100e21f9977SKent Overstreet 	return r
101e21f9977SKent Overstreet 		? ((vstruct_end(&r->field) - (void *) &r->start[0]) /
102e21f9977SKent Overstreet 		   sizeof(struct recovery_pass_entry))
103e21f9977SKent Overstreet 		: 0;
104e21f9977SKent Overstreet }
105e21f9977SKent Overstreet 
10620a4b7f3SKent Overstreet #endif /* _BCACHEFS_RECOVERY_PASSES_FORMAT_H */
107