Line data Source code
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 :
13 0 : static inline int xrep_notsupported(struct xfs_scrub *sc)
14 : {
15 0 : return -EOPNOTSUPP;
16 : }
17 :
18 : #ifdef CONFIG_XFS_ONLINE_REPAIR
19 :
20 : /* Repair helpers */
21 :
22 : int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run);
23 : bool xrep_will_attempt(struct xfs_scrub *sc);
24 : void xrep_failure(struct xfs_mount *mp);
25 : int xrep_roll_ag_trans(struct xfs_scrub *sc);
26 : int xrep_roll_trans(struct xfs_scrub *sc);
27 : int xrep_defer_finish(struct xfs_scrub *sc);
28 : bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks,
29 : enum xfs_ag_resv_type type);
30 : xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc);
31 :
32 : static inline int
33 : xrep_trans_commit(
34 : struct xfs_scrub *sc)
35 : {
36 7211410 : int error = xfs_trans_commit(sc->tp);
37 :
38 7212001 : sc->tp = NULL;
39 7212001 : return error;
40 : }
41 :
42 : struct xbitmap;
43 : struct xagb_bitmap;
44 : struct xrgb_bitmap;
45 : struct xfsb_bitmap;
46 : struct xrtb_bitmap;
47 :
48 : int xrep_fix_freelist(struct xfs_scrub *sc, int alloc_flags);
49 :
50 : struct xrep_find_ag_btree {
51 : /* in: rmap owner of the btree we're looking for */
52 : uint64_t rmap_owner;
53 :
54 : /* in: buffer ops */
55 : const struct xfs_buf_ops *buf_ops;
56 :
57 : /* in: maximum btree height */
58 : unsigned int maxlevels;
59 :
60 : /* out: the highest btree block found and the tree height */
61 : xfs_agblock_t root;
62 : unsigned int height;
63 : };
64 :
65 : int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp,
66 : struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp);
67 :
68 : #ifdef CONFIG_XFS_QUOTA
69 : void xrep_update_qflags(struct xfs_scrub *sc, unsigned int clear_flags,
70 : unsigned int set_flags);
71 : void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type);
72 : int xrep_ino_dqattach(struct xfs_scrub *sc);
73 : #else
74 : # define xrep_force_quotacheck(sc, type) ((void)0)
75 : # define xrep_ino_dqattach(sc) (0)
76 : #endif /* CONFIG_XFS_QUOTA */
77 :
78 : int xrep_setup_buftarg(struct xfs_scrub *sc, const char *descr);
79 :
80 : int xrep_ino_ensure_extent_count(struct xfs_scrub *sc, int whichfork,
81 : xfs_extnum_t nextents);
82 : int xrep_reset_perag_resv(struct xfs_scrub *sc);
83 : int xrep_bmap(struct xfs_scrub *sc, int whichfork, bool allow_unwritten);
84 : int xrep_metadata_inode_forks(struct xfs_scrub *sc);
85 : bool xrep_set_nlink(struct xfs_inode *ip, uint64_t nlink);
86 : int xrep_setup_ag_rmapbt(struct xfs_scrub *sc);
87 : int xrep_setup_ag_refcountbt(struct xfs_scrub *sc);
88 : int xrep_setup_rtsummary(struct xfs_scrub *sc, unsigned int *resblks,
89 : size_t *bufsize);
90 : int xrep_setup_xattr(struct xfs_scrub *sc);
91 : int xrep_setup_directory(struct xfs_scrub *sc);
92 : int xrep_setup_parent(struct xfs_scrub *sc);
93 : int xrep_setup_nlinks(struct xfs_scrub *sc);
94 : int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *resblks);
95 : int xrep_setup_dirtree(struct xfs_scrub *sc);
96 : int xrep_setup_rgbitmap(struct xfs_scrub *sc, unsigned int *resblks);
97 : int xrep_setup_rtrmapbt(struct xfs_scrub *sc);
98 : int xrep_setup_rtrefcountbt(struct xfs_scrub *sc);
99 :
100 : /* Repair setup functions */
101 : int xrep_setup_ag_allocbt(struct xfs_scrub *sc);
102 :
103 : struct xfs_imap;
104 : int xrep_setup_inode(struct xfs_scrub *sc, struct xfs_imap *imap);
105 : int xrep_setup_rtbitmap(struct xfs_scrub *sc, unsigned int *resblks);
106 :
107 : void xrep_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
108 : int xrep_ag_init(struct xfs_scrub *sc, struct xfs_perag *pag,
109 : struct xchk_ag *sa);
110 : #ifdef CONFIG_XFS_RT
111 : int xrep_rtgroup_init(struct xfs_scrub *sc, struct xfs_rtgroup *rtg,
112 : struct xchk_rt *sr, unsigned int rtglock_flags);
113 : void xrep_rtgroup_btcur_init(struct xfs_scrub *sc, struct xchk_rt *sr);
114 : int xrep_require_rtext_inuse(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
115 : xfs_filblks_t len, bool must_align);
116 : xfs_extlen_t xrep_calc_rtgroup_resblks(struct xfs_scrub *sc);
117 : #else
118 : # define xrep_rtgroup_init(sc, rtg, sr, lockflags) (-ENOSYS)
119 : # define xrep_calc_rtgroup_resblks(sc) (0)
120 : #endif /* CONFIG_XFS_RT */
121 :
122 : bool xrep_is_rtmeta_ino(struct xfs_scrub *sc, struct xfs_rtgroup *rtg,
123 : xfs_ino_t ino);
124 : int xrep_check_ino_btree_mapping(struct xfs_scrub *sc,
125 : const struct xfs_rmap_irec *rec);
126 :
127 : /* Metadata revalidators */
128 :
129 : int xrep_revalidate_allocbt(struct xfs_scrub *sc);
130 : int xrep_revalidate_iallocbt(struct xfs_scrub *sc);
131 :
132 : /* Metadata repairers */
133 :
134 : int xrep_probe(struct xfs_scrub *sc);
135 : int xrep_superblock(struct xfs_scrub *sc);
136 : int xrep_agf(struct xfs_scrub *sc);
137 : int xrep_agfl(struct xfs_scrub *sc);
138 : int xrep_agi(struct xfs_scrub *sc);
139 : int xrep_allocbt(struct xfs_scrub *sc);
140 : int xrep_iallocbt(struct xfs_scrub *sc);
141 : int xrep_rmapbt(struct xfs_scrub *sc);
142 : int xrep_refcountbt(struct xfs_scrub *sc);
143 : int xrep_inode(struct xfs_scrub *sc);
144 : int xrep_bmap_data(struct xfs_scrub *sc);
145 : int xrep_bmap_attr(struct xfs_scrub *sc);
146 : int xrep_bmap_cow(struct xfs_scrub *sc);
147 : int xrep_nlinks(struct xfs_scrub *sc);
148 : int xrep_fscounters(struct xfs_scrub *sc);
149 : int xrep_xattr(struct xfs_scrub *sc);
150 : int xrep_directory(struct xfs_scrub *sc);
151 : int xrep_parent(struct xfs_scrub *sc);
152 : int xrep_symlink(struct xfs_scrub *sc);
153 : int xrep_dirtree(struct xfs_scrub *sc);
154 :
155 : #ifdef CONFIG_XFS_RT
156 : int xrep_rtbitmap(struct xfs_scrub *sc);
157 : int xrep_rtsummary(struct xfs_scrub *sc);
158 : int xrep_rgsuperblock(struct xfs_scrub *sc);
159 : int xrep_rgbitmap(struct xfs_scrub *sc);
160 : int xrep_rtrmapbt(struct xfs_scrub *sc);
161 : int xrep_rtrefcountbt(struct xfs_scrub *sc);
162 : #else
163 : # define xrep_rtbitmap xrep_notsupported
164 : # define xrep_rtsummary xrep_notsupported
165 : # define xrep_rgsuperblock xrep_notsupported
166 : # define xrep_rgbitmap xrep_notsupported
167 : # define xrep_rtrmapbt xrep_notsupported
168 : # define xrep_rtrefcountbt xrep_notsupported
169 : #endif /* CONFIG_XFS_RT */
170 :
171 : #ifdef CONFIG_XFS_QUOTA
172 : int xrep_quota(struct xfs_scrub *sc);
173 : int xrep_quotacheck(struct xfs_scrub *sc);
174 : #else
175 : # define xrep_quota xrep_notsupported
176 : # define xrep_quotacheck xrep_notsupported
177 : #endif /* CONFIG_XFS_QUOTA */
178 :
179 : int xrep_reinit_pagf(struct xfs_scrub *sc);
180 : int xrep_reinit_pagi(struct xfs_scrub *sc);
181 :
182 : int xrep_trans_alloc_hook_dummy(struct xfs_mount *mp, void **cookiep,
183 : struct xfs_trans **tpp);
184 : void xrep_trans_cancel_hook_dummy(void **cookiep, struct xfs_trans *tp);
185 :
186 : bool xrep_buf_verify_struct(struct xfs_buf *bp, const struct xfs_buf_ops *ops);
187 : void xrep_inode_set_nblocks(struct xfs_scrub *sc, int64_t new_blocks);
188 : int xrep_reset_imeta_reservation(struct xfs_scrub *sc);
189 :
190 : #else
191 :
192 : #define xrep_ino_dqattach(sc) (0)
193 : #define xrep_will_attempt(sc) (false)
194 :
195 : static inline int
196 : xrep_attempt(
197 : struct xfs_scrub *sc,
198 : struct xchk_stats_run *run)
199 : {
200 : return -EOPNOTSUPP;
201 : }
202 :
203 : static inline void xrep_failure(struct xfs_mount *mp) {}
204 :
205 : static inline xfs_extlen_t
206 : xrep_calc_ag_resblks(
207 : struct xfs_scrub *sc)
208 : {
209 : return 0;
210 : }
211 :
212 : #define xrep_calc_rtgroup_resblks xrep_calc_ag_resblks
213 :
214 : static inline int
215 : xrep_reset_perag_resv(
216 : struct xfs_scrub *sc)
217 : {
218 : if (!(sc->flags & XREP_RESET_PERAG_RESV))
219 : return 0;
220 :
221 : ASSERT(0);
222 : return -EOPNOTSUPP;
223 : }
224 :
225 : /* repair setup functions for no-repair */
226 : static inline int
227 : xrep_setup_nothing(
228 : struct xfs_scrub *sc)
229 : {
230 : return 0;
231 : }
232 : #define xrep_setup_ag_allocbt xrep_setup_nothing
233 : #define xrep_setup_ag_rmapbt xrep_setup_nothing
234 : #define xrep_setup_ag_refcountbt xrep_setup_nothing
235 : #define xrep_setup_xattr xrep_setup_nothing
236 : #define xrep_setup_directory xrep_setup_nothing
237 : #define xrep_setup_parent xrep_setup_nothing
238 : #define xrep_setup_nlinks xrep_setup_nothing
239 : #define xrep_setup_dirtree xrep_setup_nothing
240 : #define xrep_setup_rtrmapbt xrep_setup_nothing
241 : #define xrep_setup_rtrefcountbt xrep_setup_nothing
242 :
243 : #define xrep_setup_inode(sc, imap) ((void)0)
244 :
245 : static inline int xrep_setup_rtbitmap(struct xfs_scrub *sc, unsigned int *x)
246 : {
247 : return 0;
248 : }
249 :
250 : static inline int
251 : xrep_setup_rtsummary(
252 : struct xfs_scrub *sc,
253 : unsigned int *whatever,
254 : size_t *dontcare)
255 : {
256 : return 0;
257 : }
258 :
259 : static inline int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *x)
260 : {
261 : return 0;
262 : }
263 :
264 : static inline int xrep_setup_rgbitmap(struct xfs_scrub *sc, unsigned int *x)
265 : {
266 : return 0;
267 : }
268 :
269 : #define xrep_revalidate_allocbt (NULL)
270 : #define xrep_revalidate_iallocbt (NULL)
271 :
272 : #define xrep_probe xrep_notsupported
273 : #define xrep_superblock xrep_notsupported
274 : #define xrep_agf xrep_notsupported
275 : #define xrep_agfl xrep_notsupported
276 : #define xrep_agi xrep_notsupported
277 : #define xrep_allocbt xrep_notsupported
278 : #define xrep_iallocbt xrep_notsupported
279 : #define xrep_rmapbt xrep_notsupported
280 : #define xrep_refcountbt xrep_notsupported
281 : #define xrep_inode xrep_notsupported
282 : #define xrep_bmap_data xrep_notsupported
283 : #define xrep_bmap_attr xrep_notsupported
284 : #define xrep_bmap_cow xrep_notsupported
285 : #define xrep_rtbitmap xrep_notsupported
286 : #define xrep_quota xrep_notsupported
287 : #define xrep_quotacheck xrep_notsupported
288 : #define xrep_nlinks xrep_notsupported
289 : #define xrep_fscounters xrep_notsupported
290 : #define xrep_rtsummary xrep_notsupported
291 : #define xrep_xattr xrep_notsupported
292 : #define xrep_directory xrep_notsupported
293 : #define xrep_parent xrep_notsupported
294 : #define xrep_symlink xrep_notsupported
295 : #define xrep_dirtree xrep_notsupported
296 : #define xrep_rgsuperblock xrep_notsupported
297 : #define xrep_rgbitmap xrep_notsupported
298 : #define xrep_rtrmapbt xrep_notsupported
299 : #define xrep_rtrefcountbt xrep_notsupported
300 :
301 : #endif /* CONFIG_XFS_ONLINE_REPAIR */
302 :
303 : #endif /* __XFS_SCRUB_REPAIR_H__ */
|