1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2018 Oracle. All Rights Reserved. 4 * Author: Darrick J. Wong <darrick.wong@oracle.com> 5 */ 6 #ifndef __XFS_SCRUB_REPAIR_H__ 7 #define __XFS_SCRUB_REPAIR_H__ 8 9 static inline int xfs_repair_notsupported(struct xfs_scrub_context *sc) 10 { 11 return -EOPNOTSUPP; 12 } 13 14 #ifdef CONFIG_XFS_ONLINE_REPAIR 15 16 /* Repair helpers */ 17 18 int xfs_repair_attempt(struct xfs_inode *ip, struct xfs_scrub_context *sc, 19 bool *fixed); 20 void xfs_repair_failure(struct xfs_mount *mp); 21 int xfs_repair_roll_ag_trans(struct xfs_scrub_context *sc); 22 bool xfs_repair_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks, 23 enum xfs_ag_resv_type type); 24 xfs_extlen_t xfs_repair_calc_ag_resblks(struct xfs_scrub_context *sc); 25 int xfs_repair_alloc_ag_block(struct xfs_scrub_context *sc, 26 struct xfs_owner_info *oinfo, xfs_fsblock_t *fsbno, 27 enum xfs_ag_resv_type resv); 28 int xfs_repair_init_btblock(struct xfs_scrub_context *sc, xfs_fsblock_t fsb, 29 struct xfs_buf **bpp, xfs_btnum_t btnum, 30 const struct xfs_buf_ops *ops); 31 32 struct xfs_repair_extent { 33 struct list_head list; 34 xfs_fsblock_t fsbno; 35 xfs_extlen_t len; 36 }; 37 38 struct xfs_repair_extent_list { 39 struct list_head list; 40 }; 41 42 static inline void 43 xfs_repair_init_extent_list( 44 struct xfs_repair_extent_list *exlist) 45 { 46 INIT_LIST_HEAD(&exlist->list); 47 } 48 49 #define for_each_xfs_repair_extent_safe(rbe, n, exlist) \ 50 list_for_each_entry_safe((rbe), (n), &(exlist)->list, list) 51 int xfs_repair_collect_btree_extent(struct xfs_scrub_context *sc, 52 struct xfs_repair_extent_list *btlist, xfs_fsblock_t fsbno, 53 xfs_extlen_t len); 54 void xfs_repair_cancel_btree_extents(struct xfs_scrub_context *sc, 55 struct xfs_repair_extent_list *btlist); 56 int xfs_repair_subtract_extents(struct xfs_scrub_context *sc, 57 struct xfs_repair_extent_list *exlist, 58 struct xfs_repair_extent_list *sublist); 59 int xfs_repair_fix_freelist(struct xfs_scrub_context *sc, bool can_shrink); 60 int xfs_repair_invalidate_blocks(struct xfs_scrub_context *sc, 61 struct xfs_repair_extent_list *btlist); 62 int xfs_repair_reap_btree_extents(struct xfs_scrub_context *sc, 63 struct xfs_repair_extent_list *exlist, 64 struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type); 65 66 struct xfs_repair_find_ag_btree { 67 /* in: rmap owner of the btree we're looking for */ 68 uint64_t rmap_owner; 69 70 /* in: buffer ops */ 71 const struct xfs_buf_ops *buf_ops; 72 73 /* in: magic number of the btree */ 74 uint32_t magic; 75 76 /* out: the highest btree block found and the tree height */ 77 xfs_agblock_t root; 78 unsigned int height; 79 }; 80 81 int xfs_repair_find_ag_btree_roots(struct xfs_scrub_context *sc, 82 struct xfs_buf *agf_bp, 83 struct xfs_repair_find_ag_btree *btree_info, 84 struct xfs_buf *agfl_bp); 85 void xfs_repair_force_quotacheck(struct xfs_scrub_context *sc, uint dqtype); 86 int xfs_repair_ino_dqattach(struct xfs_scrub_context *sc); 87 88 /* Metadata repairers */ 89 90 int xfs_repair_probe(struct xfs_scrub_context *sc); 91 int xfs_repair_superblock(struct xfs_scrub_context *sc); 92 93 #else 94 95 static inline int xfs_repair_attempt( 96 struct xfs_inode *ip, 97 struct xfs_scrub_context *sc, 98 bool *fixed) 99 { 100 return -EOPNOTSUPP; 101 } 102 103 static inline void xfs_repair_failure(struct xfs_mount *mp) {} 104 105 static inline xfs_extlen_t 106 xfs_repair_calc_ag_resblks( 107 struct xfs_scrub_context *sc) 108 { 109 ASSERT(!(sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)); 110 return 0; 111 } 112 113 #define xfs_repair_probe xfs_repair_notsupported 114 #define xfs_repair_superblock xfs_repair_notsupported 115 116 #endif /* CONFIG_XFS_ONLINE_REPAIR */ 117 118 #endif /* __XFS_SCRUB_REPAIR_H__ */ 119