btree.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2017-2023 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #ifndef __XFS_SCRUB_BTREE_H__
  7. #define __XFS_SCRUB_BTREE_H__
  8. /* btree scrub */
  9. /* Check for btree operation errors. */
  10. bool xchk_btree_process_error(struct xfs_scrub *sc,
  11. struct xfs_btree_cur *cur, int level, int *error);
  12. /* Check for btree xref operation errors. */
  13. bool xchk_btree_xref_process_error(struct xfs_scrub *sc,
  14. struct xfs_btree_cur *cur, int level, int *error);
  15. /* Check for btree corruption. */
  16. void xchk_btree_set_corrupt(struct xfs_scrub *sc,
  17. struct xfs_btree_cur *cur, int level);
  18. void xchk_btree_set_preen(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
  19. int level);
  20. /* Check for btree xref discrepancies. */
  21. void xchk_btree_xref_set_corrupt(struct xfs_scrub *sc,
  22. struct xfs_btree_cur *cur, int level);
  23. struct xchk_btree;
  24. typedef int (*xchk_btree_rec_fn)(
  25. struct xchk_btree *bs,
  26. const union xfs_btree_rec *rec);
  27. struct xchk_btree_key {
  28. union xfs_btree_key key;
  29. bool valid;
  30. };
  31. struct xchk_btree {
  32. /* caller-provided scrub state */
  33. struct xfs_scrub *sc;
  34. struct xfs_btree_cur *cur;
  35. xchk_btree_rec_fn scrub_rec;
  36. const struct xfs_owner_info *oinfo;
  37. void *private;
  38. /* internal scrub state */
  39. bool lastrec_valid;
  40. union xfs_btree_rec lastrec;
  41. struct list_head to_check;
  42. /* this element must come last! */
  43. struct xchk_btree_key lastkey[];
  44. };
  45. /*
  46. * Calculate the size of a xchk_btree structure. There are nlevels-1 slots for
  47. * keys because we track leaf records separately in lastrec.
  48. */
  49. static inline size_t
  50. xchk_btree_sizeof(unsigned int nlevels)
  51. {
  52. return struct_size_t(struct xchk_btree, lastkey, nlevels - 1);
  53. }
  54. int xchk_btree(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
  55. xchk_btree_rec_fn scrub_fn, const struct xfs_owner_info *oinfo,
  56. void *private);
  57. #endif /* __XFS_SCRUB_BTREE_H__ */