common.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_COMMON_H__
  7. #define __XFS_SCRUB_COMMON_H__
  8. /*
  9. * We /could/ terminate a scrub/repair operation early. If we're not
  10. * in a good place to continue (fatal signal, etc.) then bail out.
  11. * Note that we're careful not to make any judgements about *error.
  12. */
  13. static inline bool
  14. xchk_should_terminate(
  15. struct xfs_scrub *sc,
  16. int *error)
  17. {
  18. /*
  19. * If preemption is disabled, we need to yield to the scheduler every
  20. * few seconds so that we don't run afoul of the soft lockup watchdog
  21. * or RCU stall detector.
  22. */
  23. cond_resched();
  24. if (fatal_signal_pending(current)) {
  25. if (*error == 0)
  26. *error = -EAGAIN;
  27. return true;
  28. }
  29. return false;
  30. }
  31. int xchk_trans_alloc(struct xfs_scrub *sc, uint resblks);
  32. bool xchk_process_error(struct xfs_scrub *sc, xfs_agnumber_t agno,
  33. xfs_agblock_t bno, int *error);
  34. bool xchk_fblock_process_error(struct xfs_scrub *sc, int whichfork,
  35. xfs_fileoff_t offset, int *error);
  36. bool xchk_xref_process_error(struct xfs_scrub *sc,
  37. xfs_agnumber_t agno, xfs_agblock_t bno, int *error);
  38. bool xchk_fblock_xref_process_error(struct xfs_scrub *sc,
  39. int whichfork, xfs_fileoff_t offset, int *error);
  40. void xchk_block_set_preen(struct xfs_scrub *sc,
  41. struct xfs_buf *bp);
  42. void xchk_ino_set_preen(struct xfs_scrub *sc, xfs_ino_t ino);
  43. void xchk_block_set_corrupt(struct xfs_scrub *sc,
  44. struct xfs_buf *bp);
  45. void xchk_ino_set_corrupt(struct xfs_scrub *sc, xfs_ino_t ino);
  46. void xchk_fblock_set_corrupt(struct xfs_scrub *sc, int whichfork,
  47. xfs_fileoff_t offset);
  48. void xchk_block_xref_set_corrupt(struct xfs_scrub *sc,
  49. struct xfs_buf *bp);
  50. void xchk_ino_xref_set_corrupt(struct xfs_scrub *sc,
  51. xfs_ino_t ino);
  52. void xchk_fblock_xref_set_corrupt(struct xfs_scrub *sc,
  53. int whichfork, xfs_fileoff_t offset);
  54. void xchk_ino_set_warning(struct xfs_scrub *sc, xfs_ino_t ino);
  55. void xchk_fblock_set_warning(struct xfs_scrub *sc, int whichfork,
  56. xfs_fileoff_t offset);
  57. void xchk_set_incomplete(struct xfs_scrub *sc);
  58. int xchk_checkpoint_log(struct xfs_mount *mp);
  59. /* Are we set up for a cross-referencing check? */
  60. bool xchk_should_check_xref(struct xfs_scrub *sc, int *error,
  61. struct xfs_btree_cur **curpp);
  62. /* Setup functions */
  63. int xchk_setup_fs(struct xfs_scrub *sc, struct xfs_inode *ip);
  64. int xchk_setup_ag_allocbt(struct xfs_scrub *sc,
  65. struct xfs_inode *ip);
  66. int xchk_setup_ag_iallocbt(struct xfs_scrub *sc,
  67. struct xfs_inode *ip);
  68. int xchk_setup_ag_rmapbt(struct xfs_scrub *sc,
  69. struct xfs_inode *ip);
  70. int xchk_setup_ag_refcountbt(struct xfs_scrub *sc,
  71. struct xfs_inode *ip);
  72. int xchk_setup_inode(struct xfs_scrub *sc,
  73. struct xfs_inode *ip);
  74. int xchk_setup_inode_bmap(struct xfs_scrub *sc,
  75. struct xfs_inode *ip);
  76. int xchk_setup_inode_bmap_data(struct xfs_scrub *sc,
  77. struct xfs_inode *ip);
  78. int xchk_setup_directory(struct xfs_scrub *sc,
  79. struct xfs_inode *ip);
  80. int xchk_setup_xattr(struct xfs_scrub *sc,
  81. struct xfs_inode *ip);
  82. int xchk_setup_symlink(struct xfs_scrub *sc,
  83. struct xfs_inode *ip);
  84. int xchk_setup_parent(struct xfs_scrub *sc,
  85. struct xfs_inode *ip);
  86. #ifdef CONFIG_XFS_RT
  87. int xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip);
  88. #else
  89. static inline int
  90. xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip)
  91. {
  92. return -ENOENT;
  93. }
  94. #endif
  95. #ifdef CONFIG_XFS_QUOTA
  96. int xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip);
  97. #else
  98. static inline int
  99. xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip)
  100. {
  101. return -ENOENT;
  102. }
  103. #endif
  104. void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa);
  105. int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,
  106. struct xchk_ag *sa);
  107. void xchk_perag_get(struct xfs_mount *mp, struct xchk_ag *sa);
  108. int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
  109. struct xfs_buf **agi, struct xfs_buf **agf,
  110. struct xfs_buf **agfl);
  111. void xchk_ag_btcur_free(struct xchk_ag *sa);
  112. int xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
  113. int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
  114. struct xfs_owner_info *oinfo, xfs_filblks_t *blocks);
  115. int xchk_setup_ag_btree(struct xfs_scrub *sc, struct xfs_inode *ip,
  116. bool force_log);
  117. int xchk_get_inode(struct xfs_scrub *sc, struct xfs_inode *ip_in);
  118. int xchk_setup_inode_contents(struct xfs_scrub *sc, struct xfs_inode *ip,
  119. unsigned int resblks);
  120. void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp);
  121. /*
  122. * Don't bother cross-referencing if we already found corruption or cross
  123. * referencing discrepancies.
  124. */
  125. static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
  126. {
  127. return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
  128. XFS_SCRUB_OFLAG_XCORRUPT);
  129. }
  130. int xchk_metadata_inode_forks(struct xfs_scrub *sc);
  131. int xchk_ilock_inverted(struct xfs_inode *ip, uint lock_mode);
  132. #endif /* __XFS_SCRUB_COMMON_H__ */