]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/xfs_rmap.h
xfsprogs: Release v4.18.0
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_rmap.h
CommitLineData
37b3b4d6 1// SPDX-License-Identifier: GPL-2.0+
85aec44f
DW
2/*
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
85aec44f 4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
85aec44f
DW
5 */
6#ifndef __XFS_RMAP_H__
7#define __XFS_RMAP_H__
8
9static inline void
10xfs_rmap_ag_owner(
11 struct xfs_owner_info *oi,
12 uint64_t owner)
13{
14 oi->oi_owner = owner;
15 oi->oi_offset = 0;
16 oi->oi_flags = 0;
17}
18
19static inline void
20xfs_rmap_ino_bmbt_owner(
21 struct xfs_owner_info *oi,
22 xfs_ino_t ino,
23 int whichfork)
24{
25 oi->oi_owner = ino;
26 oi->oi_offset = 0;
27 oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
28 if (whichfork == XFS_ATTR_FORK)
29 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
30}
31
32static inline void
33xfs_rmap_ino_owner(
34 struct xfs_owner_info *oi,
35 xfs_ino_t ino,
36 int whichfork,
37 xfs_fileoff_t offset)
38{
39 oi->oi_owner = ino;
40 oi->oi_offset = offset;
41 oi->oi_flags = 0;
42 if (whichfork == XFS_ATTR_FORK)
43 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
44}
45
46static inline void
47xfs_rmap_skip_owner_update(
48 struct xfs_owner_info *oi)
49{
3ee858aa
DW
50 xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_NULL);
51}
52
53static inline bool
54xfs_rmap_should_skip_owner_update(
55 struct xfs_owner_info *oi)
56{
57 return oi->oi_owner == XFS_RMAP_OWN_NULL;
58}
59
60static inline void
61xfs_rmap_any_owner_update(
62 struct xfs_owner_info *oi)
63{
64 xfs_rmap_ag_owner(oi, XFS_RMAP_OWN_UNKNOWN);
85aec44f
DW
65}
66
631ac87a
DW
67/* Reverse mapping functions. */
68
69struct xfs_buf;
70
b3a96b46
DW
71static inline __u64
72xfs_rmap_irec_offset_pack(
73 const struct xfs_rmap_irec *irec)
74{
75 __u64 x;
76
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;
84 return x;
85}
86
87static inline int
88xfs_rmap_irec_offset_unpack(
89 __u64 offset,
90 struct xfs_rmap_irec *irec)
91{
92 if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
93 return -EFSCORRUPTED;
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;
101 return 0;
102}
103
104static inline void
105xfs_owner_info_unpack(
106 struct xfs_owner_info *oinfo,
107 uint64_t *owner,
108 uint64_t *offset,
109 unsigned int *flags)
110{
111 unsigned int r = 0;
112
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;
119 *flags = r;
120}
121
122static inline void
123xfs_owner_info_pack(
124 struct xfs_owner_info *oinfo,
125 uint64_t owner,
126 uint64_t offset,
127 unsigned int flags)
128{
129 oinfo->oi_owner = owner;
130 oinfo->oi_offset = XFS_RMAP_OFF(offset);
131 oinfo->oi_flags = 0;
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;
136}
137
631ac87a
DW
138int 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);
141int 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);
144
936ca687
DW
145int 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);
148int 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);
b26675c4
DW
151int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
152 xfs_extlen_t len, uint64_t owner, uint64_t offset,
153 unsigned int flags);
936ca687
DW
154int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
155 int *stat);
156
890e1174
DW
157typedef int (*xfs_rmap_query_range_fn)(
158 struct xfs_btree_cur *cur,
159 struct xfs_rmap_irec *rec,
160 void *priv);
161
162int 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);
7e05e856
DW
165int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
166 void *priv);
890e1174 167
e2d7f10f
DW
168enum xfs_rmap_intent_type {
169 XFS_RMAP_MAP,
170 XFS_RMAP_MAP_SHARED,
171 XFS_RMAP_UNMAP,
172 XFS_RMAP_UNMAP_SHARED,
173 XFS_RMAP_CONVERT,
174 XFS_RMAP_CONVERT_SHARED,
175 XFS_RMAP_ALLOC,
176 XFS_RMAP_FREE,
177};
178
179struct xfs_rmap_intent {
180 struct list_head ri_list;
181 enum xfs_rmap_intent_type ri_type;
4a492e72 182 uint64_t ri_owner;
e2d7f10f
DW
183 int ri_whichfork;
184 struct xfs_bmbt_irec ri_bmap;
185};
186
d7f80320
DW
187/* functions for updating the rmapbt based on bmbt map/unmap operations */
188int xfs_rmap_map_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
189 struct xfs_inode *ip, int whichfork,
190 struct xfs_bmbt_irec *imap);
191int xfs_rmap_unmap_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
192 struct xfs_inode *ip, int whichfork,
193 struct xfs_bmbt_irec *imap);
194int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
195 struct xfs_inode *ip, int whichfork,
196 struct xfs_bmbt_irec *imap);
197int xfs_rmap_alloc_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
198 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
4a492e72 199 uint64_t owner);
d7f80320
DW
200int xfs_rmap_free_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,
201 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
4a492e72 202 uint64_t owner);
d7f80320
DW
203
204void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
205 struct xfs_btree_cur *rcur, int error);
206int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
4a492e72 207 uint64_t owner, int whichfork, xfs_fileoff_t startoff,
d7f80320
DW
208 xfs_fsblock_t startblock, xfs_filblks_t blockcount,
209 xfs_exntst_t state, struct xfs_btree_cur **pcur);
210
6c6bdf6f
DW
211int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
212 uint64_t owner, uint64_t offset, unsigned int flags,
213 struct xfs_rmap_irec *irec, int *stat);
214int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
215 uint64_t owner, uint64_t offset, unsigned int flags,
216 struct xfs_rmap_irec *irec, int *stat);
9282c506
DW
217int xfs_rmap_compare(const struct xfs_rmap_irec *a,
218 const struct xfs_rmap_irec *b);
50bb67d6
DW
219union xfs_btree_rec;
220int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
221 struct xfs_rmap_irec *irec);
556c739d
DW
222int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
223 xfs_extlen_t len, bool *exists);
224int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
225 xfs_extlen_t len, struct xfs_owner_info *oinfo,
226 bool *has_rmap);
d264e392
DW
227int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
228 xfs_extlen_t len, struct xfs_owner_info *oinfo,
229 bool *has_rmap);
230int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
6c6bdf6f 231
85aec44f 232#endif /* __XFS_RMAP_H__ */