Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Oracle. All Rights Reserved. |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __XFS_SCRUB_SCRUB_H__ |
| 7 | #define __XFS_SCRUB_SCRUB_H__ |
| 8 | |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 9 | struct xfs_scrub; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 10 | |
Eric Sandeen | 8e63083 | 2018-01-08 10:41:34 -0800 | [diff] [blame] | 11 | /* Type info and names for the scrub types. */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 12 | enum xchk_type { |
Eric Sandeen | 8e63083 | 2018-01-08 10:41:34 -0800 | [diff] [blame] | 13 | ST_NONE = 1, /* disabled */ |
| 14 | ST_PERAG, /* per-AG metadata */ |
| 15 | ST_FS, /* per-FS metadata */ |
| 16 | ST_INODE, /* per-inode metadata */ |
| 17 | }; |
| 18 | |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 19 | struct xchk_meta_ops { |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 20 | /* Acquire whatever resources are needed for the operation. */ |
Darrick J. Wong | 026f57e | 2021-04-07 17:59:39 -0700 | [diff] [blame] | 21 | int (*setup)(struct xfs_scrub *sc); |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 22 | |
| 23 | /* Examine metadata for errors. */ |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 24 | int (*scrub)(struct xfs_scrub *); |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 25 | |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 26 | /* Repair or optimize the metadata. */ |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 27 | int (*repair)(struct xfs_scrub *); |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 28 | |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 29 | /* Decide if we even have this piece of metadata. */ |
Dave Chinner | 55fafb3 | 2021-08-18 18:46:54 -0700 | [diff] [blame] | 30 | bool (*has)(struct xfs_mount *); |
Eric Sandeen | 8e63083 | 2018-01-08 10:41:34 -0800 | [diff] [blame] | 31 | |
| 32 | /* type describing required/allowed inputs */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 33 | enum xchk_type type; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 36 | /* Buffer pointers and btree cursors for an entire AG. */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 37 | struct xchk_ag { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 38 | struct xfs_perag *pag; |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 39 | |
| 40 | /* AG btree roots */ |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 41 | struct xfs_buf *agf_bp; |
| 42 | struct xfs_buf *agfl_bp; |
| 43 | struct xfs_buf *agi_bp; |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 44 | |
| 45 | /* AG btrees */ |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 46 | struct xfs_btree_cur *bno_cur; |
| 47 | struct xfs_btree_cur *cnt_cur; |
| 48 | struct xfs_btree_cur *ino_cur; |
| 49 | struct xfs_btree_cur *fino_cur; |
| 50 | struct xfs_btree_cur *rmap_cur; |
| 51 | struct xfs_btree_cur *refc_cur; |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 54 | struct xfs_scrub { |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 55 | /* General scrub state. */ |
| 56 | struct xfs_mount *mp; |
| 57 | struct xfs_scrub_metadata *sm; |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 58 | const struct xchk_meta_ops *ops; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 59 | struct xfs_trans *tp; |
Darrick J. Wong | 71bddbc | 2021-03-22 09:51:51 -0700 | [diff] [blame] | 60 | |
| 61 | /* File that scrub was called with. */ |
| 62 | struct file *file; |
| 63 | |
| 64 | /* |
| 65 | * File that is undergoing the scrub operation. This can differ from |
| 66 | * the file that scrub was called with if we're checking file-based fs |
| 67 | * metadata (e.g. rt bitmaps) or if we're doing a scrub-by-handle for |
| 68 | * something that can't be opened directly (e.g. symlinks). |
| 69 | */ |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 70 | struct xfs_inode *ip; |
Darrick J. Wong | 71bddbc | 2021-03-22 09:51:51 -0700 | [diff] [blame] | 71 | |
Darrick J. Wong | eec0482 | 2017-10-17 21:37:45 -0700 | [diff] [blame] | 72 | void *buf; |
Darrick J. Wong | 80e4e12 | 2017-10-17 21:37:42 -0700 | [diff] [blame] | 73 | uint ilock_flags; |
Darrick J. Wong | f8c2a22 | 2019-04-16 08:21:59 -0700 | [diff] [blame] | 74 | |
Darrick J. Wong | 160b5a7 | 2019-04-16 08:22:00 -0700 | [diff] [blame] | 75 | /* See the XCHK/XREP state flags below. */ |
Darrick J. Wong | f8c2a22 | 2019-04-16 08:21:59 -0700 | [diff] [blame] | 76 | unsigned int flags; |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 77 | |
Darrick J. Wong | 4860a05 | 2019-04-16 08:22:00 -0700 | [diff] [blame] | 78 | /* |
| 79 | * The XFS_SICK_* flags that correspond to the metadata being scrubbed |
| 80 | * or repaired. We will use this mask to update the in-core fs health |
| 81 | * status with whatever we find. |
| 82 | */ |
| 83 | unsigned int sick_mask; |
| 84 | |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 85 | /* State tracking for single-AG operations. */ |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 86 | struct xchk_ag sa; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Darrick J. Wong | 160b5a7 | 2019-04-16 08:22:00 -0700 | [diff] [blame] | 89 | /* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */ |
Darrick J. Wong | f8c2a22 | 2019-04-16 08:21:59 -0700 | [diff] [blame] | 90 | #define XCHK_TRY_HARDER (1 << 0) /* can't get resources, try again */ |
| 91 | #define XCHK_HAS_QUOTAOFFLOCK (1 << 1) /* we hold the quotaoff lock */ |
Darrick J. Wong | 9a1f304 | 2019-04-25 18:26:23 -0700 | [diff] [blame] | 92 | #define XCHK_REAPING_DISABLED (1 << 2) /* background block reaping paused */ |
Darrick J. Wong | 160b5a7 | 2019-04-16 08:22:00 -0700 | [diff] [blame] | 93 | #define XREP_ALREADY_FIXED (1 << 31) /* checking our repair work */ |
Darrick J. Wong | f8c2a22 | 2019-04-16 08:21:59 -0700 | [diff] [blame] | 94 | |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 95 | /* Metadata scrubbers */ |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 96 | int xchk_tester(struct xfs_scrub *sc); |
| 97 | int xchk_superblock(struct xfs_scrub *sc); |
| 98 | int xchk_agf(struct xfs_scrub *sc); |
| 99 | int xchk_agfl(struct xfs_scrub *sc); |
| 100 | int xchk_agi(struct xfs_scrub *sc); |
| 101 | int xchk_bnobt(struct xfs_scrub *sc); |
| 102 | int xchk_cntbt(struct xfs_scrub *sc); |
| 103 | int xchk_inobt(struct xfs_scrub *sc); |
| 104 | int xchk_finobt(struct xfs_scrub *sc); |
| 105 | int xchk_rmapbt(struct xfs_scrub *sc); |
| 106 | int xchk_refcountbt(struct xfs_scrub *sc); |
| 107 | int xchk_inode(struct xfs_scrub *sc); |
| 108 | int xchk_bmap_data(struct xfs_scrub *sc); |
| 109 | int xchk_bmap_attr(struct xfs_scrub *sc); |
| 110 | int xchk_bmap_cow(struct xfs_scrub *sc); |
| 111 | int xchk_directory(struct xfs_scrub *sc); |
| 112 | int xchk_xattr(struct xfs_scrub *sc); |
| 113 | int xchk_symlink(struct xfs_scrub *sc); |
| 114 | int xchk_parent(struct xfs_scrub *sc); |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 115 | #ifdef CONFIG_XFS_RT |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 116 | int xchk_rtbitmap(struct xfs_scrub *sc); |
| 117 | int xchk_rtsummary(struct xfs_scrub *sc); |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 118 | #else |
| 119 | static inline int |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 120 | xchk_rtbitmap(struct xfs_scrub *sc) |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 121 | { |
| 122 | return -ENOENT; |
| 123 | } |
| 124 | static inline int |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 125 | xchk_rtsummary(struct xfs_scrub *sc) |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 126 | { |
| 127 | return -ENOENT; |
| 128 | } |
| 129 | #endif |
Darrick J. Wong | c2fc338 | 2017-10-17 21:37:47 -0700 | [diff] [blame] | 130 | #ifdef CONFIG_XFS_QUOTA |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 131 | int xchk_quota(struct xfs_scrub *sc); |
Darrick J. Wong | c2fc338 | 2017-10-17 21:37:47 -0700 | [diff] [blame] | 132 | #else |
| 133 | static inline int |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 134 | xchk_quota(struct xfs_scrub *sc) |
Darrick J. Wong | c2fc338 | 2017-10-17 21:37:47 -0700 | [diff] [blame] | 135 | { |
| 136 | return -ENOENT; |
| 137 | } |
| 138 | #endif |
Darrick J. Wong | 75efa57 | 2019-04-25 18:26:24 -0700 | [diff] [blame] | 139 | int xchk_fscounters(struct xfs_scrub *sc); |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 140 | |
Darrick J. Wong | 52dc4b4 | 2018-01-16 18:53:06 -0800 | [diff] [blame] | 141 | /* cross-referencing helpers */ |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 142 | void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno, |
| 143 | xfs_extlen_t len); |
| 144 | void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno, |
| 145 | xfs_extlen_t len); |
| 146 | void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno, |
| 147 | xfs_extlen_t len); |
| 148 | void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno, |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 149 | xfs_extlen_t len, const struct xfs_owner_info *oinfo); |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 150 | void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno, |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 151 | xfs_extlen_t len, const struct xfs_owner_info *oinfo); |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 152 | void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno, |
| 153 | xfs_extlen_t len); |
| 154 | void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno, |
| 155 | xfs_extlen_t len); |
| 156 | void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno, |
| 157 | xfs_extlen_t len); |
Darrick J. Wong | 46d9bfb | 2018-01-16 18:53:10 -0800 | [diff] [blame] | 158 | #ifdef CONFIG_XFS_RT |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 159 | void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno, |
| 160 | xfs_extlen_t len); |
Darrick J. Wong | 46d9bfb | 2018-01-16 18:53:10 -0800 | [diff] [blame] | 161 | #else |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 162 | # define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0) |
Darrick J. Wong | 46d9bfb | 2018-01-16 18:53:10 -0800 | [diff] [blame] | 163 | #endif |
Darrick J. Wong | 52dc4b4 | 2018-01-16 18:53:06 -0800 | [diff] [blame] | 164 | |
Darrick J. Wong | 75efa57 | 2019-04-25 18:26:24 -0700 | [diff] [blame] | 165 | struct xchk_fscounters { |
| 166 | uint64_t icount; |
| 167 | uint64_t ifree; |
| 168 | uint64_t fdblocks; |
| 169 | unsigned long long icount_min; |
| 170 | unsigned long long icount_max; |
| 171 | }; |
| 172 | |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 173 | #endif /* __XFS_SCRUB_SCRUB_H__ */ |