scrub.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <[email protected]>
  5. */
  6. #ifndef __XFS_SCRUB_SCRUB_H__
  7. #define __XFS_SCRUB_SCRUB_H__
  8. struct xfs_scrub;
  9. /* Type info and names for the scrub types. */
  10. enum xchk_type {
  11. ST_NONE = 1, /* disabled */
  12. ST_PERAG, /* per-AG metadata */
  13. ST_FS, /* per-FS metadata */
  14. ST_INODE, /* per-inode metadata */
  15. };
  16. struct xchk_meta_ops {
  17. /* Acquire whatever resources are needed for the operation. */
  18. int (*setup)(struct xfs_scrub *sc);
  19. /* Examine metadata for errors. */
  20. int (*scrub)(struct xfs_scrub *);
  21. /* Repair or optimize the metadata. */
  22. int (*repair)(struct xfs_scrub *);
  23. /* Decide if we even have this piece of metadata. */
  24. bool (*has)(struct xfs_mount *);
  25. /* type describing required/allowed inputs */
  26. enum xchk_type type;
  27. };
  28. /* Buffer pointers and btree cursors for an entire AG. */
  29. struct xchk_ag {
  30. struct xfs_perag *pag;
  31. /* AG btree roots */
  32. struct xfs_buf *agf_bp;
  33. struct xfs_buf *agfl_bp;
  34. struct xfs_buf *agi_bp;
  35. /* AG btrees */
  36. struct xfs_btree_cur *bno_cur;
  37. struct xfs_btree_cur *cnt_cur;
  38. struct xfs_btree_cur *ino_cur;
  39. struct xfs_btree_cur *fino_cur;
  40. struct xfs_btree_cur *rmap_cur;
  41. struct xfs_btree_cur *refc_cur;
  42. };
  43. struct xfs_scrub {
  44. /* General scrub state. */
  45. struct xfs_mount *mp;
  46. struct xfs_scrub_metadata *sm;
  47. const struct xchk_meta_ops *ops;
  48. struct xfs_trans *tp;
  49. /* File that scrub was called with. */
  50. struct file *file;
  51. /*
  52. * File that is undergoing the scrub operation. This can differ from
  53. * the file that scrub was called with if we're checking file-based fs
  54. * metadata (e.g. rt bitmaps) or if we're doing a scrub-by-handle for
  55. * something that can't be opened directly (e.g. symlinks).
  56. */
  57. struct xfs_inode *ip;
  58. void *buf;
  59. uint ilock_flags;
  60. /* See the XCHK/XREP state flags below. */
  61. unsigned int flags;
  62. /*
  63. * The XFS_SICK_* flags that correspond to the metadata being scrubbed
  64. * or repaired. We will use this mask to update the in-core fs health
  65. * status with whatever we find.
  66. */
  67. unsigned int sick_mask;
  68. /* State tracking for single-AG operations. */
  69. struct xchk_ag sa;
  70. };
  71. /* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
  72. #define XCHK_TRY_HARDER (1 << 0) /* can't get resources, try again */
  73. #define XREP_ALREADY_FIXED (1 << 31) /* checking our repair work */
  74. /* Metadata scrubbers */
  75. int xchk_tester(struct xfs_scrub *sc);
  76. int xchk_superblock(struct xfs_scrub *sc);
  77. int xchk_agf(struct xfs_scrub *sc);
  78. int xchk_agfl(struct xfs_scrub *sc);
  79. int xchk_agi(struct xfs_scrub *sc);
  80. int xchk_bnobt(struct xfs_scrub *sc);
  81. int xchk_cntbt(struct xfs_scrub *sc);
  82. int xchk_inobt(struct xfs_scrub *sc);
  83. int xchk_finobt(struct xfs_scrub *sc);
  84. int xchk_rmapbt(struct xfs_scrub *sc);
  85. int xchk_refcountbt(struct xfs_scrub *sc);
  86. int xchk_inode(struct xfs_scrub *sc);
  87. int xchk_bmap_data(struct xfs_scrub *sc);
  88. int xchk_bmap_attr(struct xfs_scrub *sc);
  89. int xchk_bmap_cow(struct xfs_scrub *sc);
  90. int xchk_directory(struct xfs_scrub *sc);
  91. int xchk_xattr(struct xfs_scrub *sc);
  92. int xchk_symlink(struct xfs_scrub *sc);
  93. int xchk_parent(struct xfs_scrub *sc);
  94. #ifdef CONFIG_XFS_RT
  95. int xchk_rtbitmap(struct xfs_scrub *sc);
  96. int xchk_rtsummary(struct xfs_scrub *sc);
  97. #else
  98. static inline int
  99. xchk_rtbitmap(struct xfs_scrub *sc)
  100. {
  101. return -ENOENT;
  102. }
  103. static inline int
  104. xchk_rtsummary(struct xfs_scrub *sc)
  105. {
  106. return -ENOENT;
  107. }
  108. #endif
  109. #ifdef CONFIG_XFS_QUOTA
  110. int xchk_quota(struct xfs_scrub *sc);
  111. #else
  112. static inline int
  113. xchk_quota(struct xfs_scrub *sc)
  114. {
  115. return -ENOENT;
  116. }
  117. #endif
  118. int xchk_fscounters(struct xfs_scrub *sc);
  119. /* cross-referencing helpers */
  120. void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
  121. xfs_extlen_t len);
  122. void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
  123. xfs_extlen_t len);
  124. void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
  125. xfs_extlen_t len);
  126. void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
  127. xfs_extlen_t len, const struct xfs_owner_info *oinfo);
  128. void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
  129. xfs_extlen_t len, const struct xfs_owner_info *oinfo);
  130. void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
  131. xfs_extlen_t len);
  132. void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
  133. xfs_extlen_t len);
  134. void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
  135. xfs_extlen_t len);
  136. #ifdef CONFIG_XFS_RT
  137. void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
  138. xfs_extlen_t len);
  139. #else
  140. # define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
  141. #endif
  142. struct xchk_fscounters {
  143. uint64_t icount;
  144. uint64_t ifree;
  145. uint64_t fdblocks;
  146. unsigned long long icount_min;
  147. unsigned long long icount_max;
  148. };
  149. #endif /* __XFS_SCRUB_SCRUB_H__ */