iscan.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2021-2024 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #ifndef __XFS_SCRUB_ISCAN_H__
  7. #define __XFS_SCRUB_ISCAN_H__
  8. struct xchk_iscan {
  9. struct xfs_scrub *sc;
  10. /* Lock to protect the scan cursor. */
  11. struct mutex lock;
  12. /*
  13. * This is the first inode in the inumber address space that we
  14. * examined. When the scan wraps around back to here, the scan is
  15. * finished.
  16. */
  17. xfs_ino_t scan_start_ino;
  18. /* This is the inode that will be examined next. */
  19. xfs_ino_t cursor_ino;
  20. /* If nonzero and non-NULL, skip this inode when scanning. */
  21. xfs_ino_t skip_ino;
  22. /*
  23. * This is the last inode that we've successfully scanned, either
  24. * because the caller scanned it, or we moved the cursor past an empty
  25. * part of the inode address space. Scan callers should only use the
  26. * xchk_iscan_visit function to modify this.
  27. */
  28. xfs_ino_t __visited_ino;
  29. /* Operational state of the livescan. */
  30. unsigned long __opstate;
  31. /* Give up on iterating @cursor_ino if we can't iget it by this time. */
  32. unsigned long __iget_deadline;
  33. /* Amount of time (in ms) that we will try to iget an inode. */
  34. unsigned int iget_timeout;
  35. /* Wait this many ms to retry an iget. */
  36. unsigned int iget_retry_delay;
  37. /*
  38. * The scan grabs batches of inodes and stashes them here before
  39. * handing them out with _iter. Unallocated inodes are set in the
  40. * mask so that all updates to that inode are selected for live
  41. * update propagation.
  42. */
  43. xfs_ino_t __batch_ino;
  44. xfs_inofree_t __skipped_inomask;
  45. struct xfs_inode *__inodes[XFS_INODES_PER_CHUNK];
  46. };
  47. /* Set if the scan has been aborted due to some event in the fs. */
  48. #define XCHK_ISCAN_OPSTATE_ABORTED (1)
  49. /* Use trylock to acquire the AGI */
  50. #define XCHK_ISCAN_OPSTATE_TRYLOCK_AGI (2)
  51. static inline bool
  52. xchk_iscan_aborted(const struct xchk_iscan *iscan)
  53. {
  54. return test_bit(XCHK_ISCAN_OPSTATE_ABORTED, &iscan->__opstate);
  55. }
  56. static inline void
  57. xchk_iscan_abort(struct xchk_iscan *iscan)
  58. {
  59. set_bit(XCHK_ISCAN_OPSTATE_ABORTED, &iscan->__opstate);
  60. }
  61. static inline bool
  62. xchk_iscan_agi_needs_trylock(const struct xchk_iscan *iscan)
  63. {
  64. return test_bit(XCHK_ISCAN_OPSTATE_TRYLOCK_AGI, &iscan->__opstate);
  65. }
  66. static inline void
  67. xchk_iscan_set_agi_trylock(struct xchk_iscan *iscan)
  68. {
  69. set_bit(XCHK_ISCAN_OPSTATE_TRYLOCK_AGI, &iscan->__opstate);
  70. }
  71. void xchk_iscan_start(struct xfs_scrub *sc, unsigned int iget_timeout,
  72. unsigned int iget_retry_delay, struct xchk_iscan *iscan);
  73. void xchk_iscan_finish_early(struct xchk_iscan *iscan);
  74. void xchk_iscan_teardown(struct xchk_iscan *iscan);
  75. int xchk_iscan_iter(struct xchk_iscan *iscan, struct xfs_inode **ipp);
  76. void xchk_iscan_iter_finish(struct xchk_iscan *iscan);
  77. void xchk_iscan_mark_visited(struct xchk_iscan *iscan, struct xfs_inode *ip);
  78. bool xchk_iscan_want_live_update(struct xchk_iscan *iscan, xfs_ino_t ino);
  79. #endif /* __XFS_SCRUB_ISCAN_H__ */