xref: /openbmc/linux/fs/xfs/scrub/repair.h (revision d7a74cad)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2018-2023 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <djwong@kernel.org>
5  */
6 #ifndef __XFS_SCRUB_REPAIR_H__
7 #define __XFS_SCRUB_REPAIR_H__
8 
9 #include "xfs_quota_defs.h"
10 
11 struct xchk_stats_run;
12 
xrep_notsupported(struct xfs_scrub * sc)13 static inline int xrep_notsupported(struct xfs_scrub *sc)
14 {
15 	return -EOPNOTSUPP;
16 }
17 
18 #ifdef CONFIG_XFS_ONLINE_REPAIR
19 
20 /*
21  * This is the maximum number of deferred extent freeing item extents (EFIs)
22  * that we'll attach to a transaction without rolling the transaction to avoid
23  * overrunning a tr_itruncate reservation.
24  */
25 #define XREP_MAX_ITRUNCATE_EFIS	(128)
26 
27 
28 /* Repair helpers */
29 
30 int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run);
31 void xrep_failure(struct xfs_mount *mp);
32 int xrep_roll_ag_trans(struct xfs_scrub *sc);
33 int xrep_defer_finish(struct xfs_scrub *sc);
34 bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks,
35 		enum xfs_ag_resv_type type);
36 xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc);
37 
38 struct xbitmap;
39 struct xagb_bitmap;
40 
41 int xrep_fix_freelist(struct xfs_scrub *sc, bool can_shrink);
42 
43 struct xrep_find_ag_btree {
44 	/* in: rmap owner of the btree we're looking for */
45 	uint64_t			rmap_owner;
46 
47 	/* in: buffer ops */
48 	const struct xfs_buf_ops	*buf_ops;
49 
50 	/* in: maximum btree height */
51 	unsigned int			maxlevels;
52 
53 	/* out: the highest btree block found and the tree height */
54 	xfs_agblock_t			root;
55 	unsigned int			height;
56 };
57 
58 int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp,
59 		struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp);
60 void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type);
61 int xrep_ino_dqattach(struct xfs_scrub *sc);
62 
63 /* Metadata repairers */
64 
65 int xrep_probe(struct xfs_scrub *sc);
66 int xrep_superblock(struct xfs_scrub *sc);
67 int xrep_agf(struct xfs_scrub *sc);
68 int xrep_agfl(struct xfs_scrub *sc);
69 int xrep_agi(struct xfs_scrub *sc);
70 
71 #else
72 
73 static inline int
xrep_attempt(struct xfs_scrub * sc,struct xchk_stats_run * run)74 xrep_attempt(
75 	struct xfs_scrub	*sc,
76 	struct xchk_stats_run	*run)
77 {
78 	return -EOPNOTSUPP;
79 }
80 
xrep_failure(struct xfs_mount * mp)81 static inline void xrep_failure(struct xfs_mount *mp) {}
82 
83 static inline xfs_extlen_t
xrep_calc_ag_resblks(struct xfs_scrub * sc)84 xrep_calc_ag_resblks(
85 	struct xfs_scrub	*sc)
86 {
87 	return 0;
88 }
89 
90 #define xrep_probe			xrep_notsupported
91 #define xrep_superblock			xrep_notsupported
92 #define xrep_agf			xrep_notsupported
93 #define xrep_agfl			xrep_notsupported
94 #define xrep_agi			xrep_notsupported
95 
96 #endif /* CONFIG_XFS_ONLINE_REPAIR */
97 
98 #endif	/* __XFS_SCRUB_REPAIR_H__ */
99