xfs_refcount.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  5. */
  6. #ifndef __XFS_REFCOUNT_H__
  7. #define __XFS_REFCOUNT_H__
  8. extern int xfs_refcount_lookup_le(struct xfs_btree_cur *cur,
  9. xfs_agblock_t bno, int *stat);
  10. extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur,
  11. xfs_agblock_t bno, int *stat);
  12. extern int xfs_refcount_lookup_eq(struct xfs_btree_cur *cur,
  13. xfs_agblock_t bno, int *stat);
  14. extern int xfs_refcount_get_rec(struct xfs_btree_cur *cur,
  15. struct xfs_refcount_irec *irec, int *stat);
  16. enum xfs_refcount_intent_type {
  17. XFS_REFCOUNT_INCREASE = 1,
  18. XFS_REFCOUNT_DECREASE,
  19. XFS_REFCOUNT_ALLOC_COW,
  20. XFS_REFCOUNT_FREE_COW,
  21. };
  22. struct xfs_refcount_intent {
  23. struct list_head ri_list;
  24. enum xfs_refcount_intent_type ri_type;
  25. xfs_fsblock_t ri_startblock;
  26. xfs_extlen_t ri_blockcount;
  27. };
  28. extern int xfs_refcount_increase_extent(struct xfs_mount *mp,
  29. struct xfs_defer_ops *dfops, struct xfs_bmbt_irec *irec);
  30. extern int xfs_refcount_decrease_extent(struct xfs_mount *mp,
  31. struct xfs_defer_ops *dfops, struct xfs_bmbt_irec *irec);
  32. extern void xfs_refcount_finish_one_cleanup(struct xfs_trans *tp,
  33. struct xfs_btree_cur *rcur, int error);
  34. extern int xfs_refcount_finish_one(struct xfs_trans *tp,
  35. struct xfs_defer_ops *dfops, enum xfs_refcount_intent_type type,
  36. xfs_fsblock_t startblock, xfs_extlen_t blockcount,
  37. xfs_fsblock_t *new_fsb, xfs_extlen_t *new_len,
  38. struct xfs_btree_cur **pcur);
  39. extern int xfs_refcount_find_shared(struct xfs_btree_cur *cur,
  40. xfs_agblock_t agbno, xfs_extlen_t aglen, xfs_agblock_t *fbno,
  41. xfs_extlen_t *flen, bool find_end_of_shared);
  42. extern int xfs_refcount_alloc_cow_extent(struct xfs_mount *mp,
  43. struct xfs_defer_ops *dfops, xfs_fsblock_t fsb,
  44. xfs_extlen_t len);
  45. extern int xfs_refcount_free_cow_extent(struct xfs_mount *mp,
  46. struct xfs_defer_ops *dfops, xfs_fsblock_t fsb,
  47. xfs_extlen_t len);
  48. extern int xfs_refcount_recover_cow_leftovers(struct xfs_mount *mp,
  49. xfs_agnumber_t agno);
  50. /*
  51. * While we're adjusting the refcounts records of an extent, we have
  52. * to keep an eye on the number of extents we're dirtying -- run too
  53. * many in a single transaction and we'll exceed the transaction's
  54. * reservation and crash the fs. Each record adds 12 bytes to the
  55. * log (plus any key updates) so we'll conservatively assume 32 bytes
  56. * per record. We must also leave space for btree splits on both ends
  57. * of the range and space for the CUD and a new CUI.
  58. */
  59. #define XFS_REFCOUNT_ITEM_OVERHEAD 32
  60. static inline xfs_fileoff_t xfs_refcount_max_unmap(int log_res)
  61. {
  62. return (log_res * 3 / 4) / XFS_REFCOUNT_ITEM_OVERHEAD;
  63. }
  64. extern int xfs_refcount_has_record(struct xfs_btree_cur *cur,
  65. xfs_agblock_t bno, xfs_extlen_t len, bool *exists);
  66. union xfs_btree_rec;
  67. extern void xfs_refcount_btrec_to_irec(union xfs_btree_rec *rec,
  68. struct xfs_refcount_irec *irec);
  69. extern int xfs_refcount_insert(struct xfs_btree_cur *cur,
  70. struct xfs_refcount_irec *irec, int *stat);
  71. #endif /* __XFS_REFCOUNT_H__ */