xref: /linux/fs/xfs/libxfs/xfs_health.h (revision 24b10e5f8e0d2bee1a10fc67011ea5d936c1a389)
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         => has not been examined since mount
32  */
33 
34 struct xfs_mount;
35 struct xfs_perag;
36 struct xfs_inode;
37 struct xfs_fsop_geom;
38 
39 /* Observable health issues for metadata spanning the entire filesystem. */
40 #define XFS_SICK_FS_COUNTERS	(1 << 0)  /* summary counters */
41 #define XFS_SICK_FS_UQUOTA	(1 << 1)  /* user quota */
42 #define XFS_SICK_FS_GQUOTA	(1 << 2)  /* group quota */
43 #define XFS_SICK_FS_PQUOTA	(1 << 3)  /* project quota */
44 
45 /* Observable health issues for realtime volume metadata. */
46 #define XFS_SICK_RT_BITMAP	(1 << 0)  /* realtime bitmap */
47 #define XFS_SICK_RT_SUMMARY	(1 << 1)  /* realtime summary */
48 
49 /* Observable health issues for AG metadata. */
50 #define XFS_SICK_AG_SB		(1 << 0)  /* superblock */
51 #define XFS_SICK_AG_AGF		(1 << 1)  /* AGF header */
52 #define XFS_SICK_AG_AGFL	(1 << 2)  /* AGFL header */
53 #define XFS_SICK_AG_AGI		(1 << 3)  /* AGI header */
54 #define XFS_SICK_AG_BNOBT	(1 << 4)  /* free space by block */
55 #define XFS_SICK_AG_CNTBT	(1 << 5)  /* free space by length */
56 #define XFS_SICK_AG_INOBT	(1 << 6)  /* inode index */
57 #define XFS_SICK_AG_FINOBT	(1 << 7)  /* free inode index */
58 #define XFS_SICK_AG_RMAPBT	(1 << 8)  /* reverse mappings */
59 #define XFS_SICK_AG_REFCNTBT	(1 << 9)  /* reference counts */
60 
61 /* Observable health issues for inode metadata. */
62 #define XFS_SICK_INO_CORE	(1 << 0)  /* inode core */
63 #define XFS_SICK_INO_BMBTD	(1 << 1)  /* data fork */
64 #define XFS_SICK_INO_BMBTA	(1 << 2)  /* attr fork */
65 #define XFS_SICK_INO_BMBTC	(1 << 3)  /* cow fork */
66 #define XFS_SICK_INO_DIR	(1 << 4)  /* directory */
67 #define XFS_SICK_INO_XATTR	(1 << 5)  /* extended attributes */
68 #define XFS_SICK_INO_SYMLINK	(1 << 6)  /* symbolic link remote target */
69 #define XFS_SICK_INO_PARENT	(1 << 7)  /* parent pointers */
70 
71 #define XFS_SICK_INO_BMBTD_ZAPPED	(1 << 8)  /* data fork erased */
72 #define XFS_SICK_INO_BMBTA_ZAPPED	(1 << 9)  /* attr fork erased */
73 #define XFS_SICK_INO_DIR_ZAPPED		(1 << 10) /* directory erased */
74 #define XFS_SICK_INO_SYMLINK_ZAPPED	(1 << 11) /* symlink erased */
75 
76 /* Primary evidence of health problems in a given group. */
77 #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
78 				 XFS_SICK_FS_UQUOTA | \
79 				 XFS_SICK_FS_GQUOTA | \
80 				 XFS_SICK_FS_PQUOTA)
81 
82 #define XFS_SICK_RT_PRIMARY	(XFS_SICK_RT_BITMAP | \
83 				 XFS_SICK_RT_SUMMARY)
84 
85 #define XFS_SICK_AG_PRIMARY	(XFS_SICK_AG_SB | \
86 				 XFS_SICK_AG_AGF | \
87 				 XFS_SICK_AG_AGFL | \
88 				 XFS_SICK_AG_AGI | \
89 				 XFS_SICK_AG_BNOBT | \
90 				 XFS_SICK_AG_CNTBT | \
91 				 XFS_SICK_AG_INOBT | \
92 				 XFS_SICK_AG_FINOBT | \
93 				 XFS_SICK_AG_RMAPBT | \
94 				 XFS_SICK_AG_REFCNTBT)
95 
96 #define XFS_SICK_INO_PRIMARY	(XFS_SICK_INO_CORE | \
97 				 XFS_SICK_INO_BMBTD | \
98 				 XFS_SICK_INO_BMBTA | \
99 				 XFS_SICK_INO_BMBTC | \
100 				 XFS_SICK_INO_DIR | \
101 				 XFS_SICK_INO_XATTR | \
102 				 XFS_SICK_INO_SYMLINK | \
103 				 XFS_SICK_INO_PARENT)
104 
105 #define XFS_SICK_INO_ZAPPED	(XFS_SICK_INO_BMBTD_ZAPPED | \
106 				 XFS_SICK_INO_BMBTA_ZAPPED | \
107 				 XFS_SICK_INO_DIR_ZAPPED | \
108 				 XFS_SICK_INO_SYMLINK_ZAPPED)
109 
110 /* These functions must be provided by the xfs implementation. */
111 
112 void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask);
113 void xfs_fs_mark_healthy(struct xfs_mount *mp, unsigned int mask);
114 void xfs_fs_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
115 		unsigned int *checked);
116 
117 void xfs_rt_mark_sick(struct xfs_mount *mp, unsigned int mask);
118 void xfs_rt_mark_healthy(struct xfs_mount *mp, unsigned int mask);
119 void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
120 		unsigned int *checked);
121 
122 void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask);
123 void xfs_ag_mark_healthy(struct xfs_perag *pag, unsigned int mask);
124 void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick,
125 		unsigned int *checked);
126 
127 void xfs_inode_mark_sick(struct xfs_inode *ip, unsigned int mask);
128 void xfs_inode_mark_healthy(struct xfs_inode *ip, unsigned int mask);
129 void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,
130 		unsigned int *checked);
131 
132 void xfs_health_unmount(struct xfs_mount *mp);
133 
134 /* Now some helpers. */
135 
136 static inline bool
137 xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask)
138 {
139 	unsigned int	sick, checked;
140 
141 	xfs_fs_measure_sickness(mp, &sick, &checked);
142 	return sick & mask;
143 }
144 
145 static inline bool
146 xfs_rt_has_sickness(struct xfs_mount *mp, unsigned int mask)
147 {
148 	unsigned int	sick, checked;
149 
150 	xfs_rt_measure_sickness(mp, &sick, &checked);
151 	return sick & mask;
152 }
153 
154 static inline bool
155 xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask)
156 {
157 	unsigned int	sick, checked;
158 
159 	xfs_ag_measure_sickness(pag, &sick, &checked);
160 	return sick & mask;
161 }
162 
163 static inline bool
164 xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask)
165 {
166 	unsigned int	sick, checked;
167 
168 	xfs_inode_measure_sickness(ip, &sick, &checked);
169 	return sick & mask;
170 }
171 
172 static inline bool
173 xfs_fs_is_healthy(struct xfs_mount *mp)
174 {
175 	return !xfs_fs_has_sickness(mp, -1U);
176 }
177 
178 static inline bool
179 xfs_rt_is_healthy(struct xfs_mount *mp)
180 {
181 	return !xfs_rt_has_sickness(mp, -1U);
182 }
183 
184 static inline bool
185 xfs_ag_is_healthy(struct xfs_perag *pag)
186 {
187 	return !xfs_ag_has_sickness(pag, -1U);
188 }
189 
190 static inline bool
191 xfs_inode_is_healthy(struct xfs_inode *ip)
192 {
193 	return !xfs_inode_has_sickness(ip, -1U);
194 }
195 
196 void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo);
197 void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
198 void xfs_bulkstat_health(struct xfs_inode *ip, struct xfs_bulkstat *bs);
199 
200 #endif	/* __XFS_HEALTH_H__ */
201