]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/xfs_rmap.h
libxfs: refactor manage_zones()
[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
85aec44f
DW
9static inline void
10xfs_rmap_ino_bmbt_owner(
11 struct xfs_owner_info *oi,
12 xfs_ino_t ino,
13 int whichfork)
14{
15 oi->oi_owner = ino;
16 oi->oi_offset = 0;
17 oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
18 if (whichfork == XFS_ATTR_FORK)
19 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
20}
21
22static inline void
23xfs_rmap_ino_owner(
24 struct xfs_owner_info *oi,
25 xfs_ino_t ino,
26 int whichfork,
27 xfs_fileoff_t offset)
28{
29 oi->oi_owner = ino;
30 oi->oi_offset = offset;
31 oi->oi_flags = 0;
32 if (whichfork == XFS_ATTR_FORK)
33 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
34}
35
3ee858aa
DW
36static inline bool
37xfs_rmap_should_skip_owner_update(
5837e73b 38 const struct xfs_owner_info *oi)
3ee858aa
DW
39{
40 return oi->oi_owner == XFS_RMAP_OWN_NULL;
41}
42
631ac87a
DW
43/* Reverse mapping functions. */
44
45struct xfs_buf;
46
b3a96b46
DW
47static inline __u64
48xfs_rmap_irec_offset_pack(
49 const struct xfs_rmap_irec *irec)
50{
51 __u64 x;
52
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;
60 return x;
61}
62
63static inline int
64xfs_rmap_irec_offset_unpack(
65 __u64 offset,
66 struct xfs_rmap_irec *irec)
67{
68 if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
69 return -EFSCORRUPTED;
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;
77 return 0;
78}
79
80static inline void
81xfs_owner_info_unpack(
5837e73b
DW
82 const struct xfs_owner_info *oinfo,
83 uint64_t *owner,
84 uint64_t *offset,
85 unsigned int *flags)
b3a96b46 86{
5837e73b 87 unsigned int r = 0;
b3a96b46
DW
88
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;
95 *flags = r;
96}
97
98static inline void
99xfs_owner_info_pack(
100 struct xfs_owner_info *oinfo,
101 uint64_t owner,
102 uint64_t offset,
103 unsigned int flags)
104{
105 oinfo->oi_owner = owner;
106 oinfo->oi_offset = XFS_RMAP_OFF(offset);
107 oinfo->oi_flags = 0;
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;
112}
113
631ac87a
DW
114int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
115 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
5837e73b 116 const struct xfs_owner_info *oinfo);
631ac87a
DW
117int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
118 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
5837e73b 119 const struct xfs_owner_info *oinfo);
631ac87a 120
936ca687
DW
121int 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);
124int 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);
b26675c4
DW
127int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
128 xfs_extlen_t len, uint64_t owner, uint64_t offset,
129 unsigned int flags);
936ca687
DW
130int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
131 int *stat);
132
890e1174
DW
133typedef int (*xfs_rmap_query_range_fn)(
134 struct xfs_btree_cur *cur,
135 struct xfs_rmap_irec *rec,
136 void *priv);
137
138int 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);
7e05e856
DW
141int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
142 void *priv);
890e1174 143
e2d7f10f
DW
144enum xfs_rmap_intent_type {
145 XFS_RMAP_MAP,
146 XFS_RMAP_MAP_SHARED,
147 XFS_RMAP_UNMAP,
148 XFS_RMAP_UNMAP_SHARED,
149 XFS_RMAP_CONVERT,
150 XFS_RMAP_CONVERT_SHARED,
151 XFS_RMAP_ALLOC,
152 XFS_RMAP_FREE,
153};
154
155struct xfs_rmap_intent {
156 struct list_head ri_list;
157 enum xfs_rmap_intent_type ri_type;
4a492e72 158 uint64_t ri_owner;
e2d7f10f
DW
159 int ri_whichfork;
160 struct xfs_bmbt_irec ri_bmap;
161};
162
d7f80320 163/* functions for updating the rmapbt based on bmbt map/unmap operations */
21375e5d
BF
164int xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
165 int whichfork, struct xfs_bmbt_irec *imap);
166int xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
167 int whichfork, struct xfs_bmbt_irec *imap);
168int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
d7f80320
DW
169 struct xfs_inode *ip, int whichfork,
170 struct xfs_bmbt_irec *imap);
21375e5d
BF
171int xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
172 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
173int xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
174 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
d7f80320
DW
175
176void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
177 struct xfs_btree_cur *rcur, int error);
178int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
4a492e72 179 uint64_t owner, int whichfork, xfs_fileoff_t startoff,
d7f80320
DW
180 xfs_fsblock_t startblock, xfs_filblks_t blockcount,
181 xfs_exntst_t state, struct xfs_btree_cur **pcur);
182
6c6bdf6f
DW
183int 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);
186int 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);
9282c506
DW
189int xfs_rmap_compare(const struct xfs_rmap_irec *a,
190 const struct xfs_rmap_irec *b);
50bb67d6
DW
191union xfs_btree_rec;
192int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
193 struct xfs_rmap_irec *irec);
556c739d
DW
194int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
195 xfs_extlen_t len, bool *exists);
196int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
5837e73b 197 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
556c739d 198 bool *has_rmap);
d264e392 199int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
5837e73b 200 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
d264e392
DW
201 bool *has_rmap);
202int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
6c6bdf6f 203
007347e3
DW
204extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
205extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
206extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
207extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
208extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
209extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
210extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
211extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
212extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
213
85aec44f 214#endif /* __XFS_RMAP_H__ */