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 xfs_rtgroup; 12 struct xchk_stats_run; 13 14 static inline int xrep_notsupported(struct xfs_scrub *sc) 15 { 16 return -EOPNOTSUPP; 17 } 18 19 #ifdef CONFIG_XFS_ONLINE_REPAIR 20 21 /* 22 * This is the maximum number of deferred extent freeing item extents (EFIs) 23 * that we'll attach to a transaction without rolling the transaction to avoid 24 * overrunning a tr_itruncate reservation. 25 */ 26 #define XREP_MAX_ITRUNCATE_EFIS (128) 27 28 29 /* Repair helpers */ 30 31 int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run); 32 bool xrep_will_attempt(struct xfs_scrub *sc); 33 void xrep_failure(struct xfs_mount *mp); 34 int xrep_roll_ag_trans(struct xfs_scrub *sc); 35 int xrep_roll_trans(struct xfs_scrub *sc); 36 int xrep_defer_finish(struct xfs_scrub *sc); 37 bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks, 38 enum xfs_ag_resv_type type); 39 xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc); 40 41 static inline int 42 xrep_trans_commit( 43 struct xfs_scrub *sc) 44 { 45 int error = xfs_trans_commit(sc->tp); 46 47 sc->tp = NULL; 48 return error; 49 } 50 51 struct xbitmap; 52 struct xagb_bitmap; 53 struct xfsb_bitmap; 54 55 int xrep_fix_freelist(struct xfs_scrub *sc, int alloc_flags); 56 57 struct xrep_find_ag_btree { 58 /* in: rmap owner of the btree we're looking for */ 59 uint64_t rmap_owner; 60 61 /* in: buffer ops */ 62 const struct xfs_buf_ops *buf_ops; 63 64 /* in: maximum btree height */ 65 unsigned int maxlevels; 66 67 /* out: the highest btree block found and the tree height */ 68 xfs_agblock_t root; 69 unsigned int height; 70 }; 71 72 int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp, 73 struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp); 74 75 #ifdef CONFIG_XFS_QUOTA 76 void xrep_update_qflags(struct xfs_scrub *sc, unsigned int clear_flags, 77 unsigned int set_flags); 78 void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type); 79 int xrep_ino_dqattach(struct xfs_scrub *sc); 80 #else 81 # define xrep_force_quotacheck(sc, type) ((void)0) 82 # define xrep_ino_dqattach(sc) (0) 83 #endif /* CONFIG_XFS_QUOTA */ 84 85 int xrep_setup_xfbtree(struct xfs_scrub *sc, const char *descr); 86 87 int xrep_ino_ensure_extent_count(struct xfs_scrub *sc, int whichfork, 88 xfs_extnum_t nextents); 89 int xrep_reset_perag_resv(struct xfs_scrub *sc); 90 int xrep_bmap(struct xfs_scrub *sc, int whichfork, bool allow_unwritten); 91 int xrep_metadata_inode_forks(struct xfs_scrub *sc); 92 int xrep_setup_ag_rmapbt(struct xfs_scrub *sc); 93 int xrep_setup_ag_refcountbt(struct xfs_scrub *sc); 94 int xrep_setup_xattr(struct xfs_scrub *sc); 95 int xrep_setup_directory(struct xfs_scrub *sc); 96 int xrep_setup_parent(struct xfs_scrub *sc); 97 int xrep_setup_nlinks(struct xfs_scrub *sc); 98 int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *resblks); 99 int xrep_setup_dirtree(struct xfs_scrub *sc); 100 101 /* Repair setup functions */ 102 int xrep_setup_ag_allocbt(struct xfs_scrub *sc); 103 104 struct xfs_imap; 105 int xrep_setup_inode(struct xfs_scrub *sc, const struct xfs_imap *imap); 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 #else 114 # define xrep_rtgroup_init(sc, rtg, sr, lockflags) (-ENOSYS) 115 #endif /* CONFIG_XFS_RT */ 116 117 /* Metadata revalidators */ 118 119 int xrep_revalidate_allocbt(struct xfs_scrub *sc); 120 int xrep_revalidate_iallocbt(struct xfs_scrub *sc); 121 122 /* Metadata repairers */ 123 124 int xrep_probe(struct xfs_scrub *sc); 125 int xrep_superblock(struct xfs_scrub *sc); 126 int xrep_agf(struct xfs_scrub *sc); 127 int xrep_agfl(struct xfs_scrub *sc); 128 int xrep_agi(struct xfs_scrub *sc); 129 int xrep_allocbt(struct xfs_scrub *sc); 130 int xrep_iallocbt(struct xfs_scrub *sc); 131 int xrep_rmapbt(struct xfs_scrub *sc); 132 int xrep_refcountbt(struct xfs_scrub *sc); 133 int xrep_inode(struct xfs_scrub *sc); 134 int xrep_bmap_data(struct xfs_scrub *sc); 135 int xrep_bmap_attr(struct xfs_scrub *sc); 136 int xrep_bmap_cow(struct xfs_scrub *sc); 137 int xrep_nlinks(struct xfs_scrub *sc); 138 int xrep_fscounters(struct xfs_scrub *sc); 139 int xrep_xattr(struct xfs_scrub *sc); 140 int xrep_directory(struct xfs_scrub *sc); 141 int xrep_parent(struct xfs_scrub *sc); 142 int xrep_symlink(struct xfs_scrub *sc); 143 int xrep_dirtree(struct xfs_scrub *sc); 144 int xrep_metapath(struct xfs_scrub *sc); 145 146 #ifdef CONFIG_XFS_RT 147 int xrep_rtbitmap(struct xfs_scrub *sc); 148 int xrep_rtsummary(struct xfs_scrub *sc); 149 int xrep_rgsuperblock(struct xfs_scrub *sc); 150 #else 151 # define xrep_rtbitmap xrep_notsupported 152 # define xrep_rtsummary xrep_notsupported 153 # define xrep_rgsuperblock xrep_notsupported 154 #endif /* CONFIG_XFS_RT */ 155 156 #ifdef CONFIG_XFS_QUOTA 157 int xrep_quota(struct xfs_scrub *sc); 158 int xrep_quotacheck(struct xfs_scrub *sc); 159 #else 160 # define xrep_quota xrep_notsupported 161 # define xrep_quotacheck xrep_notsupported 162 #endif /* CONFIG_XFS_QUOTA */ 163 164 int xrep_reinit_pagf(struct xfs_scrub *sc); 165 int xrep_reinit_pagi(struct xfs_scrub *sc); 166 167 int xrep_trans_alloc_hook_dummy(struct xfs_mount *mp, void **cookiep, 168 struct xfs_trans **tpp); 169 void xrep_trans_cancel_hook_dummy(void **cookiep, struct xfs_trans *tp); 170 171 bool xrep_buf_verify_struct(struct xfs_buf *bp, const struct xfs_buf_ops *ops); 172 173 #else 174 175 #define xrep_ino_dqattach(sc) (0) 176 #define xrep_will_attempt(sc) (false) 177 178 static inline int 179 xrep_attempt( 180 struct xfs_scrub *sc, 181 struct xchk_stats_run *run) 182 { 183 return -EOPNOTSUPP; 184 } 185 186 static inline void xrep_failure(struct xfs_mount *mp) {} 187 188 static inline xfs_extlen_t 189 xrep_calc_ag_resblks( 190 struct xfs_scrub *sc) 191 { 192 return 0; 193 } 194 195 static inline int 196 xrep_reset_perag_resv( 197 struct xfs_scrub *sc) 198 { 199 if (!(sc->flags & XREP_RESET_PERAG_RESV)) 200 return 0; 201 202 ASSERT(0); 203 return -EOPNOTSUPP; 204 } 205 206 /* repair setup functions for no-repair */ 207 static inline int 208 xrep_setup_nothing( 209 struct xfs_scrub *sc) 210 { 211 return 0; 212 } 213 #define xrep_setup_ag_allocbt xrep_setup_nothing 214 #define xrep_setup_ag_rmapbt xrep_setup_nothing 215 #define xrep_setup_ag_refcountbt xrep_setup_nothing 216 #define xrep_setup_xattr xrep_setup_nothing 217 #define xrep_setup_directory xrep_setup_nothing 218 #define xrep_setup_parent xrep_setup_nothing 219 #define xrep_setup_nlinks xrep_setup_nothing 220 #define xrep_setup_dirtree xrep_setup_nothing 221 #define xrep_setup_metapath xrep_setup_nothing 222 223 #define xrep_setup_inode(sc, imap) ((void)0) 224 225 static inline int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *x) 226 { 227 return 0; 228 } 229 230 #define xrep_revalidate_allocbt (NULL) 231 #define xrep_revalidate_iallocbt (NULL) 232 233 #define xrep_probe xrep_notsupported 234 #define xrep_superblock xrep_notsupported 235 #define xrep_agf xrep_notsupported 236 #define xrep_agfl xrep_notsupported 237 #define xrep_agi xrep_notsupported 238 #define xrep_allocbt xrep_notsupported 239 #define xrep_iallocbt xrep_notsupported 240 #define xrep_rmapbt xrep_notsupported 241 #define xrep_refcountbt xrep_notsupported 242 #define xrep_inode xrep_notsupported 243 #define xrep_bmap_data xrep_notsupported 244 #define xrep_bmap_attr xrep_notsupported 245 #define xrep_bmap_cow xrep_notsupported 246 #define xrep_rtbitmap xrep_notsupported 247 #define xrep_quota xrep_notsupported 248 #define xrep_quotacheck xrep_notsupported 249 #define xrep_nlinks xrep_notsupported 250 #define xrep_fscounters xrep_notsupported 251 #define xrep_rtsummary xrep_notsupported 252 #define xrep_xattr xrep_notsupported 253 #define xrep_directory xrep_notsupported 254 #define xrep_parent xrep_notsupported 255 #define xrep_symlink xrep_notsupported 256 #define xrep_dirtree xrep_notsupported 257 #define xrep_metapath xrep_notsupported 258 #define xrep_rgsuperblock xrep_notsupported 259 260 #endif /* CONFIG_XFS_ONLINE_REPAIR */ 261 262 #endif /* __XFS_SCRUB_REPAIR_H__ */ 263