rtbitmap.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2023 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #ifndef __XFS_SCRUB_RTBITMAP_H__
  7. #define __XFS_SCRUB_RTBITMAP_H__
  8. /*
  9. * We use an xfile to construct new bitmap blocks for the portion of the
  10. * rtbitmap file that we're replacing. Whereas the ondisk bitmap must be
  11. * accessed through the buffer cache, the xfile bitmap supports direct
  12. * word-level accesses. Therefore, we create a small abstraction for linear
  13. * access.
  14. */
  15. typedef unsigned long long xrep_wordoff_t;
  16. typedef unsigned int xrep_wordcnt_t;
  17. /* Mask to round an rtx down to the nearest bitmap word. */
  18. #define XREP_RTBMP_WORDMASK ((1ULL << XFS_NBWORDLOG) - 1)
  19. struct xchk_rtbitmap {
  20. struct xfs_scrub *sc;
  21. uint64_t rextents;
  22. uint64_t rbmblocks;
  23. unsigned int rextslog;
  24. unsigned int resblks;
  25. /* The next free rt group block number that we expect to see. */
  26. xfs_rgblock_t next_free_rgbno;
  27. #ifdef CONFIG_XFS_ONLINE_REPAIR
  28. /* stuff for staging a new bitmap */
  29. struct xfs_rtalloc_args args;
  30. struct xrep_tempexch tempexch;
  31. #endif
  32. /* The next rtgroup block we expect to see during our rtrmapbt walk. */
  33. xfs_rgblock_t next_rgbno;
  34. /* rtgroup lock flags */
  35. unsigned int rtglock_flags;
  36. /* rtword position of xfile as we write buffers to disk. */
  37. xrep_wordoff_t prep_wordoff;
  38. /* In-Memory rtbitmap for repair. */
  39. union xfs_rtword_raw words[];
  40. };
  41. #ifdef CONFIG_XFS_ONLINE_REPAIR
  42. int xrep_setup_rtbitmap(struct xfs_scrub *sc, struct xchk_rtbitmap *rtb);
  43. /*
  44. * How big should the words[] buffer be?
  45. *
  46. * For repairs, we want a full fsblock worth of space so that we can memcpy a
  47. * buffer full of 1s into the xfile bitmap. The xfile bitmap doesn't have
  48. * rtbitmap block headers, so we don't use blockwsize. Scrub doesn't use the
  49. * words buffer at all.
  50. */
  51. static inline unsigned int
  52. xchk_rtbitmap_wordcnt(
  53. struct xfs_scrub *sc)
  54. {
  55. if (xchk_could_repair(sc))
  56. return sc->mp->m_sb.sb_blocksize >> XFS_WORDLOG;
  57. return 0;
  58. }
  59. #else
  60. # define xrep_setup_rtbitmap(sc, rtb) (0)
  61. # define xchk_rtbitmap_wordcnt(sc) (0)
  62. #endif /* CONFIG_XFS_ONLINE_REPAIR */
  63. #endif /* __XFS_SCRUB_RTBITMAP_H__ */