xref: /linux/fs/xfs/scrub/common.h (revision 856e7c4b619af622d56b3b454f7bec32a170ac99)
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 xfs_scrub_should_terminate(
16 	struct xfs_scrub_context	*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 xfs_scrub_trans_alloc(struct xfs_scrub_context *sc, uint resblks);
28 bool xfs_scrub_process_error(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
29 		xfs_agblock_t bno, int *error);
30 bool xfs_scrub_fblock_process_error(struct xfs_scrub_context *sc, int whichfork,
31 		xfs_fileoff_t offset, int *error);
32 
33 bool xfs_scrub_xref_process_error(struct xfs_scrub_context *sc,
34 		xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
35 bool xfs_scrub_fblock_xref_process_error(struct xfs_scrub_context *sc,
36 		int whichfork, xfs_fileoff_t offset, int *error);
37 
38 void xfs_scrub_block_set_preen(struct xfs_scrub_context *sc,
39 		struct xfs_buf *bp);
40 void xfs_scrub_ino_set_preen(struct xfs_scrub_context *sc, xfs_ino_t ino);
41 
42 void xfs_scrub_block_set_corrupt(struct xfs_scrub_context *sc,
43 		struct xfs_buf *bp);
44 void xfs_scrub_ino_set_corrupt(struct xfs_scrub_context *sc, xfs_ino_t ino);
45 void xfs_scrub_fblock_set_corrupt(struct xfs_scrub_context *sc, int whichfork,
46 		xfs_fileoff_t offset);
47 
48 void xfs_scrub_block_xref_set_corrupt(struct xfs_scrub_context *sc,
49 		struct xfs_buf *bp);
50 void xfs_scrub_ino_xref_set_corrupt(struct xfs_scrub_context *sc,
51 		xfs_ino_t ino);
52 void xfs_scrub_fblock_xref_set_corrupt(struct xfs_scrub_context *sc,
53 		int whichfork, xfs_fileoff_t offset);
54 
55 void xfs_scrub_ino_set_warning(struct xfs_scrub_context *sc, xfs_ino_t ino);
56 void xfs_scrub_fblock_set_warning(struct xfs_scrub_context *sc, int whichfork,
57 		xfs_fileoff_t offset);
58 
59 void xfs_scrub_set_incomplete(struct xfs_scrub_context *sc);
60 int xfs_scrub_checkpoint_log(struct xfs_mount *mp);
61 
62 /* Are we set up for a cross-referencing check? */
63 bool xfs_scrub_should_check_xref(struct xfs_scrub_context *sc, int *error,
64 			   struct xfs_btree_cur **curpp);
65 
66 /* Setup functions */
67 int xfs_scrub_setup_fs(struct xfs_scrub_context *sc, struct xfs_inode *ip);
68 int xfs_scrub_setup_ag_allocbt(struct xfs_scrub_context *sc,
69 			       struct xfs_inode *ip);
70 int xfs_scrub_setup_ag_iallocbt(struct xfs_scrub_context *sc,
71 				struct xfs_inode *ip);
72 int xfs_scrub_setup_ag_rmapbt(struct xfs_scrub_context *sc,
73 			      struct xfs_inode *ip);
74 int xfs_scrub_setup_ag_refcountbt(struct xfs_scrub_context *sc,
75 				  struct xfs_inode *ip);
76 int xfs_scrub_setup_inode(struct xfs_scrub_context *sc,
77 			  struct xfs_inode *ip);
78 int xfs_scrub_setup_inode_bmap(struct xfs_scrub_context *sc,
79 			       struct xfs_inode *ip);
80 int xfs_scrub_setup_inode_bmap_data(struct xfs_scrub_context *sc,
81 				    struct xfs_inode *ip);
82 int xfs_scrub_setup_directory(struct xfs_scrub_context *sc,
83 			      struct xfs_inode *ip);
84 int xfs_scrub_setup_xattr(struct xfs_scrub_context *sc,
85 			  struct xfs_inode *ip);
86 int xfs_scrub_setup_symlink(struct xfs_scrub_context *sc,
87 			    struct xfs_inode *ip);
88 int xfs_scrub_setup_parent(struct xfs_scrub_context *sc,
89 			   struct xfs_inode *ip);
90 #ifdef CONFIG_XFS_RT
91 int xfs_scrub_setup_rt(struct xfs_scrub_context *sc, struct xfs_inode *ip);
92 #else
93 static inline int
94 xfs_scrub_setup_rt(struct xfs_scrub_context *sc, struct xfs_inode *ip)
95 {
96 	return -ENOENT;
97 }
98 #endif
99 #ifdef CONFIG_XFS_QUOTA
100 int xfs_scrub_setup_quota(struct xfs_scrub_context *sc, struct xfs_inode *ip);
101 #else
102 static inline int
103 xfs_scrub_setup_quota(struct xfs_scrub_context *sc, struct xfs_inode *ip)
104 {
105 	return -ENOENT;
106 }
107 #endif
108 
109 void xfs_scrub_ag_free(struct xfs_scrub_context *sc, struct xfs_scrub_ag *sa);
110 int xfs_scrub_ag_init(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
111 		      struct xfs_scrub_ag *sa);
112 void xfs_scrub_perag_get(struct xfs_mount *mp, struct xfs_scrub_ag *sa);
113 int xfs_scrub_ag_read_headers(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
114 			      struct xfs_buf **agi, struct xfs_buf **agf,
115 			      struct xfs_buf **agfl);
116 void xfs_scrub_ag_btcur_free(struct xfs_scrub_ag *sa);
117 int xfs_scrub_ag_btcur_init(struct xfs_scrub_context *sc,
118 			    struct xfs_scrub_ag *sa);
119 int xfs_scrub_count_rmap_ownedby_ag(struct xfs_scrub_context *sc,
120 				    struct xfs_btree_cur *cur,
121 				    struct xfs_owner_info *oinfo,
122 				    xfs_filblks_t *blocks);
123 
124 int xfs_scrub_setup_ag_btree(struct xfs_scrub_context *sc,
125 			     struct xfs_inode *ip, bool force_log);
126 int xfs_scrub_get_inode(struct xfs_scrub_context *sc, struct xfs_inode *ip_in);
127 int xfs_scrub_setup_inode_contents(struct xfs_scrub_context *sc,
128 				   struct xfs_inode *ip, unsigned int resblks);
129 void xfs_scrub_buffer_recheck(struct xfs_scrub_context *sc, struct xfs_buf *bp);
130 
131 /*
132  * Don't bother cross-referencing if we already found corruption or cross
133  * referencing discrepancies.
134  */
135 static inline bool xfs_scrub_skip_xref(struct xfs_scrub_metadata *sm)
136 {
137 	return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
138 			       XFS_SCRUB_OFLAG_XCORRUPT);
139 }
140 
141 int xfs_scrub_metadata_inode_forks(struct xfs_scrub_context *sc);
142 int xfs_scrub_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
143 
144 #endif	/* __XFS_SCRUB_COMMON_H__ */
145