scrub.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_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 *,
  19. struct xfs_inode *);
  20. /* Examine metadata for errors. */
  21. int (*scrub)(struct xfs_scrub *);
  22. /* Repair or optimize the metadata. */
  23. int (*repair)(struct xfs_scrub *);
  24. /* Decide if we even have this piece of metadata. */
  25. bool (*has)(struct xfs_sb *);
  26. /* type describing required/allowed inputs */
  27. enum xchk_type type;
  28. };
  29. /* Buffer pointers and btree cursors for an entire AG. */
  30. struct xchk_ag {
  31. xfs_agnumber_t agno;
  32. struct xfs_perag *pag;
  33. /* AG btree roots */
  34. struct xfs_buf *agf_bp;
  35. struct xfs_buf *agfl_bp;
  36. struct xfs_buf *agi_bp;
  37. /* AG btrees */
  38. struct xfs_btree_cur *bno_cur;
  39. struct xfs_btree_cur *cnt_cur;
  40. struct xfs_btree_cur *ino_cur;
  41. struct xfs_btree_cur *fino_cur;
  42. struct xfs_btree_cur *rmap_cur;
  43. struct xfs_btree_cur *refc_cur;
  44. };
  45. struct xfs_scrub {
  46. /* General scrub state. */
  47. struct xfs_mount *mp;
  48. struct xfs_scrub_metadata *sm;
  49. const struct xchk_meta_ops *ops;
  50. struct xfs_trans *tp;
  51. struct xfs_inode *ip;
  52. void *buf;
  53. uint ilock_flags;
  54. bool try_harder;
  55. bool has_quotaofflock;
  56. /* State tracking for single-AG operations. */
  57. struct xchk_ag sa;
  58. };
  59. /* Metadata scrubbers */
  60. int xchk_tester(struct xfs_scrub *sc);
  61. int xchk_superblock(struct xfs_scrub *sc);
  62. int xchk_agf(struct xfs_scrub *sc);
  63. int xchk_agfl(struct xfs_scrub *sc);
  64. int xchk_agi(struct xfs_scrub *sc);
  65. int xchk_bnobt(struct xfs_scrub *sc);
  66. int xchk_cntbt(struct xfs_scrub *sc);
  67. int xchk_inobt(struct xfs_scrub *sc);
  68. int xchk_finobt(struct xfs_scrub *sc);
  69. int xchk_rmapbt(struct xfs_scrub *sc);
  70. int xchk_refcountbt(struct xfs_scrub *sc);
  71. int xchk_inode(struct xfs_scrub *sc);
  72. int xchk_bmap_data(struct xfs_scrub *sc);
  73. int xchk_bmap_attr(struct xfs_scrub *sc);
  74. int xchk_bmap_cow(struct xfs_scrub *sc);
  75. int xchk_directory(struct xfs_scrub *sc);
  76. int xchk_xattr(struct xfs_scrub *sc);
  77. int xchk_symlink(struct xfs_scrub *sc);
  78. int xchk_parent(struct xfs_scrub *sc);
  79. #ifdef CONFIG_XFS_RT
  80. int xchk_rtbitmap(struct xfs_scrub *sc);
  81. int xchk_rtsummary(struct xfs_scrub *sc);
  82. #else
  83. static inline int
  84. xchk_rtbitmap(struct xfs_scrub *sc)
  85. {
  86. return -ENOENT;
  87. }
  88. static inline int
  89. xchk_rtsummary(struct xfs_scrub *sc)
  90. {
  91. return -ENOENT;
  92. }
  93. #endif
  94. #ifdef CONFIG_XFS_QUOTA
  95. int xchk_quota(struct xfs_scrub *sc);
  96. #else
  97. static inline int
  98. xchk_quota(struct xfs_scrub *sc)
  99. {
  100. return -ENOENT;
  101. }
  102. #endif
  103. /* cross-referencing helpers */
  104. void xchk_xref_is_used_space(struct xfs_scrub *sc, xfs_agblock_t agbno,
  105. xfs_extlen_t len);
  106. void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
  107. xfs_extlen_t len);
  108. void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno,
  109. xfs_extlen_t len);
  110. void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
  111. xfs_extlen_t len, struct xfs_owner_info *oinfo);
  112. void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno,
  113. xfs_extlen_t len, struct xfs_owner_info *oinfo);
  114. void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno,
  115. xfs_extlen_t len);
  116. void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno,
  117. xfs_extlen_t len);
  118. void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,
  119. xfs_extlen_t len);
  120. #ifdef CONFIG_XFS_RT
  121. void xchk_xref_is_used_rt_space(struct xfs_scrub *sc, xfs_rtblock_t rtbno,
  122. xfs_extlen_t len);
  123. #else
  124. # define xchk_xref_is_used_rt_space(sc, rtbno, len) do { } while (0)
  125. #endif
  126. #endif /* __XFS_SCRUB_SCRUB_H__ */