xfs_rmap.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. oi->oi_owner = XFS_RMAP_OWN_UNKNOWN;
  61. }
  62. /* Reverse mapping functions. */
  63. struct xfs_buf;
  64. static inline __u64
  65. xfs_rmap_irec_offset_pack(
  66. const struct xfs_rmap_irec *irec)
  67. {
  68. __u64 x;
  69. x = XFS_RMAP_OFF(irec->rm_offset);
  70. if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
  71. x |= XFS_RMAP_OFF_ATTR_FORK;
  72. if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
  73. x |= XFS_RMAP_OFF_BMBT_BLOCK;
  74. if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
  75. x |= XFS_RMAP_OFF_UNWRITTEN;
  76. return x;
  77. }
  78. static inline int
  79. xfs_rmap_irec_offset_unpack(
  80. __u64 offset,
  81. struct xfs_rmap_irec *irec)
  82. {
  83. if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
  84. return -EFSCORRUPTED;
  85. irec->rm_offset = XFS_RMAP_OFF(offset);
  86. if (offset & XFS_RMAP_OFF_ATTR_FORK)
  87. irec->rm_flags |= XFS_RMAP_ATTR_FORK;
  88. if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
  89. irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
  90. if (offset & XFS_RMAP_OFF_UNWRITTEN)
  91. irec->rm_flags |= XFS_RMAP_UNWRITTEN;
  92. return 0;
  93. }
  94. static inline void
  95. xfs_owner_info_unpack(
  96. struct xfs_owner_info *oinfo,
  97. uint64_t *owner,
  98. uint64_t *offset,
  99. unsigned int *flags)
  100. {
  101. unsigned int r = 0;
  102. *owner = oinfo->oi_owner;
  103. *offset = oinfo->oi_offset;
  104. if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
  105. r |= XFS_RMAP_ATTR_FORK;
  106. if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
  107. r |= XFS_RMAP_BMBT_BLOCK;
  108. *flags = r;
  109. }
  110. static inline void
  111. xfs_owner_info_pack(
  112. struct xfs_owner_info *oinfo,
  113. uint64_t owner,
  114. uint64_t offset,
  115. unsigned int flags)
  116. {
  117. oinfo->oi_owner = owner;
  118. oinfo->oi_offset = XFS_RMAP_OFF(offset);
  119. oinfo->oi_flags = 0;
  120. if (flags & XFS_RMAP_ATTR_FORK)
  121. oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
  122. if (flags & XFS_RMAP_BMBT_BLOCK)
  123. oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
  124. }
  125. int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
  126. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  127. struct xfs_owner_info *oinfo);
  128. int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
  129. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  130. struct xfs_owner_info *oinfo);
  131. int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  132. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  133. unsigned int flags, int *stat);
  134. int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  135. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  136. unsigned int flags, int *stat);
  137. int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
  138. xfs_extlen_t len, uint64_t owner, uint64_t offset,
  139. unsigned int flags);
  140. int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
  141. int *stat);
  142. typedef int (*xfs_rmap_query_range_fn)(
  143. struct xfs_btree_cur *cur,
  144. struct xfs_rmap_irec *rec,
  145. void *priv);
  146. int xfs_rmap_query_range(struct xfs_btree_cur *cur,
  147. struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
  148. xfs_rmap_query_range_fn fn, 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_mount *mp, struct xfs_defer_ops *dfops,
  168. struct xfs_inode *ip, int whichfork,
  169. struct xfs_bmbt_irec *imap);
  170. int xfs_rmap_unmap_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  171. struct xfs_inode *ip, int whichfork,
  172. struct xfs_bmbt_irec *imap);
  173. int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  174. struct xfs_inode *ip, int whichfork,
  175. struct xfs_bmbt_irec *imap);
  176. int xfs_rmap_alloc_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  177. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  178. __uint64_t owner);
  179. int xfs_rmap_free_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
  180. xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
  181. __uint64_t owner);
  182. void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
  183. struct xfs_btree_cur *rcur, int error);
  184. int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
  185. __uint64_t owner, int whichfork, xfs_fileoff_t startoff,
  186. xfs_fsblock_t startblock, xfs_filblks_t blockcount,
  187. xfs_exntst_t state, struct xfs_btree_cur **pcur);
  188. int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  189. uint64_t owner, uint64_t offset, unsigned int flags,
  190. struct xfs_rmap_irec *irec, int *stat);
  191. int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  192. uint64_t owner, uint64_t offset, unsigned int flags,
  193. struct xfs_rmap_irec *irec, int *stat);
  194. #endif /* __XFS_RMAP_H__ */