1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
13 xfs_rmap_ino_bmbt_owner(
14 struct xfs_owner_info *oi,
20 oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
21 if (whichfork == XFS_ATTR_FORK)
22 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
27 struct xfs_owner_info *oi,
33 oi->oi_offset = offset;
35 if (whichfork == XFS_ATTR_FORK)
36 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
40 xfs_rmap_should_skip_owner_update(
41 const struct xfs_owner_info *oi)
43 return oi->oi_owner == XFS_RMAP_OWN_NULL;
46 /* Reverse mapping functions. */
51 xfs_rmap_irec_offset_pack(
52 const struct xfs_rmap_irec *irec)
56 x = XFS_RMAP_OFF(irec->rm_offset);
57 if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
58 x |= XFS_RMAP_OFF_ATTR_FORK;
59 if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
60 x |= XFS_RMAP_OFF_BMBT_BLOCK;
61 if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
62 x |= XFS_RMAP_OFF_UNWRITTEN;
66 static inline xfs_failaddr_t
67 xfs_rmap_irec_offset_unpack(
69 struct xfs_rmap_irec *irec)
71 if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
72 return __this_address;
74 irec->rm_offset = XFS_RMAP_OFF(offset);
76 if (offset & XFS_RMAP_OFF_ATTR_FORK)
77 irec->rm_flags |= XFS_RMAP_ATTR_FORK;
78 if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
79 irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
80 if (offset & XFS_RMAP_OFF_UNWRITTEN)
81 irec->rm_flags |= XFS_RMAP_UNWRITTEN;
86 xfs_owner_info_unpack(
87 const struct xfs_owner_info *oinfo,
94 *owner = oinfo->oi_owner;
95 *offset = oinfo->oi_offset;
96 if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
97 r |= XFS_RMAP_ATTR_FORK;
98 if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
99 r |= XFS_RMAP_BMBT_BLOCK;
105 struct xfs_owner_info *oinfo,
110 oinfo->oi_owner = owner;
111 oinfo->oi_offset = XFS_RMAP_OFF(offset);
113 if (flags & XFS_RMAP_ATTR_FORK)
114 oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
115 if (flags & XFS_RMAP_BMBT_BLOCK)
116 oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
119 int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
120 struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
121 const struct xfs_owner_info *oinfo);
122 int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
123 struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
124 const struct xfs_owner_info *oinfo);
126 int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
127 uint64_t owner, uint64_t offset, unsigned int flags,
128 struct xfs_rmap_irec *irec, int *stat);
129 int xfs_rmap_lookup_eq(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_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
133 xfs_extlen_t len, uint64_t owner, uint64_t offset,
135 int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
138 typedef int (*xfs_rmap_query_range_fn)(
139 struct xfs_btree_cur *cur,
140 const struct xfs_rmap_irec *rec,
143 int xfs_rmap_query_range(struct xfs_btree_cur *cur,
144 const struct xfs_rmap_irec *low_rec,
145 const 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,
150 enum xfs_rmap_intent_type {
154 XFS_RMAP_UNMAP_SHARED,
156 XFS_RMAP_CONVERT_SHARED,
161 #define XFS_RMAP_INTENT_STRINGS \
162 { XFS_RMAP_MAP, "map" }, \
163 { XFS_RMAP_MAP_SHARED, "map_shared" }, \
164 { XFS_RMAP_UNMAP, "unmap" }, \
165 { XFS_RMAP_UNMAP_SHARED, "unmap_shared" }, \
166 { XFS_RMAP_CONVERT, "cvt" }, \
167 { XFS_RMAP_CONVERT_SHARED, "cvt_shared" }, \
168 { XFS_RMAP_ALLOC, "alloc" }, \
169 { XFS_RMAP_FREE, "free" }
171 struct xfs_rmap_intent {
172 struct list_head ri_list;
173 enum xfs_rmap_intent_type ri_type;
176 struct xfs_bmbt_irec ri_bmap;
177 struct xfs_group *ri_group;
181 /* functions for updating the rmapbt based on bmbt map/unmap operations */
182 void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
183 int whichfork, struct xfs_bmbt_irec *imap);
184 void xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
185 int whichfork, struct xfs_bmbt_irec *imap);
186 void xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
187 struct xfs_inode *ip, int whichfork,
188 struct xfs_bmbt_irec *imap);
189 void xfs_rmap_alloc_extent(struct xfs_trans *tp, bool isrt, xfs_fsblock_t fsbno,
190 xfs_extlen_t len, uint64_t owner);
191 void xfs_rmap_free_extent(struct xfs_trans *tp, bool isrt, xfs_fsblock_t fsbno,
192 xfs_extlen_t len, uint64_t owner);
194 int xfs_rmap_finish_one(struct xfs_trans *tp, struct xfs_rmap_intent *ri,
195 struct xfs_btree_cur **pcur);
196 int __xfs_rmap_finish_intent(struct xfs_btree_cur *rcur,
197 enum xfs_rmap_intent_type op, xfs_agblock_t bno,
198 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
201 int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
202 uint64_t owner, uint64_t offset, unsigned int flags,
203 struct xfs_rmap_irec *irec, int *stat);
204 int xfs_rmap_compare(const struct xfs_rmap_irec *a,
205 const struct xfs_rmap_irec *b);
207 xfs_failaddr_t xfs_rmap_btrec_to_irec(const union xfs_btree_rec *rec,
208 struct xfs_rmap_irec *irec);
209 xfs_failaddr_t xfs_rmap_check_irec(struct xfs_perag *pag,
210 const struct xfs_rmap_irec *irec);
211 xfs_failaddr_t xfs_rtrmap_check_irec(struct xfs_rtgroup *rtg,
212 const struct xfs_rmap_irec *irec);
214 int xfs_rmap_has_records(struct xfs_btree_cur *cur, xfs_agblock_t bno,
215 xfs_extlen_t len, enum xbtree_recpacking *outcome);
217 struct xfs_rmap_matches {
218 /* Number of owner matches. */
219 unsigned long long matches;
221 /* Number of non-owner matches. */
222 unsigned long long non_owner_matches;
224 /* Number of non-owner matches that conflict with the owner matches. */
225 unsigned long long bad_non_owner_matches;
228 int xfs_rmap_count_owners(struct xfs_btree_cur *cur, xfs_agblock_t bno,
229 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
230 struct xfs_rmap_matches *rmatch);
231 int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
232 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
234 int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
236 extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
237 extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
238 extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
239 extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
240 extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
241 extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
242 extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
243 extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
244 extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
246 extern struct kmem_cache *xfs_rmap_intent_cache;
248 int __init xfs_rmap_intent_init_cache(void);
249 void xfs_rmap_intent_destroy_cache(void);
252 * Parameters for tracking reverse mapping changes. The hook function arg
253 * parameter is enum xfs_rmap_intent_type, and the rest is below.
255 struct xfs_rmap_update_params {
256 xfs_agblock_t startblock;
257 xfs_extlen_t blockcount;
258 struct xfs_owner_info oinfo;
262 #ifdef CONFIG_XFS_LIVE_HOOKS
264 struct xfs_rmap_hook {
265 struct xfs_hook rmap_hook;
268 void xfs_rmap_hook_disable(void);
269 void xfs_rmap_hook_enable(void);
271 int xfs_rmap_hook_add(struct xfs_group *xg, struct xfs_rmap_hook *hook);
272 void xfs_rmap_hook_del(struct xfs_group *xg, struct xfs_rmap_hook *hook);
273 void xfs_rmap_hook_setup(struct xfs_rmap_hook *hook, notifier_fn_t mod_fn);
276 #endif /* __XFS_RMAP_H__ */