]>
Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
dcb660f9 DW |
2 | /* |
3 | * Copyright (C) 2017 Oracle. All Rights Reserved. | |
dcb660f9 | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
dcb660f9 DW |
5 | */ |
6 | #ifndef __XFS_SCRUB_COMMON_H__ | |
7 | #define __XFS_SCRUB_COMMON_H__ | |
8 | ||
9 | /* | |
10 | * We /could/ terminate a scrub/repair operation early. If we're not | |
11 | * in a good place to continue (fatal signal, etc.) then bail out. | |
12 | * Note that we're careful not to make any judgements about *error. | |
13 | */ | |
14 | static inline bool | |
c517b3aa | 15 | xchk_should_terminate( |
1d8a748a | 16 | struct xfs_scrub *sc, |
5d1116d4 | 17 | int *error) |
dcb660f9 | 18 | { |
5d1116d4 DW |
19 | /* |
20 | * If preemption is disabled, we need to yield to the scheduler every | |
21 | * few seconds so that we don't run afoul of the soft lockup watchdog | |
22 | * or RCU stall detector. | |
23 | */ | |
24 | cond_resched(); | |
25 | ||
dcb660f9 DW |
26 | if (fatal_signal_pending(current)) { |
27 | if (*error == 0) | |
28 | *error = -EAGAIN; | |
29 | return true; | |
30 | } | |
31 | return false; | |
32 | } | |
33 | ||
1d8a748a DW |
34 | int xchk_trans_alloc(struct xfs_scrub *sc, uint resblks); |
35 | bool xchk_process_error(struct xfs_scrub *sc, xfs_agnumber_t agno, | |
4700d229 | 36 | xfs_agblock_t bno, int *error); |
1d8a748a | 37 | bool xchk_fblock_process_error(struct xfs_scrub *sc, int whichfork, |
4700d229 DW |
38 | xfs_fileoff_t offset, int *error); |
39 | ||
1d8a748a | 40 | bool xchk_xref_process_error(struct xfs_scrub *sc, |
64b12563 | 41 | xfs_agnumber_t agno, xfs_agblock_t bno, int *error); |
1d8a748a | 42 | bool xchk_fblock_xref_process_error(struct xfs_scrub *sc, |
64b12563 DW |
43 | int whichfork, xfs_fileoff_t offset, int *error); |
44 | ||
1d8a748a | 45 | void xchk_block_set_preen(struct xfs_scrub *sc, |
4700d229 | 46 | struct xfs_buf *bp); |
1d8a748a | 47 | void xchk_ino_set_preen(struct xfs_scrub *sc, xfs_ino_t ino); |
4700d229 | 48 | |
75efa57d | 49 | void xchk_set_corrupt(struct xfs_scrub *sc); |
1d8a748a | 50 | void xchk_block_set_corrupt(struct xfs_scrub *sc, |
4700d229 | 51 | struct xfs_buf *bp); |
1d8a748a DW |
52 | void xchk_ino_set_corrupt(struct xfs_scrub *sc, xfs_ino_t ino); |
53 | void xchk_fblock_set_corrupt(struct xfs_scrub *sc, int whichfork, | |
4700d229 DW |
54 | xfs_fileoff_t offset); |
55 | ||
1d8a748a | 56 | void xchk_block_xref_set_corrupt(struct xfs_scrub *sc, |
64b12563 | 57 | struct xfs_buf *bp); |
1d8a748a | 58 | void xchk_ino_xref_set_corrupt(struct xfs_scrub *sc, |
7e56d9ea | 59 | xfs_ino_t ino); |
1d8a748a | 60 | void xchk_fblock_xref_set_corrupt(struct xfs_scrub *sc, |
64b12563 DW |
61 | int whichfork, xfs_fileoff_t offset); |
62 | ||
1d8a748a DW |
63 | void xchk_ino_set_warning(struct xfs_scrub *sc, xfs_ino_t ino); |
64 | void xchk_fblock_set_warning(struct xfs_scrub *sc, int whichfork, | |
4700d229 DW |
65 | xfs_fileoff_t offset); |
66 | ||
1d8a748a | 67 | void xchk_set_incomplete(struct xfs_scrub *sc); |
c517b3aa | 68 | int xchk_checkpoint_log(struct xfs_mount *mp); |
4700d229 | 69 | |
64b12563 | 70 | /* Are we set up for a cross-referencing check? */ |
1d8a748a | 71 | bool xchk_should_check_xref(struct xfs_scrub *sc, int *error, |
64b12563 DW |
72 | struct xfs_btree_cur **curpp); |
73 | ||
dcb660f9 | 74 | /* Setup functions */ |
026f57eb DW |
75 | int xchk_setup_fs(struct xfs_scrub *sc); |
76 | int xchk_setup_ag_allocbt(struct xfs_scrub *sc); | |
77 | int xchk_setup_ag_iallocbt(struct xfs_scrub *sc); | |
78 | int xchk_setup_ag_rmapbt(struct xfs_scrub *sc); | |
79 | int xchk_setup_ag_refcountbt(struct xfs_scrub *sc); | |
80 | int xchk_setup_inode(struct xfs_scrub *sc); | |
81 | int xchk_setup_inode_bmap(struct xfs_scrub *sc); | |
82 | int xchk_setup_inode_bmap_data(struct xfs_scrub *sc); | |
83 | int xchk_setup_directory(struct xfs_scrub *sc); | |
84 | int xchk_setup_xattr(struct xfs_scrub *sc); | |
85 | int xchk_setup_symlink(struct xfs_scrub *sc); | |
86 | int xchk_setup_parent(struct xfs_scrub *sc); | |
29b0767b | 87 | #ifdef CONFIG_XFS_RT |
026f57eb | 88 | int xchk_setup_rt(struct xfs_scrub *sc); |
29b0767b DW |
89 | #else |
90 | static inline int | |
026f57eb | 91 | xchk_setup_rt(struct xfs_scrub *sc) |
c2fc338c DW |
92 | { |
93 | return -ENOENT; | |
94 | } | |
95 | #endif | |
96 | #ifdef CONFIG_XFS_QUOTA | |
026f57eb | 97 | int xchk_setup_quota(struct xfs_scrub *sc); |
c2fc338c DW |
98 | #else |
99 | static inline int | |
026f57eb | 100 | xchk_setup_quota(struct xfs_scrub *sc) |
29b0767b DW |
101 | { |
102 | return -ENOENT; | |
103 | } | |
104 | #endif | |
026f57eb | 105 | int xchk_setup_fscounters(struct xfs_scrub *sc); |
dcb660f9 | 106 | |
1d8a748a DW |
107 | void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa); |
108 | int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno, | |
032d91f9 | 109 | struct xchk_ag *sa); |
48c6615c DW |
110 | |
111 | /* | |
112 | * Grab all AG resources, treating the inability to grab the perag structure as | |
113 | * a fs corruption. This is intended for callers checking an ondisk reference | |
114 | * to a given AG, which means that the AG must still exist. | |
115 | */ | |
116 | static inline int | |
117 | xchk_ag_init_existing( | |
118 | struct xfs_scrub *sc, | |
119 | xfs_agnumber_t agno, | |
120 | struct xchk_ag *sa) | |
121 | { | |
122 | int error = xchk_ag_init(sc, agno, sa); | |
123 | ||
124 | return error == -ENOENT ? -EFSCORRUPTED : error; | |
125 | } | |
126 | ||
1d8a748a | 127 | int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno, |
de9d2a78 | 128 | struct xchk_ag *sa); |
c517b3aa | 129 | void xchk_ag_btcur_free(struct xchk_ag *sa); |
f53acfac | 130 | void xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa); |
032d91f9 | 131 | int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur, |
66e3237e | 132 | const struct xfs_owner_info *oinfo, xfs_filblks_t *blocks); |
b6c1beb9 | 133 | |
026f57eb DW |
134 | int xchk_setup_ag_btree(struct xfs_scrub *sc, bool force_log); |
135 | int xchk_get_inode(struct xfs_scrub *sc); | |
136 | int xchk_setup_inode_contents(struct xfs_scrub *sc, unsigned int resblks); | |
1d8a748a | 137 | void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp); |
efa7a99c | 138 | |
8389f3ff DW |
139 | /* |
140 | * Don't bother cross-referencing if we already found corruption or cross | |
141 | * referencing discrepancies. | |
142 | */ | |
c517b3aa | 143 | static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm) |
8389f3ff DW |
144 | { |
145 | return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT | | |
146 | XFS_SCRUB_OFLAG_XCORRUPT); | |
147 | } | |
148 | ||
1d8a748a | 149 | int xchk_metadata_inode_forks(struct xfs_scrub *sc); |
c517b3aa | 150 | int xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode); |
9a1f3049 DW |
151 | void xchk_stop_reaping(struct xfs_scrub *sc); |
152 | void xchk_start_reaping(struct xfs_scrub *sc); | |
87d9d609 | 153 | |
dcb660f9 | 154 | #endif /* __XFS_SCRUB_COMMON_H__ */ |