Line data Source code
1 : /* SPDX-License-Identifier: GPL-2.0+ */
2 : /*
3 : * Copyright (C) 2019 Oracle. All Rights Reserved.
4 : * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 : */
6 : #ifndef __XFS_HEALTH_H__
7 : #define __XFS_HEALTH_H__
8 :
9 : /*
10 : * In-Core Filesystem Health Assessments
11 : * =====================================
12 : *
13 : * We'd like to be able to summarize the current health status of the
14 : * filesystem so that the administrator knows when it's necessary to schedule
15 : * some downtime for repairs. Until then, we would also like to avoid abrupt
16 : * shutdowns due to corrupt metadata.
17 : *
18 : * The online scrub feature evaluates the health of all filesystem metadata.
19 : * When scrub detects corruption in a piece of metadata it will set the
20 : * corresponding sickness flag, and repair will clear it if successful. If
21 : * problems remain at unmount time, we can also request manual intervention by
22 : * logging a notice to run xfs_repair.
23 : *
24 : * Each health tracking group uses a pair of fields for reporting. The
25 : * "checked" field tell us if a given piece of metadata has ever been examined,
26 : * and the "sick" field tells us if that piece was found to need repairs.
27 : * Therefore we can conclude that for a given sick flag value:
28 : *
29 : * - checked && sick => metadata needs repair
30 : * - checked && !sick => metadata is ok
31 : * - !checked && sick => errors have been observed during normal operation,
32 : * but the metadata has not been checked thoroughly
33 : * - !checked && !sick => has not been examined since mount
34 : *
35 : * Evidence of health problems can be sorted into three basic categories:
36 : *
37 : * a) Primary evidence, which signals that something is defective within the
38 : * general grouping of metadata.
39 : *
40 : * b) Secondary evidence, which are side effects of primary problem but are
41 : * not themselves problems. These can be forgotten when the primary
42 : * health problems are addressed.
43 : *
44 : * c) Indirect evidence, which points to something being wrong in another
45 : * group, but we had to release resources and this is all that's left of
46 : * that state.
47 : */
48 :
49 : struct xfs_mount;
50 : struct xfs_perag;
51 : struct xfs_inode;
52 : struct xfs_fsop_geom;
53 : struct xfs_btree_cur;
54 : struct xfs_da_args;
55 :
56 : /* Observable health issues for metadata spanning the entire filesystem. */
57 : #define XFS_SICK_FS_COUNTERS (1 << 0) /* summary counters */
58 : #define XFS_SICK_FS_UQUOTA (1 << 1) /* user quota */
59 : #define XFS_SICK_FS_GQUOTA (1 << 2) /* group quota */
60 : #define XFS_SICK_FS_PQUOTA (1 << 3) /* project quota */
61 : #define XFS_SICK_FS_QUOTACHECK (1 << 4) /* quota counts */
62 : #define XFS_SICK_FS_NLINKS (1 << 5) /* inode link counts */
63 :
64 : /* Observable health issues for realtime volume metadata. */
65 : #define XFS_SICK_RT_BITMAP (1 << 0) /* realtime bitmap */
66 : #define XFS_SICK_RT_SUMMARY (1 << 1) /* realtime summary */
67 :
68 : /* Observable health issues for AG metadata. */
69 : #define XFS_SICK_AG_SB (1 << 0) /* superblock */
70 : #define XFS_SICK_AG_AGF (1 << 1) /* AGF header */
71 : #define XFS_SICK_AG_AGFL (1 << 2) /* AGFL header */
72 : #define XFS_SICK_AG_AGI (1 << 3) /* AGI header */
73 : #define XFS_SICK_AG_BNOBT (1 << 4) /* free space by block */
74 : #define XFS_SICK_AG_CNTBT (1 << 5) /* free space by length */
75 : #define XFS_SICK_AG_INOBT (1 << 6) /* inode index */
76 : #define XFS_SICK_AG_FINOBT (1 << 7) /* free inode index */
77 : #define XFS_SICK_AG_RMAPBT (1 << 8) /* reverse mappings */
78 : #define XFS_SICK_AG_REFCNTBT (1 << 9) /* reference counts */
79 : #define XFS_SICK_AG_INODES (1 << 10) /* inactivated bad inodes */
80 :
81 : /* Observable health issues for inode metadata. */
82 : #define XFS_SICK_INO_CORE (1 << 0) /* inode core */
83 : #define XFS_SICK_INO_BMBTD (1 << 1) /* data fork */
84 : #define XFS_SICK_INO_BMBTA (1 << 2) /* attr fork */
85 : #define XFS_SICK_INO_BMBTC (1 << 3) /* cow fork */
86 : #define XFS_SICK_INO_DIR (1 << 4) /* directory */
87 : #define XFS_SICK_INO_XATTR (1 << 5) /* extended attributes */
88 : #define XFS_SICK_INO_SYMLINK (1 << 6) /* symbolic link remote target */
89 : #define XFS_SICK_INO_PARENT (1 << 7) /* parent pointers */
90 : /* Don't propagate sick status to ag health summary during inactivation */
91 : #define XFS_SICK_INO_FORGET (1 << 8)
92 : #define XFS_SICK_INO_DIRTREE (1 << 9) /* directory tree structure */
93 :
94 : /* Primary evidence of health problems in a given group. */
95 : #define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \
96 : XFS_SICK_FS_UQUOTA | \
97 : XFS_SICK_FS_GQUOTA | \
98 : XFS_SICK_FS_PQUOTA | \
99 : XFS_SICK_FS_QUOTACHECK | \
100 : XFS_SICK_FS_NLINKS)
101 :
102 : #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \
103 : XFS_SICK_RT_SUMMARY)
104 :
105 : #define XFS_SICK_AG_PRIMARY (XFS_SICK_AG_SB | \
106 : XFS_SICK_AG_AGF | \
107 : XFS_SICK_AG_AGFL | \
108 : XFS_SICK_AG_AGI | \
109 : XFS_SICK_AG_BNOBT | \
110 : XFS_SICK_AG_CNTBT | \
111 : XFS_SICK_AG_INOBT | \
112 : XFS_SICK_AG_FINOBT | \
113 : XFS_SICK_AG_RMAPBT | \
114 : XFS_SICK_AG_REFCNTBT)
115 :
116 : #define XFS_SICK_INO_PRIMARY (XFS_SICK_INO_CORE | \
117 : XFS_SICK_INO_BMBTD | \
118 : XFS_SICK_INO_BMBTA | \
119 : XFS_SICK_INO_BMBTC | \
120 : XFS_SICK_INO_DIR | \
121 : XFS_SICK_INO_XATTR | \
122 : XFS_SICK_INO_SYMLINK | \
123 : XFS_SICK_INO_PARENT | \
124 : XFS_SICK_INO_DIRTREE)
125 :
126 : /* Secondary state related to (but not primary evidence of) health problems. */
127 : #define XFS_SICK_FS_SECONDARY (0)
128 : #define XFS_SICK_RT_SECONDARY (0)
129 : #define XFS_SICK_AG_SECONDARY (0)
130 : #define XFS_SICK_INO_SECONDARY (XFS_SICK_INO_FORGET)
131 :
132 : /* Evidence of health problems elsewhere. */
133 : #define XFS_SICK_FS_INDIRECT (0)
134 : #define XFS_SICK_RT_INDIRECT (0)
135 : #define XFS_SICK_AG_INDIRECT (XFS_SICK_AG_INODES)
136 : #define XFS_SICK_INO_INDIRECT (0)
137 :
138 : /* All health masks. */
139 : #define XFS_SICK_FS_ALL (XFS_SICK_FS_PRIMARY | \
140 : XFS_SICK_FS_SECONDARY | \
141 : XFS_SICK_FS_INDIRECT)
142 :
143 : #define XFS_SICK_RT_ALL (XFS_SICK_RT_PRIMARY | \
144 : XFS_SICK_RT_SECONDARY | \
145 : XFS_SICK_RT_INDIRECT)
146 :
147 : #define XFS_SICK_AG_ALL (XFS_SICK_AG_PRIMARY | \
148 : XFS_SICK_AG_SECONDARY | \
149 : XFS_SICK_AG_INDIRECT)
150 :
151 : #define XFS_SICK_INO_ALL (XFS_SICK_INO_PRIMARY | \
152 : XFS_SICK_INO_SECONDARY | \
153 : XFS_SICK_INO_INDIRECT)
154 :
155 : /*
156 : * These functions must be provided by the xfs implementation. Function
157 : * behavior with respect to the first argument should be as follows:
158 : *
159 : * xfs_*_mark_sick: set the sick flags and do not set checked flags.
160 : * xfs_*_mark_checked: set the checked flags.
161 : * xfs_*_mark_healthy: clear the sick flags and set the checked flags.
162 : *
163 : * xfs_*_measure_sickness: return the sick and check status in the provided
164 : * out parameters.
165 : */
166 :
167 : void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask);
168 : void xfs_fs_mark_checked(struct xfs_mount *mp, unsigned int mask);
169 : void xfs_fs_mark_healthy(struct xfs_mount *mp, unsigned int mask);
170 : void xfs_fs_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
171 : unsigned int *checked);
172 :
173 : void xfs_rt_mark_sick(struct xfs_mount *mp, unsigned int mask);
174 : void xfs_rt_mark_checked(struct xfs_mount *mp, unsigned int mask);
175 : void xfs_rt_mark_healthy(struct xfs_mount *mp, unsigned int mask);
176 : void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
177 : unsigned int *checked);
178 :
179 : void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno,
180 : unsigned int mask);
181 : void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask);
182 : void xfs_ag_mark_checked(struct xfs_perag *pag, unsigned int mask);
183 : void xfs_ag_mark_healthy(struct xfs_perag *pag, unsigned int mask);
184 : void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick,
185 : unsigned int *checked);
186 :
187 : void xfs_inode_mark_sick(struct xfs_inode *ip, unsigned int mask);
188 : void xfs_inode_mark_checked(struct xfs_inode *ip, unsigned int mask);
189 : void xfs_inode_mark_healthy(struct xfs_inode *ip, unsigned int mask);
190 : void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,
191 : unsigned int *checked);
192 :
193 : void xfs_health_unmount(struct xfs_mount *mp);
194 : void xfs_bmap_mark_sick(struct xfs_inode *ip, int whichfork);
195 : void xfs_btree_mark_sick(struct xfs_btree_cur *cur);
196 : void xfs_dirattr_mark_sick(struct xfs_inode *ip, int whichfork);
197 : void xfs_da_mark_sick(struct xfs_da_args *args);
198 :
199 : /* Now some helpers. */
200 :
201 : static inline bool
202 : xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask)
203 : {
204 96941 : unsigned int sick, checked;
205 :
206 96941 : xfs_fs_measure_sickness(mp, &sick, &checked);
207 96941 : return sick & mask;
208 : }
209 :
210 : static inline bool
211 : xfs_rt_has_sickness(struct xfs_mount *mp, unsigned int mask)
212 : {
213 : unsigned int sick, checked;
214 :
215 : xfs_rt_measure_sickness(mp, &sick, &checked);
216 : return sick & mask;
217 : }
218 :
219 : static inline bool
220 : xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask)
221 : {
222 2559469986 : unsigned int sick, checked;
223 :
224 2559469986 : xfs_ag_measure_sickness(pag, &sick, &checked);
225 2561061266 : return sick & mask;
226 : }
227 :
228 : static inline bool
229 : xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask)
230 : {
231 303403 : unsigned int sick, checked;
232 :
233 303403 : xfs_inode_measure_sickness(ip, &sick, &checked);
234 303417 : return sick & mask;
235 : }
236 :
237 : static inline bool
238 : xfs_fs_is_healthy(struct xfs_mount *mp)
239 : {
240 : return !xfs_fs_has_sickness(mp, -1U);
241 : }
242 :
243 : static inline bool
244 : xfs_rt_is_healthy(struct xfs_mount *mp)
245 : {
246 : return !xfs_rt_has_sickness(mp, -1U);
247 : }
248 :
249 : static inline bool
250 : xfs_ag_is_healthy(struct xfs_perag *pag)
251 : {
252 : return !xfs_ag_has_sickness(pag, -1U);
253 : }
254 :
255 : static inline bool
256 : xfs_inode_is_healthy(struct xfs_inode *ip)
257 : {
258 : return !xfs_inode_has_sickness(ip, -1U);
259 : }
260 :
261 : void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo);
262 : void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
263 : void xfs_bulkstat_health(struct xfs_inode *ip, struct xfs_bulkstat *bs);
264 :
265 : #define xfs_metadata_is_sick(error) \
266 : (unlikely((error) == -EFSCORRUPTED || (error) == -EFSBADCRC))
267 :
268 : #endif /* __XFS_HEALTH_H__ */
|