xfs_rmap.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_RMAP_H__
  7. #define __XFS_RMAP_H__
  8. static inline void
  9. xfs_rmap_ag_owner(
  10. struct xfs_owner_info *oi,
  11. uint64_t owner)
  12. {
  13. oi->oi_owner = owner;
  14. oi->oi_offset = 0;
  15. oi->oi_flags = 0;
  16. }
  17. static inline void
  18. xfs_rmap_ino_bmbt_owner(
  19. struct xfs_owner_info *oi,
  20. xfs_ino_t ino,
  21. int whichfork)
  22. {
  23. oi->oi_owner = ino;
  24. oi->oi_offset = 0;
  25. oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
  26. if (whichfork == XFS_ATTR_FORK)
  27. oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  28. }
  29. static inline void
  30. xfs_rmap_ino_owner(
  31. struct xfs_owner_info *oi,
  32. xfs_ino_t ino,
  33. int whichfork,
  34. xfs_fileoff_t offset)
  35. {
  36. oi->oi_owner = ino;
  37. oi->oi_offset = offset;
  38. oi->oi_flags = 0;
  39. if (whichfork == XFS_ATTR_FORK)
  40. oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  41. }
  42. static inline void
  43. xfs_rmap_skip_owner_update(
  44. struct xfs_owner_info *oi)
  45. {
  46. xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_NULL);
  47. }
  48. static inline bool
  49. xfs_rmap_should_skip_owner_update(
  50. struct xfs_owner_info *oi)
  51. {
  52. return oi->oi_owner == XFS_RMAP_OWN_NULL;
  53. }
  54. static inline void
  55. xfs_rmap_any_owner_update(
  56. struct xfs_owner_info *oi)
  57. {
  58. xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_UNKNOWN);
  59. }
  60. /* Reverse mapping functions. */
  61. struct xfs_buf;
  62. static inline __u64
  63. xfs_rmap_irec_offset_pack(
  64. const struct xfs_rmap_irec *irec)
  65. {
  66. __u64 x;
  67. x = XFS_RMAP_OFF(irec->rm_offset);
  68. if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
  69. x |= XFS_RMAP_OFF_ATTR_FORK;
  70. if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
  71. x |= XFS_RMAP_OFF_BMBT_BLOCK;
  72. if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
  73. x |= XFS_RMAP_OFF_UNWRITTEN;
  74. return x;
  75. }
  76. static inline int
  77. xfs_rmap_irec_offset_unpack(
  78. __u64 offset,
  79. struct xfs_rmap_irec *irec)
  80. {
  81. if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
  82. return -EFSCORRUPTED;
  83. irec->rm_offset = XFS_RMAP_OFF(offset);
  84. if (offset & XFS_RMAP_OFF_ATTR_FORK)
  85. irec->rm_flags |= XFS_RMAP_ATTR_FORK;
  86. if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
  87. irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
  88. if (offset & XFS_RMAP_OFF_UNWRITTEN)
  89. irec->rm_flags |= XFS_RMAP_UNWRITTEN;
  90. return 0;
  91. }
  92. static inline void
  93. xfs_owner_info_unpack(
  94. struct xfs_owner_info *oinfo,
  95. uint64_t *owner,
  96. uint64_t *offset,
  97. unsigned int *flags)
  98. {
  99. unsigned int r = 0;
  100. *owner = oinfo->oi_owner;
  101. *offset = oinfo->oi_offset;
  102. if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
  103. r |= XFS_RMAP_ATTR_FORK;
  104. if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
  105. r |= XFS_RMAP_BMBT_BLOCK;
  106. *flags = r;
  107. }
  108. static inline void
  109. xfs_owner_info_pack(
  110. struct xfs_owner_info *oinfo,
  111. uint64_t owner,
  112. uint64_t offset,
  113. unsigned int flags)
  114. {
  115. oinfo->oi_owner = owner;
  116. oinfo->oi_offset = XFS_RMAP_OFF(offset);
  117. oinfo->oi_flags = 0;
  118. if (flags & XFS_RMAP_ATTR_FORK)
  119. oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  120. if (flags & XFS_RMAP_BMBT_BLOCK)
  121. oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
  122. }
  123. int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
  124. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  125. struct xfs_owner_info *oinfo);
  126. int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
  127. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  128. struct xfs_owner_info *oinfo);
  129. int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  130. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  131. unsigned int flags, int *stat);
  132. int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  133. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  134. unsigned int flags, int *stat);
  135. int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
  136. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  137. unsigned int flags);
  138. int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
  139. int *stat);
  140. typedef int (*xfs_rmap_query_range_fn)(
  141. struct xfs_btree_cur *cur,
  142. struct xfs_rmap_irec *rec,
  143. void *priv);
  144. int xfs_rmap_query_range(struct xfs_btree_cur *cur,
  145. struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
  146. xfs_rmap_query_range_fn fn, void *priv);
  147. int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
  148. void *priv);
  149. enum xfs_rmap_intent_type {
  150. XFS_RMAP_MAP,
  151. XFS_RMAP_MAP_SHARED,
  152. XFS_RMAP_UNMAP,
  153. XFS_RMAP_UNMAP_SHARED,
  154. XFS_RMAP_CONVERT,
  155. XFS_RMAP_CONVERT_SHARED,
  156. XFS_RMAP_ALLOC,
  157. XFS_RMAP_FREE,
  158. };
  159. struct xfs_rmap_intent {
  160. struct list_head ri_list;
  161. enum xfs_rmap_intent_type ri_type;
  162. uint64_t ri_owner;
  163. int ri_whichfork;
  164. struct xfs_bmbt_irec ri_bmap;
  165. };
  166. /* functions for updating the rmapbt based on bmbt map/unmap operations */
  167. int xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
  168. int whichfork, struct xfs_bmbt_irec *imap);
  169. int xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
  170. int whichfork, struct xfs_bmbt_irec *imap);
  171. int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
  172. struct xfs_inode *ip, int whichfork,
  173. struct xfs_bmbt_irec *imap);
  174. int xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
  175. xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
  176. int xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
  177. xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
  178. void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
  179. struct xfs_btree_cur *rcur, int error);
  180. int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
  181. uint64_t owner, int whichfork, xfs_fileoff_t startoff,
  182. xfs_fsblock_t startblock, xfs_filblks_t blockcount,
  183. xfs_exntst_t state, struct xfs_btree_cur **pcur);
  184. int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  185. uint64_t owner, uint64_t offset, unsigned int flags,
  186. struct xfs_rmap_irec *irec, int *stat);
  187. int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  188. uint64_t owner, uint64_t offset, unsigned int flags,
  189. struct xfs_rmap_irec *irec, int *stat);
  190. int xfs_rmap_compare(const struct xfs_rmap_irec *a,
  191. const struct xfs_rmap_irec *b);
  192. union xfs_btree_rec;
  193. int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
  194. struct xfs_rmap_irec *irec);
  195. int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  196. xfs_extlen_t len, bool *exists);
  197. int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  198. xfs_extlen_t len, struct xfs_owner_info *oinfo,
  199. bool *has_rmap);
  200. int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  201. xfs_extlen_t len, struct xfs_owner_info *oinfo,
  202. bool *has_rmap);
  203. int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
  204. #endif /* __XFS_RMAP_H__ */