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 | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 9 | struct xfs_scrub_context; |
| 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. */ |
| 21 | int (*setup)(struct xfs_scrub_context *, |
| 22 | struct xfs_inode *); |
| 23 | |
| 24 | /* Examine metadata for errors. */ |
| 25 | int (*scrub)(struct xfs_scrub_context *); |
| 26 | |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 27 | /* Repair or optimize the metadata. */ |
| 28 | int (*repair)(struct xfs_scrub_context *); |
| 29 | |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 30 | /* Decide if we even have this piece of metadata. */ |
| 31 | bool (*has)(struct xfs_sb *); |
Eric Sandeen | 8e63083 | 2018-01-08 10:41:34 -0800 | [diff] [blame] | 32 | |
| 33 | /* type describing required/allowed inputs */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 34 | enum xchk_type type; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 37 | /* Buffer pointers and btree cursors for an entire AG. */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 38 | struct xchk_ag { |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 39 | xfs_agnumber_t agno; |
Darrick J. Wong | 51863d7 | 2018-05-29 22:24:44 -0700 | [diff] [blame] | 40 | struct xfs_perag *pag; |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 41 | |
| 42 | /* AG btree roots */ |
| 43 | struct xfs_buf *agf_bp; |
| 44 | struct xfs_buf *agfl_bp; |
| 45 | struct xfs_buf *agi_bp; |
| 46 | |
| 47 | /* AG btrees */ |
| 48 | struct xfs_btree_cur *bno_cur; |
| 49 | struct xfs_btree_cur *cnt_cur; |
| 50 | struct xfs_btree_cur *ino_cur; |
| 51 | struct xfs_btree_cur *fino_cur; |
| 52 | struct xfs_btree_cur *rmap_cur; |
| 53 | struct xfs_btree_cur *refc_cur; |
| 54 | }; |
| 55 | |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 56 | struct xfs_scrub_context { |
| 57 | /* General scrub state. */ |
| 58 | struct xfs_mount *mp; |
| 59 | struct xfs_scrub_metadata *sm; |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 60 | const struct xchk_meta_ops *ops; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 61 | struct xfs_trans *tp; |
| 62 | struct xfs_inode *ip; |
Darrick J. Wong | eec0482 | 2017-10-17 21:37:45 -0700 | [diff] [blame] | 63 | void *buf; |
Darrick J. Wong | 80e4e12 | 2017-10-17 21:37:42 -0700 | [diff] [blame] | 64 | uint ilock_flags; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 65 | bool try_harder; |
Darrick J. Wong | eb41c93 | 2018-05-09 10:02:00 -0700 | [diff] [blame] | 66 | bool has_quotaofflock; |
Darrick J. Wong | b6c1beb | 2017-10-17 21:37:38 -0700 | [diff] [blame] | 67 | |
| 68 | /* State tracking for single-AG operations. */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 69 | struct xchk_ag sa; |
Darrick J. Wong | a563718 | 2017-10-17 21:37:35 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 72 | /* Metadata scrubbers */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 73 | int xchk_tester(struct xfs_scrub_context *sc); |
| 74 | int xchk_superblock(struct xfs_scrub_context *sc); |
| 75 | int xchk_agf(struct xfs_scrub_context *sc); |
| 76 | int xchk_agfl(struct xfs_scrub_context *sc); |
| 77 | int xchk_agi(struct xfs_scrub_context *sc); |
| 78 | int xchk_bnobt(struct xfs_scrub_context *sc); |
| 79 | int xchk_cntbt(struct xfs_scrub_context *sc); |
| 80 | int xchk_inobt(struct xfs_scrub_context *sc); |
| 81 | int xchk_finobt(struct xfs_scrub_context *sc); |
| 82 | int xchk_rmapbt(struct xfs_scrub_context *sc); |
| 83 | int xchk_refcountbt(struct xfs_scrub_context *sc); |
| 84 | int xchk_inode(struct xfs_scrub_context *sc); |
| 85 | int xchk_bmap_data(struct xfs_scrub_context *sc); |
| 86 | int xchk_bmap_attr(struct xfs_scrub_context *sc); |
| 87 | int xchk_bmap_cow(struct xfs_scrub_context *sc); |
| 88 | int xchk_directory(struct xfs_scrub_context *sc); |
| 89 | int xchk_xattr(struct xfs_scrub_context *sc); |
| 90 | int xchk_symlink(struct xfs_scrub_context *sc); |
| 91 | int xchk_parent(struct xfs_scrub_context *sc); |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 92 | #ifdef CONFIG_XFS_RT |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 93 | int xchk_rtbitmap(struct xfs_scrub_context *sc); |
| 94 | int xchk_rtsummary(struct xfs_scrub_context *sc); |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 95 | #else |
| 96 | static inline int |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 97 | xchk_rtbitmap(struct xfs_scrub_context *sc) |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 98 | { |
| 99 | return -ENOENT; |
| 100 | } |
| 101 | static inline int |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 102 | xchk_rtsummary(struct xfs_scrub_context *sc) |
Darrick J. Wong | 29b0767 | 2017-10-17 21:37:46 -0700 | [diff] [blame] | 103 | { |
| 104 | return -ENOENT; |
| 105 | } |
| 106 | #endif |
Darrick J. Wong | c2fc338 | 2017-10-17 21:37:47 -0700 | [diff] [blame] | 107 | #ifdef CONFIG_XFS_QUOTA |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 108 | int xchk_quota(struct xfs_scrub_context *sc); |
Darrick J. Wong | c2fc338 | 2017-10-17 21:37:47 -0700 | [diff] [blame] | 109 | #else |
| 110 | static inline int |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 111 | xchk_quota(struct xfs_scrub_context *sc) |
Darrick J. Wong | c2fc338 | 2017-10-17 21:37:47 -0700 | [diff] [blame] | 112 | { |
| 113 | return -ENOENT; |
| 114 | } |
| 115 | #endif |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 116 | |
Darrick J. Wong | 52dc4b4 | 2018-01-16 18:53:06 -0800 | [diff] [blame] | 117 | /* cross-referencing helpers */ |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 118 | void xchk_xref_is_used_space(struct xfs_scrub_context *sc, |
Darrick J. Wong | 52dc4b4 | 2018-01-16 18:53:06 -0800 | [diff] [blame] | 119 | xfs_agblock_t agbno, xfs_extlen_t len); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 120 | void xchk_xref_is_not_inode_chunk(struct xfs_scrub_context *sc, |
Darrick J. Wong | 2e6f275 | 2018-01-16 18:53:07 -0800 | [diff] [blame] | 121 | xfs_agblock_t agbno, xfs_extlen_t len); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 122 | void xchk_xref_is_inode_chunk(struct xfs_scrub_context *sc, |
Darrick J. Wong | 2e6f275 | 2018-01-16 18:53:07 -0800 | [diff] [blame] | 123 | xfs_agblock_t agbno, xfs_extlen_t len); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 124 | void xchk_xref_is_owned_by(struct xfs_scrub_context *sc, |
Darrick J. Wong | d852657 | 2018-01-16 18:53:08 -0800 | [diff] [blame] | 125 | xfs_agblock_t agbno, xfs_extlen_t len, |
| 126 | struct xfs_owner_info *oinfo); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 127 | void xchk_xref_is_not_owned_by(struct xfs_scrub_context *sc, |
Darrick J. Wong | d852657 | 2018-01-16 18:53:08 -0800 | [diff] [blame] | 128 | xfs_agblock_t agbno, xfs_extlen_t len, |
| 129 | struct xfs_owner_info *oinfo); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 130 | void xchk_xref_has_no_owner(struct xfs_scrub_context *sc, |
Darrick J. Wong | d852657 | 2018-01-16 18:53:08 -0800 | [diff] [blame] | 131 | xfs_agblock_t agbno, xfs_extlen_t len); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 132 | void xchk_xref_is_cow_staging(struct xfs_scrub_context *sc, |
Darrick J. Wong | f6d5fc2 | 2018-01-16 18:53:09 -0800 | [diff] [blame] | 133 | xfs_agblock_t bno, xfs_extlen_t len); |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 134 | void xchk_xref_is_not_shared(struct xfs_scrub_context *sc, |
Darrick J. Wong | f6d5fc2 | 2018-01-16 18:53:09 -0800 | [diff] [blame] | 135 | xfs_agblock_t bno, xfs_extlen_t len); |
Darrick J. Wong | 46d9bfb | 2018-01-16 18:53:10 -0800 | [diff] [blame] | 136 | #ifdef CONFIG_XFS_RT |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 137 | void xchk_xref_is_used_rt_space(struct xfs_scrub_context *sc, |
Darrick J. Wong | 46d9bfb | 2018-01-16 18:53:10 -0800 | [diff] [blame] | 138 | xfs_rtblock_t rtbno, xfs_extlen_t len); |
| 139 | #else |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame^] | 140 | # 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] | 141 | #endif |
Darrick J. Wong | 52dc4b4 | 2018-01-16 18:53:06 -0800 | [diff] [blame] | 142 | |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 143 | #endif /* __XFS_SCRUB_SCRUB_H__ */ |