xfs_rmap.h 6.6 KB

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