Commit | Line | Data |
---|---|---|
340785cc DW |
1 | /* |
2 | * Copyright (C) 2016 Oracle. All Rights Reserved. | |
3 | * | |
4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it would be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write the Free Software Foundation, | |
18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | */ | |
20 | #ifndef __XFS_RMAP_H__ | |
21 | #define __XFS_RMAP_H__ | |
22 | ||
23 | static inline void | |
24 | xfs_rmap_ag_owner( | |
25 | struct xfs_owner_info *oi, | |
26 | uint64_t owner) | |
27 | { | |
28 | oi->oi_owner = owner; | |
29 | oi->oi_offset = 0; | |
30 | oi->oi_flags = 0; | |
31 | } | |
32 | ||
33 | static inline void | |
34 | xfs_rmap_ino_bmbt_owner( | |
35 | struct xfs_owner_info *oi, | |
36 | xfs_ino_t ino, | |
37 | int whichfork) | |
38 | { | |
39 | oi->oi_owner = ino; | |
40 | oi->oi_offset = 0; | |
41 | oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK; | |
42 | if (whichfork == XFS_ATTR_FORK) | |
43 | oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK; | |
44 | } | |
45 | ||
46 | static inline void | |
47 | xfs_rmap_ino_owner( | |
48 | struct xfs_owner_info *oi, | |
49 | xfs_ino_t ino, | |
50 | int whichfork, | |
51 | xfs_fileoff_t offset) | |
52 | { | |
53 | oi->oi_owner = ino; | |
54 | oi->oi_offset = offset; | |
55 | oi->oi_flags = 0; | |
56 | if (whichfork == XFS_ATTR_FORK) | |
57 | oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK; | |
58 | } | |
59 | ||
60 | static inline void | |
61 | xfs_rmap_skip_owner_update( | |
62 | struct xfs_owner_info *oi) | |
63 | { | |
64 | oi->oi_owner = XFS_RMAP_OWN_UNKNOWN; | |
65 | } | |
66 | ||
673930c3 DW |
67 | /* Reverse mapping functions. */ |
68 | ||
69 | struct xfs_buf; | |
70 | ||
035e00ac DW |
71 | static inline __u64 |
72 | xfs_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 | ||
87 | static inline int | |
88 | xfs_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 | ||
104 | static inline void | |
105 | xfs_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 | ||
122 | static inline void | |
123 | xfs_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 | ||
673930c3 DW |
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); | |
144 | ||
4b8ed677 DW |
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); | |
abf09233 DW |
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, | |
153 | unsigned int flags); | |
4b8ed677 DW |
154 | int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec, |
155 | int *stat); | |
156 | ||
c543838a DW |
157 | typedef int (*xfs_rmap_query_range_fn)( |
158 | struct xfs_btree_cur *cur, | |
159 | struct xfs_rmap_irec *rec, | |
160 | void *priv); | |
161 | ||
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 | ||
5880f2d7 DW |
166 | enum xfs_rmap_intent_type { |
167 | XFS_RMAP_MAP, | |
168 | XFS_RMAP_MAP_SHARED, | |
169 | XFS_RMAP_UNMAP, | |
170 | XFS_RMAP_UNMAP_SHARED, | |
171 | XFS_RMAP_CONVERT, | |
172 | XFS_RMAP_CONVERT_SHARED, | |
173 | XFS_RMAP_ALLOC, | |
174 | XFS_RMAP_FREE, | |
175 | }; | |
176 | ||
177 | struct xfs_rmap_intent { | |
178 | struct list_head ri_list; | |
179 | enum xfs_rmap_intent_type ri_type; | |
180 | __uint64_t ri_owner; | |
181 | int ri_whichfork; | |
182 | struct xfs_bmbt_irec ri_bmap; | |
183 | }; | |
184 | ||
340785cc | 185 | #endif /* __XFS_RMAP_H__ */ |