Merge tag 'sound-5.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-2.6-microblaze.git] / fs / xfs / libxfs / xfs_rmap.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  */
6 #ifndef __XFS_RMAP_H__
7 #define __XFS_RMAP_H__
8
9 struct xfs_perag;
10
11 static inline void
12 xfs_rmap_ino_bmbt_owner(
13         struct xfs_owner_info   *oi,
14         xfs_ino_t               ino,
15         int                     whichfork)
16 {
17         oi->oi_owner = ino;
18         oi->oi_offset = 0;
19         oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
20         if (whichfork == XFS_ATTR_FORK)
21                 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
22 }
23
24 static inline void
25 xfs_rmap_ino_owner(
26         struct xfs_owner_info   *oi,
27         xfs_ino_t               ino,
28         int                     whichfork,
29         xfs_fileoff_t           offset)
30 {
31         oi->oi_owner = ino;
32         oi->oi_offset = offset;
33         oi->oi_flags = 0;
34         if (whichfork == XFS_ATTR_FORK)
35                 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
36 }
37
38 static inline bool
39 xfs_rmap_should_skip_owner_update(
40         const struct xfs_owner_info     *oi)
41 {
42         return oi->oi_owner == XFS_RMAP_OWN_NULL;
43 }
44
45 /* Reverse mapping functions. */
46
47 struct xfs_buf;
48
49 static inline __u64
50 xfs_rmap_irec_offset_pack(
51         const struct xfs_rmap_irec      *irec)
52 {
53         __u64                   x;
54
55         x = XFS_RMAP_OFF(irec->rm_offset);
56         if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
57                 x |= XFS_RMAP_OFF_ATTR_FORK;
58         if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
59                 x |= XFS_RMAP_OFF_BMBT_BLOCK;
60         if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
61                 x |= XFS_RMAP_OFF_UNWRITTEN;
62         return x;
63 }
64
65 static inline int
66 xfs_rmap_irec_offset_unpack(
67         __u64                   offset,
68         struct xfs_rmap_irec    *irec)
69 {
70         if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
71                 return -EFSCORRUPTED;
72         irec->rm_offset = XFS_RMAP_OFF(offset);
73         irec->rm_flags = 0;
74         if (offset & XFS_RMAP_OFF_ATTR_FORK)
75                 irec->rm_flags |= XFS_RMAP_ATTR_FORK;
76         if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
77                 irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
78         if (offset & XFS_RMAP_OFF_UNWRITTEN)
79                 irec->rm_flags |= XFS_RMAP_UNWRITTEN;
80         return 0;
81 }
82
83 static inline void
84 xfs_owner_info_unpack(
85         const struct xfs_owner_info     *oinfo,
86         uint64_t                        *owner,
87         uint64_t                        *offset,
88         unsigned int                    *flags)
89 {
90         unsigned int                    r = 0;
91
92         *owner = oinfo->oi_owner;
93         *offset = oinfo->oi_offset;
94         if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
95                 r |= XFS_RMAP_ATTR_FORK;
96         if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
97                 r |= XFS_RMAP_BMBT_BLOCK;
98         *flags = r;
99 }
100
101 static inline void
102 xfs_owner_info_pack(
103         struct xfs_owner_info   *oinfo,
104         uint64_t                owner,
105         uint64_t                offset,
106         unsigned int            flags)
107 {
108         oinfo->oi_owner = owner;
109         oinfo->oi_offset = XFS_RMAP_OFF(offset);
110         oinfo->oi_flags = 0;
111         if (flags & XFS_RMAP_ATTR_FORK)
112                 oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
113         if (flags & XFS_RMAP_BMBT_BLOCK)
114                 oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
115 }
116
117 int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
118                    struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
119                    const struct xfs_owner_info *oinfo);
120 int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
121                   struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
122                   const struct xfs_owner_info *oinfo);
123
124 int xfs_rmap_lookup_le(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_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
128                 xfs_extlen_t len, uint64_t owner, uint64_t offset,
129                 unsigned int flags, int *stat);
130 int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
131                 xfs_extlen_t len, uint64_t owner, uint64_t offset,
132                 unsigned int flags);
133 int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
134                 int *stat);
135
136 typedef int (*xfs_rmap_query_range_fn)(
137         struct xfs_btree_cur    *cur,
138         struct xfs_rmap_irec    *rec,
139         void                    *priv);
140
141 int xfs_rmap_query_range(struct xfs_btree_cur *cur,
142                 struct xfs_rmap_irec *low_rec, struct xfs_rmap_irec *high_rec,
143                 xfs_rmap_query_range_fn fn, void *priv);
144 int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
145                 void *priv);
146
147 enum xfs_rmap_intent_type {
148         XFS_RMAP_MAP,
149         XFS_RMAP_MAP_SHARED,
150         XFS_RMAP_UNMAP,
151         XFS_RMAP_UNMAP_SHARED,
152         XFS_RMAP_CONVERT,
153         XFS_RMAP_CONVERT_SHARED,
154         XFS_RMAP_ALLOC,
155         XFS_RMAP_FREE,
156 };
157
158 struct xfs_rmap_intent {
159         struct list_head                        ri_list;
160         enum xfs_rmap_intent_type               ri_type;
161         uint64_t                                ri_owner;
162         int                                     ri_whichfork;
163         struct xfs_bmbt_irec                    ri_bmap;
164 };
165
166 /* functions for updating the rmapbt based on bmbt map/unmap operations */
167 void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
168                 int whichfork, struct xfs_bmbt_irec *imap);
169 void xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
170                 int whichfork, struct xfs_bmbt_irec *imap);
171 void xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
172                 struct xfs_inode *ip, int whichfork,
173                 struct xfs_bmbt_irec *imap);
174 void xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
175                 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
176 void xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
177                 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
178
179 void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
180                 struct xfs_btree_cur *rcur, int error);
181 int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
182                 uint64_t owner, int whichfork, xfs_fileoff_t startoff,
183                 xfs_fsblock_t startblock, xfs_filblks_t blockcount,
184                 xfs_exntst_t state, struct xfs_btree_cur **pcur);
185
186 int xfs_rmap_find_left_neighbor(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_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
190                 uint64_t owner, uint64_t offset, unsigned int flags,
191                 struct xfs_rmap_irec *irec, int *stat);
192 int xfs_rmap_compare(const struct xfs_rmap_irec *a,
193                 const struct xfs_rmap_irec *b);
194 union xfs_btree_rec;
195 int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec,
196                 struct xfs_rmap_irec *irec);
197 int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
198                 xfs_extlen_t len, bool *exists);
199 int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno,
200                 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
201                 bool *has_rmap);
202 int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
203                 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
204                 bool *has_rmap);
205 int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
206
207 extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
208 extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
209 extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
210 extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
211 extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
212 extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
213 extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
214 extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
215 extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
216
217 #endif  /* __XFS_RMAP_H__ */