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 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 bool xrep_will_attempt(struct xfs_scrub *sc); 32 void xrep_failure(struct xfs_mount *mp); 33 int xrep_roll_ag_trans(struct xfs_scrub *sc); 34 int xrep_roll_trans(struct xfs_scrub *sc); 35 int xrep_defer_finish(struct xfs_scrub *sc); 36 bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks, 37 enum xfs_ag_resv_type type); 38 xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc); 39 40 static inline int 41 xrep_trans_commit( 42 struct xfs_scrub *sc) 43 { 44 int error = xfs_trans_commit(sc->tp); 45 46 sc->tp = NULL; 47 return error; 48 } 49 50 struct xbitmap; 51 struct xagb_bitmap; 52 struct xfsb_bitmap; 53 54 int xrep_fix_freelist(struct xfs_scrub *sc, bool can_shrink); 55 56 struct xrep_find_ag_btree { 57 /* in: rmap owner of the btree we're looking for */ 58 uint64_t rmap_owner; 59 60 /* in: buffer ops */ 61 const struct xfs_buf_ops *buf_ops; 62 63 /* in: maximum btree height */ 64 unsigned int maxlevels; 65 66 /* out: the highest btree block found and the tree height */ 67 xfs_agblock_t root; 68 unsigned int height; 69 }; 70 71 int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp, 72 struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp); 73 74 #ifdef CONFIG_XFS_QUOTA 75 void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type); 76 int xrep_ino_dqattach(struct xfs_scrub *sc); 77 #else 78 # define xrep_force_quotacheck(sc, type) ((void)0) 79 # define xrep_ino_dqattach(sc) (0) 80 #endif /* CONFIG_XFS_QUOTA */ 81 82 int xrep_ino_ensure_extent_count(struct xfs_scrub *sc, int whichfork, 83 xfs_extnum_t nextents); 84 int xrep_reset_perag_resv(struct xfs_scrub *sc); 85 int xrep_bmap(struct xfs_scrub *sc, int whichfork, bool allow_unwritten); 86 int xrep_metadata_inode_forks(struct xfs_scrub *sc); 87 88 /* Repair setup functions */ 89 int xrep_setup_ag_allocbt(struct xfs_scrub *sc); 90 91 struct xfs_imap; 92 int xrep_setup_inode(struct xfs_scrub *sc, const struct xfs_imap *imap); 93 94 void xrep_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa); 95 int xrep_ag_init(struct xfs_scrub *sc, struct xfs_perag *pag, 96 struct xchk_ag *sa); 97 98 /* Metadata revalidators */ 99 100 int xrep_revalidate_allocbt(struct xfs_scrub *sc); 101 int xrep_revalidate_iallocbt(struct xfs_scrub *sc); 102 103 /* Metadata repairers */ 104 105 int xrep_probe(struct xfs_scrub *sc); 106 int xrep_superblock(struct xfs_scrub *sc); 107 int xrep_agf(struct xfs_scrub *sc); 108 int xrep_agfl(struct xfs_scrub *sc); 109 int xrep_agi(struct xfs_scrub *sc); 110 int xrep_allocbt(struct xfs_scrub *sc); 111 int xrep_iallocbt(struct xfs_scrub *sc); 112 int xrep_refcountbt(struct xfs_scrub *sc); 113 int xrep_inode(struct xfs_scrub *sc); 114 int xrep_bmap_data(struct xfs_scrub *sc); 115 int xrep_bmap_attr(struct xfs_scrub *sc); 116 int xrep_bmap_cow(struct xfs_scrub *sc); 117 118 #ifdef CONFIG_XFS_RT 119 int xrep_rtbitmap(struct xfs_scrub *sc); 120 #else 121 # define xrep_rtbitmap xrep_notsupported 122 #endif /* CONFIG_XFS_RT */ 123 124 #ifdef CONFIG_XFS_QUOTA 125 int xrep_quota(struct xfs_scrub *sc); 126 #else 127 # define xrep_quota xrep_notsupported 128 #endif /* CONFIG_XFS_QUOTA */ 129 130 int xrep_reinit_pagf(struct xfs_scrub *sc); 131 int xrep_reinit_pagi(struct xfs_scrub *sc); 132 133 #else 134 135 #define xrep_ino_dqattach(sc) (0) 136 #define xrep_will_attempt(sc) (false) 137 138 static inline int 139 xrep_attempt( 140 struct xfs_scrub *sc, 141 struct xchk_stats_run *run) 142 { 143 return -EOPNOTSUPP; 144 } 145 146 static inline void xrep_failure(struct xfs_mount *mp) {} 147 148 static inline xfs_extlen_t 149 xrep_calc_ag_resblks( 150 struct xfs_scrub *sc) 151 { 152 return 0; 153 } 154 155 static inline int 156 xrep_reset_perag_resv( 157 struct xfs_scrub *sc) 158 { 159 if (!(sc->flags & XREP_RESET_PERAG_RESV)) 160 return 0; 161 162 ASSERT(0); 163 return -EOPNOTSUPP; 164 } 165 166 /* repair setup functions for no-repair */ 167 static inline int 168 xrep_setup_nothing( 169 struct xfs_scrub *sc) 170 { 171 return 0; 172 } 173 #define xrep_setup_ag_allocbt xrep_setup_nothing 174 175 #define xrep_setup_inode(sc, imap) ((void)0) 176 177 #define xrep_revalidate_allocbt (NULL) 178 #define xrep_revalidate_iallocbt (NULL) 179 180 #define xrep_probe xrep_notsupported 181 #define xrep_superblock xrep_notsupported 182 #define xrep_agf xrep_notsupported 183 #define xrep_agfl xrep_notsupported 184 #define xrep_agi xrep_notsupported 185 #define xrep_allocbt xrep_notsupported 186 #define xrep_iallocbt xrep_notsupported 187 #define xrep_refcountbt xrep_notsupported 188 #define xrep_inode xrep_notsupported 189 #define xrep_bmap_data xrep_notsupported 190 #define xrep_bmap_attr xrep_notsupported 191 #define xrep_bmap_cow xrep_notsupported 192 #define xrep_rtbitmap xrep_notsupported 193 #define xrep_quota xrep_notsupported 194 195 #endif /* CONFIG_XFS_ONLINE_REPAIR */ 196 197 #endif /* __XFS_SCRUB_REPAIR_H__ */ 198