.. | .. |
---|
1 | | -// SPDX-License-Identifier: GPL-2.0 |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
---|
2 | 2 | /* |
---|
3 | 3 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
---|
4 | 4 | * All Rights Reserved. |
---|
.. | .. |
---|
95 | 95 | /* Map something in the CoW fork. */ |
---|
96 | 96 | #define XFS_BMAPI_COWFORK 0x200 |
---|
97 | 97 | |
---|
98 | | -/* Only convert delalloc space, don't allocate entirely new extents */ |
---|
99 | | -#define XFS_BMAPI_DELALLOC 0x400 |
---|
100 | | - |
---|
101 | | -/* Only convert unwritten extents, don't allocate new blocks */ |
---|
102 | | -#define XFS_BMAPI_CONVERT_ONLY 0x800 |
---|
103 | | - |
---|
104 | 98 | /* Skip online discard of freed extents */ |
---|
105 | 99 | #define XFS_BMAPI_NODISCARD 0x1000 |
---|
106 | 100 | |
---|
.. | .. |
---|
117 | 111 | { XFS_BMAPI_ZERO, "ZERO" }, \ |
---|
118 | 112 | { XFS_BMAPI_REMAP, "REMAP" }, \ |
---|
119 | 113 | { XFS_BMAPI_COWFORK, "COWFORK" }, \ |
---|
120 | | - { XFS_BMAPI_DELALLOC, "DELALLOC" }, \ |
---|
121 | | - { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" }, \ |
---|
122 | 114 | { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ |
---|
123 | 115 | { XFS_BMAPI_NORMAP, "NORMAP" } |
---|
124 | 116 | |
---|
.. | .. |
---|
166 | 158 | { BMAP_ATTRFORK, "ATTR" }, \ |
---|
167 | 159 | { BMAP_COWFORK, "COW" } |
---|
168 | 160 | |
---|
| 161 | +/* Return true if the extent is an allocated extent, written or not. */ |
---|
| 162 | +static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) |
---|
| 163 | +{ |
---|
| 164 | + return irec->br_startblock != HOLESTARTBLOCK && |
---|
| 165 | + irec->br_startblock != DELAYSTARTBLOCK && |
---|
| 166 | + !isnullstartblock(irec->br_startblock); |
---|
| 167 | +} |
---|
169 | 168 | |
---|
170 | 169 | /* |
---|
171 | 170 | * Return true if the extent is a real, allocated extent, or false if it is a |
---|
172 | 171 | * delayed allocation, and unwritten extent or a hole. |
---|
173 | 172 | */ |
---|
174 | | -static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) |
---|
| 173 | +static inline bool xfs_bmap_is_written_extent(struct xfs_bmbt_irec *irec) |
---|
175 | 174 | { |
---|
176 | | - return irec->br_state != XFS_EXT_UNWRITTEN && |
---|
177 | | - irec->br_startblock != HOLESTARTBLOCK && |
---|
178 | | - irec->br_startblock != DELAYSTARTBLOCK && |
---|
179 | | - !isnullstartblock(irec->br_startblock); |
---|
| 175 | + return xfs_bmap_is_real_extent(irec) && |
---|
| 176 | + irec->br_state != XFS_EXT_UNWRITTEN; |
---|
180 | 177 | } |
---|
| 178 | + |
---|
| 179 | +/* |
---|
| 180 | + * Check the mapping for obviously garbage allocations that could trash the |
---|
| 181 | + * filesystem immediately. |
---|
| 182 | + */ |
---|
| 183 | +#define xfs_valid_startblock(ip, startblock) \ |
---|
| 184 | + ((startblock) != 0 || XFS_IS_REALTIME_INODE(ip)) |
---|
181 | 185 | |
---|
182 | 186 | void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno, |
---|
183 | 187 | xfs_filblks_t len); |
---|
184 | | -void xfs_trim_extent_eof(struct xfs_bmbt_irec *, struct xfs_inode *); |
---|
185 | 188 | int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); |
---|
186 | 189 | int xfs_bmap_set_attrforkoff(struct xfs_inode *ip, int size, int *version); |
---|
187 | | -void xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork); |
---|
| 190 | +void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp, |
---|
| 191 | + struct xfs_inode *ip, int whichfork); |
---|
188 | 192 | void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno, |
---|
189 | | - xfs_filblks_t len, struct xfs_owner_info *oinfo, |
---|
| 193 | + xfs_filblks_t len, const struct xfs_owner_info *oinfo, |
---|
190 | 194 | bool skip_discard); |
---|
191 | 195 | void xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork); |
---|
192 | 196 | int xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
.. | .. |
---|
223 | 227 | int xfs_bmap_insert_extents(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
224 | 228 | xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb, |
---|
225 | 229 | bool *done, xfs_fileoff_t stop_fsb); |
---|
226 | | -int xfs_bmap_split_extent(struct xfs_inode *ip, xfs_fileoff_t split_offset); |
---|
| 230 | +int xfs_bmap_split_extent(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
| 231 | + xfs_fileoff_t split_offset); |
---|
227 | 232 | int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork, |
---|
228 | 233 | xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc, |
---|
229 | 234 | struct xfs_bmbt_irec *got, struct xfs_iext_cursor *cur, |
---|
230 | 235 | int eof); |
---|
| 236 | +int xfs_bmapi_convert_delalloc(struct xfs_inode *ip, int whichfork, |
---|
| 237 | + xfs_off_t offset, struct iomap *iomap, unsigned int *seq); |
---|
| 238 | +int xfs_bmap_add_extent_unwritten_real(struct xfs_trans *tp, |
---|
| 239 | + struct xfs_inode *ip, int whichfork, |
---|
| 240 | + struct xfs_iext_cursor *icur, struct xfs_btree_cur **curp, |
---|
| 241 | + struct xfs_bmbt_irec *new, int *logflagsp); |
---|
231 | 242 | |
---|
232 | 243 | static inline void |
---|
233 | 244 | xfs_bmap_add_free( |
---|
234 | 245 | struct xfs_trans *tp, |
---|
235 | 246 | xfs_fsblock_t bno, |
---|
236 | 247 | xfs_filblks_t len, |
---|
237 | | - struct xfs_owner_info *oinfo) |
---|
| 248 | + const struct xfs_owner_info *oinfo) |
---|
238 | 249 | { |
---|
239 | 250 | __xfs_bmap_add_free(tp, bno, len, oinfo, false); |
---|
240 | 251 | } |
---|
.. | .. |
---|
256 | 267 | enum xfs_bmap_intent_type type, int whichfork, |
---|
257 | 268 | xfs_fileoff_t startoff, xfs_fsblock_t startblock, |
---|
258 | 269 | xfs_filblks_t *blockcount, xfs_exntst_t state); |
---|
259 | | -int xfs_bmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
| 270 | +void xfs_bmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
260 | 271 | struct xfs_bmbt_irec *imap); |
---|
261 | | -int xfs_bmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
| 272 | +void xfs_bmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip, |
---|
262 | 273 | struct xfs_bmbt_irec *imap); |
---|
263 | 274 | |
---|
264 | 275 | static inline int xfs_bmap_fork_to_state(int whichfork) |
---|