btree.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <[email protected]>
  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. /* Check for btree xref discrepancies. */
  19. void xchk_btree_xref_set_corrupt(struct xfs_scrub *sc,
  20. struct xfs_btree_cur *cur, int level);
  21. struct xchk_btree;
  22. typedef int (*xchk_btree_rec_fn)(
  23. struct xchk_btree *bs,
  24. const union xfs_btree_rec *rec);
  25. struct xchk_btree {
  26. /* caller-provided scrub state */
  27. struct xfs_scrub *sc;
  28. struct xfs_btree_cur *cur;
  29. xchk_btree_rec_fn scrub_rec;
  30. const struct xfs_owner_info *oinfo;
  31. void *private;
  32. /* internal scrub state */
  33. union xfs_btree_rec lastrec;
  34. struct list_head to_check;
  35. /* this element must come last! */
  36. union xfs_btree_key lastkey[];
  37. };
  38. /*
  39. * Calculate the size of a xchk_btree structure. There are nlevels-1 slots for
  40. * keys because we track leaf records separately in lastrec.
  41. */
  42. static inline size_t
  43. xchk_btree_sizeof(unsigned int nlevels)
  44. {
  45. return struct_size((struct xchk_btree *)NULL, lastkey, nlevels - 1);
  46. }
  47. int xchk_btree(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
  48. xchk_btree_rec_fn scrub_fn, const struct xfs_owner_info *oinfo,
  49. void *private);
  50. #endif /* __XFS_SCRUB_BTREE_H__ */