1 /* 2 * Copyright (C) 2017 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_SCRUB_H__ 21 #define __XFS_SCRUB_SCRUB_H__ 22 23 struct xfs_scrub_context; 24 25 /* Type info and names for the scrub types. */ 26 enum xfs_scrub_type { 27 ST_NONE = 1, /* disabled */ 28 ST_PERAG, /* per-AG metadata */ 29 ST_FS, /* per-FS metadata */ 30 ST_INODE, /* per-inode metadata */ 31 }; 32 33 struct xfs_scrub_meta_ops { 34 /* Acquire whatever resources are needed for the operation. */ 35 int (*setup)(struct xfs_scrub_context *, 36 struct xfs_inode *); 37 38 /* Examine metadata for errors. */ 39 int (*scrub)(struct xfs_scrub_context *); 40 41 /* Decide if we even have this piece of metadata. */ 42 bool (*has)(struct xfs_sb *); 43 44 /* type describing required/allowed inputs */ 45 enum xfs_scrub_type type; 46 }; 47 48 /* Buffer pointers and btree cursors for an entire AG. */ 49 struct xfs_scrub_ag { 50 xfs_agnumber_t agno; 51 52 /* AG btree roots */ 53 struct xfs_buf *agf_bp; 54 struct xfs_buf *agfl_bp; 55 struct xfs_buf *agi_bp; 56 57 /* AG btrees */ 58 struct xfs_btree_cur *bno_cur; 59 struct xfs_btree_cur *cnt_cur; 60 struct xfs_btree_cur *ino_cur; 61 struct xfs_btree_cur *fino_cur; 62 struct xfs_btree_cur *rmap_cur; 63 struct xfs_btree_cur *refc_cur; 64 }; 65 66 struct xfs_scrub_context { 67 /* General scrub state. */ 68 struct xfs_mount *mp; 69 struct xfs_scrub_metadata *sm; 70 const struct xfs_scrub_meta_ops *ops; 71 struct xfs_trans *tp; 72 struct xfs_inode *ip; 73 void *buf; 74 uint ilock_flags; 75 bool try_harder; 76 77 /* State tracking for single-AG operations. */ 78 struct xfs_scrub_ag sa; 79 }; 80 81 /* Metadata scrubbers */ 82 int xfs_scrub_tester(struct xfs_scrub_context *sc); 83 int xfs_scrub_superblock(struct xfs_scrub_context *sc); 84 int xfs_scrub_agf(struct xfs_scrub_context *sc); 85 int xfs_scrub_agfl(struct xfs_scrub_context *sc); 86 int xfs_scrub_agi(struct xfs_scrub_context *sc); 87 int xfs_scrub_bnobt(struct xfs_scrub_context *sc); 88 int xfs_scrub_cntbt(struct xfs_scrub_context *sc); 89 int xfs_scrub_inobt(struct xfs_scrub_context *sc); 90 int xfs_scrub_finobt(struct xfs_scrub_context *sc); 91 int xfs_scrub_rmapbt(struct xfs_scrub_context *sc); 92 int xfs_scrub_refcountbt(struct xfs_scrub_context *sc); 93 int xfs_scrub_inode(struct xfs_scrub_context *sc); 94 int xfs_scrub_bmap_data(struct xfs_scrub_context *sc); 95 int xfs_scrub_bmap_attr(struct xfs_scrub_context *sc); 96 int xfs_scrub_bmap_cow(struct xfs_scrub_context *sc); 97 int xfs_scrub_directory(struct xfs_scrub_context *sc); 98 int xfs_scrub_xattr(struct xfs_scrub_context *sc); 99 int xfs_scrub_symlink(struct xfs_scrub_context *sc); 100 int xfs_scrub_parent(struct xfs_scrub_context *sc); 101 #ifdef CONFIG_XFS_RT 102 int xfs_scrub_rtbitmap(struct xfs_scrub_context *sc); 103 int xfs_scrub_rtsummary(struct xfs_scrub_context *sc); 104 #else 105 static inline int 106 xfs_scrub_rtbitmap(struct xfs_scrub_context *sc) 107 { 108 return -ENOENT; 109 } 110 static inline int 111 xfs_scrub_rtsummary(struct xfs_scrub_context *sc) 112 { 113 return -ENOENT; 114 } 115 #endif 116 #ifdef CONFIG_XFS_QUOTA 117 int xfs_scrub_quota(struct xfs_scrub_context *sc); 118 #else 119 static inline int 120 xfs_scrub_quota(struct xfs_scrub_context *sc) 121 { 122 return -ENOENT; 123 } 124 #endif 125 126 /* cross-referencing helpers */ 127 void xfs_scrub_xref_is_used_space(struct xfs_scrub_context *sc, 128 xfs_agblock_t agbno, xfs_extlen_t len); 129 void xfs_scrub_xref_is_not_inode_chunk(struct xfs_scrub_context *sc, 130 xfs_agblock_t agbno, xfs_extlen_t len); 131 void xfs_scrub_xref_is_inode_chunk(struct xfs_scrub_context *sc, 132 xfs_agblock_t agbno, xfs_extlen_t len); 133 void xfs_scrub_xref_is_owned_by(struct xfs_scrub_context *sc, 134 xfs_agblock_t agbno, xfs_extlen_t len, 135 struct xfs_owner_info *oinfo); 136 void xfs_scrub_xref_is_not_owned_by(struct xfs_scrub_context *sc, 137 xfs_agblock_t agbno, xfs_extlen_t len, 138 struct xfs_owner_info *oinfo); 139 void xfs_scrub_xref_has_no_owner(struct xfs_scrub_context *sc, 140 xfs_agblock_t agbno, xfs_extlen_t len); 141 void xfs_scrub_xref_is_cow_staging(struct xfs_scrub_context *sc, 142 xfs_agblock_t bno, xfs_extlen_t len); 143 void xfs_scrub_xref_is_not_shared(struct xfs_scrub_context *sc, 144 xfs_agblock_t bno, xfs_extlen_t len); 145 #ifdef CONFIG_XFS_RT 146 void xfs_scrub_xref_is_used_rt_space(struct xfs_scrub_context *sc, 147 xfs_rtblock_t rtbno, xfs_extlen_t len); 148 #else 149 # define xfs_scrub_xref_is_used_rt_space(sc, rtbno, len) do { } while (0) 150 #endif 151 152 #endif /* __XFS_SCRUB_SCRUB_H__ */ 153