1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
10 xfs_rmap_ino_bmbt_owner(
11 struct xfs_owner_info *oi,
17 oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
18 if (whichfork == XFS_ATTR_FORK)
19 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
24 struct xfs_owner_info *oi,
30 oi->oi_offset = offset;
32 if (whichfork == XFS_ATTR_FORK)
33 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
37 xfs_rmap_should_skip_owner_update(
38 const struct xfs_owner_info *oi)
40 return oi->oi_owner == XFS_RMAP_OWN_NULL;
43 /* Reverse mapping functions. */
48 xfs_rmap_irec_offset_pack(
49 const struct xfs_rmap_irec *irec)
53 x = XFS_RMAP_OFF(irec->rm_offset);
54 if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
55 x |= XFS_RMAP_OFF_ATTR_FORK;
56 if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
57 x |= XFS_RMAP_OFF_BMBT_BLOCK;
58 if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
59 x |= XFS_RMAP_OFF_UNWRITTEN;
64 xfs_rmap_irec_offset_unpack(
66 struct xfs_rmap_irec *irec)
68 if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
70 irec->rm_offset = XFS_RMAP_OFF(offset);
72 if (offset & XFS_RMAP_OFF_ATTR_FORK)
73 irec->rm_flags |= XFS_RMAP_ATTR_FORK;
74 if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
75 irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
76 if (offset & XFS_RMAP_OFF_UNWRITTEN)
77 irec->rm_flags |= XFS_RMAP_UNWRITTEN;
82 xfs_owner_info_unpack(
83 const struct xfs_owner_info *oinfo,
90 *owner = oinfo->oi_owner;
91 *offset = oinfo->oi_offset;
92 if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
93 r |= XFS_RMAP_ATTR_FORK;
94 if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
95 r |= XFS_RMAP_BMBT_BLOCK;
101 struct xfs_owner_info *oinfo,
106 oinfo->oi_owner = owner;
107 oinfo->oi_offset = XFS_RMAP_OFF(offset);
109 if (flags & XFS_RMAP_ATTR_FORK)
110 oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
111 if (flags & XFS_RMAP_BMBT_BLOCK)
112 oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
115 int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
116 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
117 const struct xfs_owner_info *oinfo);
118 int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
119 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
120 const struct xfs_owner_info *oinfo);
122 int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
123 xfs_extlen_t len, uint64_t owner, uint64_t offset,
124 unsigned int flags, int *stat);
125 int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
126 xfs_extlen_t len, uint64_t owner, uint64_t offset,
127 unsigned int flags, int *stat);
128 int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
129 xfs_extlen_t len, uint64_t owner, uint64_t offset,
131 int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
134 typedef int (*xfs_rmap_query_range_fn)(
135 struct xfs_btree_cur *cur,
136 struct xfs_rmap_irec *rec,
139 int xfs_rmap_query_range(struct xfs_btree_cur *cur,
140 struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
141 xfs_rmap_query_range_fn fn, void *priv);
142 int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
145 enum xfs_rmap_intent_type {
149 XFS_RMAP_UNMAP_SHARED,
151 XFS_RMAP_CONVERT_SHARED,
156 struct xfs_rmap_intent {
157 struct list_head ri_list;
158 enum xfs_rmap_intent_type ri_type;
161 struct xfs_bmbt_irec ri_bmap;
164 /* functions for updating the rmapbt based on bmbt map/unmap operations */
165 void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
166 int whichfork, struct xfs_bmbt_irec *imap);
167 void xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
168 int whichfork, struct xfs_bmbt_irec *imap);
169 void xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
170 struct xfs_inode *ip, int whichfork,
171 struct xfs_bmbt_irec *imap);
172 void xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
173 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
174 void xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
175 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
177 void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
178 struct xfs_btree_cur *rcur, int error);
179 int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
180 uint64_t owner, int whichfork, xfs_fileoff_t startoff,
181 xfs_fsblock_t startblock, xfs_filblks_t blockcount,
182 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);
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, const struct xfs_owner_info *oinfo,
200 int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
201 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
203 int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
205 extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
206 extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
207 extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
208 extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
209 extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
210 extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
211 extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
212 extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
213 extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
215 #endif /* __XFS_RMAP_H__ */