xfs_rmap.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (C) 2016 Oracle. All Rights Reserved.
  3. *
  4. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it would be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write the Free Software Foundation,
  18. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef __XFS_RMAP_H__
  21. #define __XFS_RMAP_H__
  22. static inline void
  23. xfs_rmap_ag_owner(
  24. struct xfs_owner_info *oi,
  25. uint64_t owner)
  26. {
  27. oi->oi_owner = owner;
  28. oi->oi_offset = 0;
  29. oi->oi_flags = 0;
  30. }
  31. static inline void
  32. xfs_rmap_ino_bmbt_owner(
  33. struct xfs_owner_info *oi,
  34. xfs_ino_t ino,
  35. int whichfork)
  36. {
  37. oi->oi_owner = ino;
  38. oi->oi_offset = 0;
  39. oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
  40. if (whichfork == XFS_ATTR_FORK)
  41. oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  42. }
  43. static inline void
  44. xfs_rmap_ino_owner(
  45. struct xfs_owner_info *oi,
  46. xfs_ino_t ino,
  47. int whichfork,
  48. xfs_fileoff_t offset)
  49. {
  50. oi->oi_owner = ino;
  51. oi->oi_offset = offset;
  52. oi->oi_flags = 0;
  53. if (whichfork == XFS_ATTR_FORK)
  54. oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  55. }
  56. static inline void
  57. xfs_rmap_skip_owner_update(
  58. struct xfs_owner_info *oi)
  59. {
  60. xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_NULL);
  61. }
  62. static inline bool
  63. xfs_rmap_should_skip_owner_update(
  64. struct xfs_owner_info *oi)
  65. {
  66. return oi->oi_owner == XFS_RMAP_OWN_NULL;
  67. }
  68. static inline void
  69. xfs_rmap_any_owner_update(
  70. struct xfs_owner_info *oi)
  71. {
  72. xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_UNKNOWN);
  73. }
  74. /* Reverse mapping functions. */
  75. struct xfs_buf;
  76. static inline __u64
  77. xfs_rmap_irec_offset_pack(
  78. const struct xfs_rmap_irec *irec)
  79. {
  80. __u64 x;
  81. x = XFS_RMAP_OFF(irec->rm_offset);
  82. if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
  83. x |= XFS_RMAP_OFF_ATTR_FORK;
  84. if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
  85. x |= XFS_RMAP_OFF_BMBT_BLOCK;
  86. if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
  87. x |= XFS_RMAP_OFF_UNWRITTEN;
  88. return x;
  89. }
  90. static inline int
  91. xfs_rmap_irec_offset_unpack(
  92. __u64 offset,
  93. struct xfs_rmap_irec *irec)
  94. {
  95. if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
  96. return -EFSCORRUPTED;
  97. irec->rm_offset = XFS_RMAP_OFF(offset);
  98. if (offset & XFS_RMAP_OFF_ATTR_FORK)
  99. irec->rm_flags |= XFS_RMAP_ATTR_FORK;
  100. if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
  101. irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
  102. if (offset & XFS_RMAP_OFF_UNWRITTEN)
  103. irec->rm_flags |= XFS_RMAP_UNWRITTEN;
  104. return 0;
  105. }
  106. static inline void
  107. xfs_owner_info_unpack(
  108. struct xfs_owner_info *oinfo,
  109. uint64_t *owner,
  110. uint64_t *offset,
  111. unsigned int *flags)
  112. {
  113. unsigned int r = 0;
  114. *owner = oinfo->oi_owner;
  115. *offset = oinfo->oi_offset;
  116. if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
  117. r |= XFS_RMAP_ATTR_FORK;
  118. if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
  119. r |= XFS_RMAP_BMBT_BLOCK;
  120. *flags = r;
  121. }
  122. static inline void
  123. xfs_owner_info_pack(
  124. struct xfs_owner_info *oinfo,
  125. uint64_t owner,
  126. uint64_t offset,
  127. unsigned int flags)
  128. {
  129. oinfo->oi_owner = owner;
  130. oinfo->oi_offset = XFS_RMAP_OFF(offset);
  131. oinfo->oi_flags = 0;
  132. if (flags & XFS_RMAP_ATTR_FORK)
  133. oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  134. if (flags & XFS_RMAP_BMBT_BLOCK)
  135. oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
  136. }
  137. int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
  138. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  139. struct xfs_owner_info *oinfo);
  140. int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
  141. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  142. struct xfs_owner_info *oinfo);
  143. int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  144. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  145. unsigned int flags, int *stat);
  146. int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  147. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  148. unsigned int flags, int *stat);
  149. int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
  150. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  151. unsigned int flags);
  152. int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
  153. int *stat);
  154. typedef int (*xfs_rmap_query_range_fn)(
  155. struct xfs_btree_cur *cur,
  156. struct xfs_rmap_irec *rec,
  157. void *priv);
  158. int xfs_rmap_query_range(struct xfs_btree_cur *cur,
  159. struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
  160. xfs_rmap_query_range_fn fn, void *priv);
  161. int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
  162. void *priv);
  163. enum xfs_rmap_intent_type {
  164. XFS_RMAP_MAP,
  165. XFS_RMAP_MAP_SHARED,
  166. XFS_RMAP_UNMAP,
  167. XFS_RMAP_UNMAP_SHARED,
  168. XFS_RMAP_CONVERT,
  169. XFS_RMAP_CONVERT_SHARED,
  170. XFS_RMAP_ALLOC,
  171. XFS_RMAP_FREE,
  172. };
  173. struct xfs_rmap_intent {
  174. struct list_head ri_list;
  175. enum xfs_rmap_intent_type ri_type;
  176. uint64_t ri_owner;
  177. int ri_whichfork;
  178. struct xfs_bmbt_irec ri_bmap;
  179. };
  180. /* functions for updating the rmapbt based on bmbt map/unmap operations */
  181. int xfs_rmap_map_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  182. struct xfs_inode *ip, int whichfork,
  183. struct xfs_bmbt_irec *imap);
  184. int xfs_rmap_unmap_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  185. struct xfs_inode *ip, int whichfork,
  186. struct xfs_bmbt_irec *imap);
  187. int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  188. struct xfs_inode *ip, int whichfork,
  189. struct xfs_bmbt_irec *imap);
  190. int xfs_rmap_alloc_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  191. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  192. uint64_t owner);
  193. int xfs_rmap_free_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  194. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  195. uint64_t owner);
  196. void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
  197. struct xfs_btree_cur *rcur, int error);
  198. int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
  199. uint64_t owner, int whichfork, xfs_fileoff_t startoff,
  200. xfs_fsblock_t startblock, xfs_filblks_t blockcount,
  201. xfs_exntst_t state, struct xfs_btree_cur **pcur);
  202. int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  203. uint64_t owner, uint64_t offset, unsigned int flags,
  204. struct xfs_rmap_irec *irec, int *stat);
  205. int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  206. uint64_t owner, uint64_t offset, unsigned int flags,
  207. struct xfs_rmap_irec *irec, int *stat);
  208. int xfs_rmap_compare(const struct xfs_rmap_irec *a,
  209. const struct xfs_rmap_irec *b);
  210. union xfs_btree_rec;
  211. int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
  212. struct xfs_rmap_irec *irec);
  213. int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  214. xfs_extlen_t len, bool *exists);
  215. int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  216. xfs_extlen_t len, struct xfs_owner_info *oinfo,
  217. bool *has_rmap);
  218. #endif /* __XFS_RMAP_H__ */