xref: /openbmc/linux/fs/xfs/scrub/common.h (revision b830f94f)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
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
15 xchk_should_terminate(
16 	struct xfs_scrub	*sc,
17 	int				*error)
18 {
19 	if (fatal_signal_pending(current)) {
20 		if (*error == 0)
21 			*error = -EAGAIN;
22 		return true;
23 	}
24 	return false;
25 }
26 
27 int xchk_trans_alloc(struct xfs_scrub *sc, uint resblks);
28 bool xchk_process_error(struct xfs_scrub *sc, xfs_agnumber_t agno,
29 		xfs_agblock_t bno, int *error);
30 bool xchk_fblock_process_error(struct xfs_scrub *sc, int whichfork,
31 		xfs_fileoff_t offset, int *error);
32 
33 bool xchk_xref_process_error(struct xfs_scrub *sc,
34 		xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
35 bool xchk_fblock_xref_process_error(struct xfs_scrub *sc,
36 		int whichfork, xfs_fileoff_t offset, int *error);
37 
38 void xchk_block_set_preen(struct xfs_scrub *sc,
39 		struct xfs_buf *bp);
40 void xchk_ino_set_preen(struct xfs_scrub *sc, xfs_ino_t ino);
41 
42 void xchk_set_corrupt(struct xfs_scrub *sc);
43 void xchk_block_set_corrupt(struct xfs_scrub *sc,
44 		struct xfs_buf *bp);
45 void xchk_ino_set_corrupt(struct xfs_scrub *sc, xfs_ino_t ino);
46 void xchk_fblock_set_corrupt(struct xfs_scrub *sc, int whichfork,
47 		xfs_fileoff_t offset);
48 
49 void xchk_block_xref_set_corrupt(struct xfs_scrub *sc,
50 		struct xfs_buf *bp);
51 void xchk_ino_xref_set_corrupt(struct xfs_scrub *sc,
52 		xfs_ino_t ino);
53 void xchk_fblock_xref_set_corrupt(struct xfs_scrub *sc,
54 		int whichfork, xfs_fileoff_t offset);
55 
56 void xchk_ino_set_warning(struct xfs_scrub *sc, xfs_ino_t ino);
57 void xchk_fblock_set_warning(struct xfs_scrub *sc, int whichfork,
58 		xfs_fileoff_t offset);
59 
60 void xchk_set_incomplete(struct xfs_scrub *sc);
61 int xchk_checkpoint_log(struct xfs_mount *mp);
62 
63 /* Are we set up for a cross-referencing check? */
64 bool xchk_should_check_xref(struct xfs_scrub *sc, int *error,
65 			   struct xfs_btree_cur **curpp);
66 
67 /* Setup functions */
68 int xchk_setup_fs(struct xfs_scrub *sc, struct xfs_inode *ip);
69 int xchk_setup_ag_allocbt(struct xfs_scrub *sc,
70 			       struct xfs_inode *ip);
71 int xchk_setup_ag_iallocbt(struct xfs_scrub *sc,
72 				struct xfs_inode *ip);
73 int xchk_setup_ag_rmapbt(struct xfs_scrub *sc,
74 			      struct xfs_inode *ip);
75 int xchk_setup_ag_refcountbt(struct xfs_scrub *sc,
76 				  struct xfs_inode *ip);
77 int xchk_setup_inode(struct xfs_scrub *sc,
78 			  struct xfs_inode *ip);
79 int xchk_setup_inode_bmap(struct xfs_scrub *sc,
80 			       struct xfs_inode *ip);
81 int xchk_setup_inode_bmap_data(struct xfs_scrub *sc,
82 				    struct xfs_inode *ip);
83 int xchk_setup_directory(struct xfs_scrub *sc,
84 			      struct xfs_inode *ip);
85 int xchk_setup_xattr(struct xfs_scrub *sc,
86 			  struct xfs_inode *ip);
87 int xchk_setup_symlink(struct xfs_scrub *sc,
88 			    struct xfs_inode *ip);
89 int xchk_setup_parent(struct xfs_scrub *sc,
90 			   struct xfs_inode *ip);
91 #ifdef CONFIG_XFS_RT
92 int xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip);
93 #else
94 static inline int
95 xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip)
96 {
97 	return -ENOENT;
98 }
99 #endif
100 #ifdef CONFIG_XFS_QUOTA
101 int xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip);
102 #else
103 static inline int
104 xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip)
105 {
106 	return -ENOENT;
107 }
108 #endif
109 int xchk_setup_fscounters(struct xfs_scrub *sc, struct xfs_inode *ip);
110 
111 void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa);
112 int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,
113 		struct xchk_ag *sa);
114 void xchk_perag_get(struct xfs_mount *mp, struct xchk_ag *sa);
115 int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
116 		struct xfs_buf **agi, struct xfs_buf **agf,
117 		struct xfs_buf **agfl);
118 void xchk_ag_btcur_free(struct xchk_ag *sa);
119 int xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
120 int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
121 		const struct xfs_owner_info *oinfo, xfs_filblks_t *blocks);
122 
123 int xchk_setup_ag_btree(struct xfs_scrub *sc, struct xfs_inode *ip,
124 		bool force_log);
125 int xchk_get_inode(struct xfs_scrub *sc, struct xfs_inode *ip_in);
126 int xchk_setup_inode_contents(struct xfs_scrub *sc, struct xfs_inode *ip,
127 		unsigned int resblks);
128 void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp);
129 
130 /*
131  * Don't bother cross-referencing if we already found corruption or cross
132  * referencing discrepancies.
133  */
134 static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
135 {
136 	return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
137 			       XFS_SCRUB_OFLAG_XCORRUPT);
138 }
139 
140 int xchk_metadata_inode_forks(struct xfs_scrub *sc);
141 int xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
142 void xchk_stop_reaping(struct xfs_scrub *sc);
143 void xchk_start_reaping(struct xfs_scrub *sc);
144 
145 #endif	/* __XFS_SCRUB_COMMON_H__ */
146