1 /* 2 * Copyright (C) 2018 Oracle. All Rights Reserved. 3 * 4 * Author: Darrick J. Wong <darrick.wong@oracle.com> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it would be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 #ifndef __XFS_SCRUB_REPAIR_H__ 21 #define __XFS_SCRUB_REPAIR_H__ 22 23 static inline int xfs_repair_notsupported(struct xfs_scrub_context *sc) 24 { 25 return -EOPNOTSUPP; 26 } 27 28 #ifdef CONFIG_XFS_ONLINE_REPAIR 29 30 /* Repair helpers */ 31 32 int xfs_repair_attempt(struct xfs_inode *ip, struct xfs_scrub_context *sc, 33 bool *fixed); 34 void xfs_repair_failure(struct xfs_mount *mp); 35 int xfs_repair_roll_ag_trans(struct xfs_scrub_context *sc); 36 bool xfs_repair_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks, 37 enum xfs_ag_resv_type type); 38 xfs_extlen_t xfs_repair_calc_ag_resblks(struct xfs_scrub_context *sc); 39 int xfs_repair_alloc_ag_block(struct xfs_scrub_context *sc, 40 struct xfs_owner_info *oinfo, xfs_fsblock_t *fsbno, 41 enum xfs_ag_resv_type resv); 42 int xfs_repair_init_btblock(struct xfs_scrub_context *sc, xfs_fsblock_t fsb, 43 struct xfs_buf **bpp, xfs_btnum_t btnum, 44 const struct xfs_buf_ops *ops); 45 46 struct xfs_repair_extent { 47 struct list_head list; 48 xfs_fsblock_t fsbno; 49 xfs_extlen_t len; 50 }; 51 52 struct xfs_repair_extent_list { 53 struct list_head list; 54 }; 55 56 static inline void 57 xfs_repair_init_extent_list( 58 struct xfs_repair_extent_list *exlist) 59 { 60 INIT_LIST_HEAD(&exlist->list); 61 } 62 63 #define for_each_xfs_repair_extent_safe(rbe, n, exlist) \ 64 list_for_each_entry_safe((rbe), (n), &(exlist)->list, list) 65 int xfs_repair_collect_btree_extent(struct xfs_scrub_context *sc, 66 struct xfs_repair_extent_list *btlist, xfs_fsblock_t fsbno, 67 xfs_extlen_t len); 68 void xfs_repair_cancel_btree_extents(struct xfs_scrub_context *sc, 69 struct xfs_repair_extent_list *btlist); 70 int xfs_repair_subtract_extents(struct xfs_scrub_context *sc, 71 struct xfs_repair_extent_list *exlist, 72 struct xfs_repair_extent_list *sublist); 73 int xfs_repair_fix_freelist(struct xfs_scrub_context *sc, bool can_shrink); 74 int xfs_repair_invalidate_blocks(struct xfs_scrub_context *sc, 75 struct xfs_repair_extent_list *btlist); 76 int xfs_repair_reap_btree_extents(struct xfs_scrub_context *sc, 77 struct xfs_repair_extent_list *exlist, 78 struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type); 79 80 struct xfs_repair_find_ag_btree { 81 /* in: rmap owner of the btree we're looking for */ 82 uint64_t rmap_owner; 83 84 /* in: buffer ops */ 85 const struct xfs_buf_ops *buf_ops; 86 87 /* in: magic number of the btree */ 88 uint32_t magic; 89 90 /* out: the highest btree block found and the tree height */ 91 xfs_agblock_t root; 92 unsigned int height; 93 }; 94 95 int xfs_repair_find_ag_btree_roots(struct xfs_scrub_context *sc, 96 struct xfs_buf *agf_bp, 97 struct xfs_repair_find_ag_btree *btree_info, 98 struct xfs_buf *agfl_bp); 99 void xfs_repair_force_quotacheck(struct xfs_scrub_context *sc, uint dqtype); 100 int xfs_repair_ino_dqattach(struct xfs_scrub_context *sc); 101 102 /* Metadata repairers */ 103 104 int xfs_repair_probe(struct xfs_scrub_context *sc); 105 int xfs_repair_superblock(struct xfs_scrub_context *sc); 106 107 #else 108 109 static inline int xfs_repair_attempt( 110 struct xfs_inode *ip, 111 struct xfs_scrub_context *sc, 112 bool *fixed) 113 { 114 return -EOPNOTSUPP; 115 } 116 117 static inline void xfs_repair_failure(struct xfs_mount *mp) {} 118 119 static inline xfs_extlen_t 120 xfs_repair_calc_ag_resblks( 121 struct xfs_scrub_context *sc) 122 { 123 ASSERT(!(sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)); 124 return 0; 125 } 126 127 #define xfs_repair_probe xfs_repair_notsupported 128 #define xfs_repair_superblock xfs_repair_notsupported 129 130 #endif /* CONFIG_XFS_ONLINE_REPAIR */ 131 132 #endif /* __XFS_SCRUB_REPAIR_H__ */ 133