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