1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
11 struct xfs_owner_info
*oi
,
20 xfs_rmap_ino_bmbt_owner(
21 struct xfs_owner_info
*oi
,
27 oi
->oi_flags
= XFS_OWNER_INFO_BMBT_BLOCK
;
28 if (whichfork
== XFS_ATTR_FORK
)
29 oi
->oi_flags
|= XFS_OWNER_INFO_ATTR_FORK
;
34 struct xfs_owner_info
*oi
,
40 oi
->oi_offset
= offset
;
42 if (whichfork
== XFS_ATTR_FORK
)
43 oi
->oi_flags
|= XFS_OWNER_INFO_ATTR_FORK
;
47 xfs_rmap_skip_owner_update(
48 struct xfs_owner_info
*oi
)
50 xfs_rmap_ag_owner(oi
, XFS_RMAP_OWN_NULL
);
54 xfs_rmap_should_skip_owner_update(
55 struct xfs_owner_info
*oi
)
57 return oi
->oi_owner
== XFS_RMAP_OWN_NULL
;
61 xfs_rmap_any_owner_update(
62 struct xfs_owner_info
*oi
)
64 xfs_rmap_ag_owner(oi
, XFS_RMAP_OWN_UNKNOWN
);
67 /* Reverse mapping functions. */
72 xfs_rmap_irec_offset_pack(
73 const struct xfs_rmap_irec
*irec
)
77 x
= XFS_RMAP_OFF(irec
->rm_offset
);
78 if (irec
->rm_flags
& XFS_RMAP_ATTR_FORK
)
79 x
|= XFS_RMAP_OFF_ATTR_FORK
;
80 if (irec
->rm_flags
& XFS_RMAP_BMBT_BLOCK
)
81 x
|= XFS_RMAP_OFF_BMBT_BLOCK
;
82 if (irec
->rm_flags
& XFS_RMAP_UNWRITTEN
)
83 x
|= XFS_RMAP_OFF_UNWRITTEN
;
88 xfs_rmap_irec_offset_unpack(
90 struct xfs_rmap_irec
*irec
)
92 if (offset
& ~(XFS_RMAP_OFF_MASK
| XFS_RMAP_OFF_FLAGS
))
94 irec
->rm_offset
= XFS_RMAP_OFF(offset
);
95 if (offset
& XFS_RMAP_OFF_ATTR_FORK
)
96 irec
->rm_flags
|= XFS_RMAP_ATTR_FORK
;
97 if (offset
& XFS_RMAP_OFF_BMBT_BLOCK
)
98 irec
->rm_flags
|= XFS_RMAP_BMBT_BLOCK
;
99 if (offset
& XFS_RMAP_OFF_UNWRITTEN
)
100 irec
->rm_flags
|= XFS_RMAP_UNWRITTEN
;
105 xfs_owner_info_unpack(
106 struct xfs_owner_info
*oinfo
,
113 *owner
= oinfo
->oi_owner
;
114 *offset
= oinfo
->oi_offset
;
115 if (oinfo
->oi_flags
& XFS_OWNER_INFO_ATTR_FORK
)
116 r
|= XFS_RMAP_ATTR_FORK
;
117 if (oinfo
->oi_flags
& XFS_OWNER_INFO_BMBT_BLOCK
)
118 r
|= XFS_RMAP_BMBT_BLOCK
;
124 struct xfs_owner_info
*oinfo
,
129 oinfo
->oi_owner
= owner
;
130 oinfo
->oi_offset
= XFS_RMAP_OFF(offset
);
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
;
138 int xfs_rmap_alloc(struct xfs_trans
*tp
, struct xfs_buf
*agbp
,
139 xfs_agnumber_t agno
, xfs_agblock_t bno
, xfs_extlen_t len
,
140 struct xfs_owner_info
*oinfo
);
141 int xfs_rmap_free(struct xfs_trans
*tp
, struct xfs_buf
*agbp
,
142 xfs_agnumber_t agno
, xfs_agblock_t bno
, xfs_extlen_t len
,
143 struct xfs_owner_info
*oinfo
);
145 int xfs_rmap_lookup_le(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
146 xfs_extlen_t len
, uint64_t owner
, uint64_t offset
,
147 unsigned int flags
, int *stat
);
148 int xfs_rmap_lookup_eq(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
149 xfs_extlen_t len
, uint64_t owner
, uint64_t offset
,
150 unsigned int flags
, int *stat
);
151 int xfs_rmap_insert(struct xfs_btree_cur
*rcur
, xfs_agblock_t agbno
,
152 xfs_extlen_t len
, uint64_t owner
, uint64_t offset
,
154 int xfs_rmap_get_rec(struct xfs_btree_cur
*cur
, struct xfs_rmap_irec
*irec
,
157 typedef int (*xfs_rmap_query_range_fn
)(
158 struct xfs_btree_cur
*cur
,
159 struct xfs_rmap_irec
*rec
,
162 int xfs_rmap_query_range(struct xfs_btree_cur
*cur
,
163 struct xfs_rmap_irec
*low_rec
, struct xfs_rmap_irec
*high_rec
,
164 xfs_rmap_query_range_fn fn
, void *priv
);
165 int xfs_rmap_query_all(struct xfs_btree_cur
*cur
, xfs_rmap_query_range_fn fn
,
168 enum xfs_rmap_intent_type
{
172 XFS_RMAP_UNMAP_SHARED
,
174 XFS_RMAP_CONVERT_SHARED
,
179 struct xfs_rmap_intent
{
180 struct list_head ri_list
;
181 enum xfs_rmap_intent_type ri_type
;
184 struct xfs_bmbt_irec ri_bmap
;
187 /* functions for updating the rmapbt based on bmbt map/unmap operations */
188 int xfs_rmap_map_extent(struct xfs_trans
*tp
, struct xfs_inode
*ip
,
189 int whichfork
, struct xfs_bmbt_irec
*imap
);
190 int xfs_rmap_unmap_extent(struct xfs_trans
*tp
, struct xfs_inode
*ip
,
191 int whichfork
, struct xfs_bmbt_irec
*imap
);
192 int xfs_rmap_convert_extent(struct xfs_mount
*mp
, struct xfs_trans
*tp
,
193 struct xfs_inode
*ip
, int whichfork
,
194 struct xfs_bmbt_irec
*imap
);
195 int xfs_rmap_alloc_extent(struct xfs_trans
*tp
, xfs_agnumber_t agno
,
196 xfs_agblock_t bno
, xfs_extlen_t len
, uint64_t owner
);
197 int xfs_rmap_free_extent(struct xfs_trans
*tp
, xfs_agnumber_t agno
,
198 xfs_agblock_t bno
, xfs_extlen_t len
, uint64_t owner
);
200 void xfs_rmap_finish_one_cleanup(struct xfs_trans
*tp
,
201 struct xfs_btree_cur
*rcur
, int error
);
202 int xfs_rmap_finish_one(struct xfs_trans
*tp
, enum xfs_rmap_intent_type type
,
203 uint64_t owner
, int whichfork
, xfs_fileoff_t startoff
,
204 xfs_fsblock_t startblock
, xfs_filblks_t blockcount
,
205 xfs_exntst_t state
, struct xfs_btree_cur
**pcur
);
207 int xfs_rmap_find_left_neighbor(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
208 uint64_t owner
, uint64_t offset
, unsigned int flags
,
209 struct xfs_rmap_irec
*irec
, int *stat
);
210 int xfs_rmap_lookup_le_range(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
211 uint64_t owner
, uint64_t offset
, unsigned int flags
,
212 struct xfs_rmap_irec
*irec
, int *stat
);
213 int xfs_rmap_compare(const struct xfs_rmap_irec
*a
,
214 const struct xfs_rmap_irec
*b
);
216 int xfs_rmap_btrec_to_irec(union xfs_btree_rec
*rec
,
217 struct xfs_rmap_irec
*irec
);
218 int xfs_rmap_has_record(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
219 xfs_extlen_t len
, bool *exists
);
220 int xfs_rmap_record_exists(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
221 xfs_extlen_t len
, struct xfs_owner_info
*oinfo
,
223 int xfs_rmap_has_other_keys(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
224 xfs_extlen_t len
, struct xfs_owner_info
*oinfo
,
226 int xfs_rmap_map_raw(struct xfs_btree_cur
*cur
, struct xfs_rmap_irec
*rmap
);
228 #endif /* __XFS_RMAP_H__ */