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
);
71 if (offset
& XFS_RMAP_OFF_ATTR_FORK
)
72 irec
->rm_flags
|= XFS_RMAP_ATTR_FORK
;
73 if (offset
& XFS_RMAP_OFF_BMBT_BLOCK
)
74 irec
->rm_flags
|= XFS_RMAP_BMBT_BLOCK
;
75 if (offset
& XFS_RMAP_OFF_UNWRITTEN
)
76 irec
->rm_flags
|= XFS_RMAP_UNWRITTEN
;
81 xfs_owner_info_unpack(
82 const struct xfs_owner_info
*oinfo
,
89 *owner
= oinfo
->oi_owner
;
90 *offset
= oinfo
->oi_offset
;
91 if (oinfo
->oi_flags
& XFS_OWNER_INFO_ATTR_FORK
)
92 r
|= XFS_RMAP_ATTR_FORK
;
93 if (oinfo
->oi_flags
& XFS_OWNER_INFO_BMBT_BLOCK
)
94 r
|= XFS_RMAP_BMBT_BLOCK
;
100 struct xfs_owner_info
*oinfo
,
105 oinfo
->oi_owner
= owner
;
106 oinfo
->oi_offset
= XFS_RMAP_OFF(offset
);
108 if (flags
& XFS_RMAP_ATTR_FORK
)
109 oinfo
->oi_flags
|= XFS_OWNER_INFO_ATTR_FORK
;
110 if (flags
& XFS_RMAP_BMBT_BLOCK
)
111 oinfo
->oi_flags
|= XFS_OWNER_INFO_BMBT_BLOCK
;
114 int xfs_rmap_alloc(struct xfs_trans
*tp
, struct xfs_buf
*agbp
,
115 xfs_agnumber_t agno
, xfs_agblock_t bno
, xfs_extlen_t len
,
116 const struct xfs_owner_info
*oinfo
);
117 int xfs_rmap_free(struct xfs_trans
*tp
, struct xfs_buf
*agbp
,
118 xfs_agnumber_t agno
, xfs_agblock_t bno
, xfs_extlen_t len
,
119 const struct xfs_owner_info
*oinfo
);
121 int xfs_rmap_lookup_le(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
122 xfs_extlen_t len
, uint64_t owner
, uint64_t offset
,
123 unsigned int flags
, int *stat
);
124 int xfs_rmap_lookup_eq(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
125 xfs_extlen_t len
, uint64_t owner
, uint64_t offset
,
126 unsigned int flags
, int *stat
);
127 int xfs_rmap_insert(struct xfs_btree_cur
*rcur
, xfs_agblock_t agbno
,
128 xfs_extlen_t len
, uint64_t owner
, uint64_t offset
,
130 int xfs_rmap_get_rec(struct xfs_btree_cur
*cur
, struct xfs_rmap_irec
*irec
,
133 typedef int (*xfs_rmap_query_range_fn
)(
134 struct xfs_btree_cur
*cur
,
135 struct xfs_rmap_irec
*rec
,
138 int xfs_rmap_query_range(struct xfs_btree_cur
*cur
,
139 struct xfs_rmap_irec
*low_rec
, struct xfs_rmap_irec
*high_rec
,
140 xfs_rmap_query_range_fn fn
, void *priv
);
141 int xfs_rmap_query_all(struct xfs_btree_cur
*cur
, xfs_rmap_query_range_fn fn
,
144 enum xfs_rmap_intent_type
{
148 XFS_RMAP_UNMAP_SHARED
,
150 XFS_RMAP_CONVERT_SHARED
,
155 struct xfs_rmap_intent
{
156 struct list_head ri_list
;
157 enum xfs_rmap_intent_type ri_type
;
160 struct xfs_bmbt_irec ri_bmap
;
163 /* functions for updating the rmapbt based on bmbt map/unmap operations */
164 int xfs_rmap_map_extent(struct xfs_trans
*tp
, struct xfs_inode
*ip
,
165 int whichfork
, struct xfs_bmbt_irec
*imap
);
166 int xfs_rmap_unmap_extent(struct xfs_trans
*tp
, struct xfs_inode
*ip
,
167 int whichfork
, struct xfs_bmbt_irec
*imap
);
168 int xfs_rmap_convert_extent(struct xfs_mount
*mp
, struct xfs_trans
*tp
,
169 struct xfs_inode
*ip
, int whichfork
,
170 struct xfs_bmbt_irec
*imap
);
171 int xfs_rmap_alloc_extent(struct xfs_trans
*tp
, xfs_agnumber_t agno
,
172 xfs_agblock_t bno
, xfs_extlen_t len
, uint64_t owner
);
173 int xfs_rmap_free_extent(struct xfs_trans
*tp
, xfs_agnumber_t agno
,
174 xfs_agblock_t bno
, xfs_extlen_t len
, uint64_t owner
);
176 void xfs_rmap_finish_one_cleanup(struct xfs_trans
*tp
,
177 struct xfs_btree_cur
*rcur
, int error
);
178 int xfs_rmap_finish_one(struct xfs_trans
*tp
, enum xfs_rmap_intent_type type
,
179 uint64_t owner
, int whichfork
, xfs_fileoff_t startoff
,
180 xfs_fsblock_t startblock
, xfs_filblks_t blockcount
,
181 xfs_exntst_t state
, struct xfs_btree_cur
**pcur
);
183 int xfs_rmap_find_left_neighbor(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
184 uint64_t owner
, uint64_t offset
, unsigned int flags
,
185 struct xfs_rmap_irec
*irec
, int *stat
);
186 int xfs_rmap_lookup_le_range(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
187 uint64_t owner
, uint64_t offset
, unsigned int flags
,
188 struct xfs_rmap_irec
*irec
, int *stat
);
189 int xfs_rmap_compare(const struct xfs_rmap_irec
*a
,
190 const struct xfs_rmap_irec
*b
);
192 int xfs_rmap_btrec_to_irec(union xfs_btree_rec
*rec
,
193 struct xfs_rmap_irec
*irec
);
194 int xfs_rmap_has_record(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
195 xfs_extlen_t len
, bool *exists
);
196 int xfs_rmap_record_exists(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
197 xfs_extlen_t len
, const struct xfs_owner_info
*oinfo
,
199 int xfs_rmap_has_other_keys(struct xfs_btree_cur
*cur
, xfs_agblock_t bno
,
200 xfs_extlen_t len
, const struct xfs_owner_info
*oinfo
,
202 int xfs_rmap_map_raw(struct xfs_btree_cur
*cur
, struct xfs_rmap_irec
*rmap
);
204 extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE
;
205 extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER
;
206 extern const struct xfs_owner_info XFS_RMAP_OINFO_FS
;
207 extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG
;
208 extern const struct xfs_owner_info XFS_RMAP_OINFO_AG
;
209 extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT
;
210 extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES
;
211 extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC
;
212 extern const struct xfs_owner_info XFS_RMAP_OINFO_COW
;
214 #endif /* __XFS_RMAP_H__ */