xfs_health.h 10 KB

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