Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: simplify xfs_iomap_eof_align_last_fsb

By open coding xfs_bmap_last_extent instead of calling it through a
double indirection we don't need to handle an error return that
can't happen given that we are guaranteed to have the extent list in
memory already. Also simplify the calling conventions a little and
move the extent list assert from the only caller into the function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

authored by

Christoph Hellwig and committed by
Darrick J. Wong
ae7e403f 249bd908

+22 -50
-23
fs/xfs/xfs_bmap_util.c
··· 180 180 #endif /* CONFIG_XFS_RT */ 181 181 182 182 /* 183 - * Check if the endoff is outside the last extent. If so the caller will grow 184 - * the allocation to a stripe unit boundary. All offsets are considered outside 185 - * the end of file for an empty fork, so 1 is returned in *eof in that case. 186 - */ 187 - int 188 - xfs_bmap_eof( 189 - struct xfs_inode *ip, 190 - xfs_fileoff_t endoff, 191 - int whichfork, 192 - int *eof) 193 - { 194 - struct xfs_bmbt_irec rec; 195 - int error; 196 - 197 - error = xfs_bmap_last_extent(NULL, ip, whichfork, &rec, eof); 198 - if (error || *eof) 199 - return error; 200 - 201 - *eof = endoff >= rec.br_startoff + rec.br_blockcount; 202 - return 0; 203 - } 204 - 205 - /* 206 183 * Extent tree block counting routines. 207 184 */ 208 185
-2
fs/xfs/xfs_bmap_util.h
··· 30 30 } 31 31 #endif /* CONFIG_XFS_RT */ 32 32 33 - int xfs_bmap_eof(struct xfs_inode *ip, xfs_fileoff_t endoff, 34 - int whichfork, int *eof); 35 33 int xfs_bmap_punch_delalloc_range(struct xfs_inode *ip, 36 34 xfs_fileoff_t start_fsb, xfs_fileoff_t length); 37 35
+22 -25
fs/xfs/xfs_iomap.c
··· 156 156 return align; 157 157 } 158 158 159 - STATIC int 159 + /* 160 + * Check if last_fsb is outside the last extent, and if so grow it to the next 161 + * stripe unit boundary. 162 + */ 163 + static xfs_fileoff_t 160 164 xfs_iomap_eof_align_last_fsb( 161 165 struct xfs_inode *ip, 162 - xfs_extlen_t extsize, 163 - xfs_fileoff_t *last_fsb) 166 + xfs_fileoff_t end_fsb) 164 167 { 165 - xfs_extlen_t align = xfs_eof_alignment(ip, extsize); 168 + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); 169 + xfs_extlen_t extsz = xfs_get_extsz_hint(ip); 170 + xfs_extlen_t align = xfs_eof_alignment(ip, extsz); 171 + struct xfs_bmbt_irec irec; 172 + struct xfs_iext_cursor icur; 173 + 174 + ASSERT(ifp->if_flags & XFS_IFEXTENTS); 166 175 167 176 if (align) { 168 - xfs_fileoff_t new_last_fsb = roundup_64(*last_fsb, align); 169 - int eof, error; 177 + xfs_fileoff_t aligned_end_fsb = roundup_64(end_fsb, align); 170 178 171 - error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof); 172 - if (error) 173 - return error; 174 - if (eof) 175 - *last_fsb = new_last_fsb; 179 + xfs_iext_last(ifp, &icur); 180 + if (!xfs_iext_get_extent(ifp, &icur, &irec) || 181 + aligned_end_fsb >= irec.br_startoff + irec.br_blockcount) 182 + return aligned_end_fsb; 176 183 } 177 - return 0; 184 + 185 + return end_fsb; 178 186 } 179 187 180 188 int ··· 214 206 215 207 ASSERT(xfs_isilocked(ip, lockmode)); 216 208 217 - if ((offset + count) > XFS_ISIZE(ip)) { 218 - /* 219 - * Assert that the in-core extent list is present since this can 220 - * call xfs_iread_extents() and we only have the ilock shared. 221 - * This should be safe because the lock was held around a bmapi 222 - * call in the caller and we only need it to access the in-core 223 - * list. 224 - */ 225 - ASSERT(XFS_IFORK_PTR(ip, XFS_DATA_FORK)->if_flags & 226 - XFS_IFEXTENTS); 227 - error = xfs_iomap_eof_align_last_fsb(ip, extsz, &last_fsb); 228 - if (error) 229 - goto out_unlock; 209 + if (offset + count > XFS_ISIZE(ip)) { 210 + last_fsb = xfs_iomap_eof_align_last_fsb(ip, last_fsb); 230 211 } else { 231 212 if (nmaps && (imap->br_startblock == HOLESTARTBLOCK)) 232 213 last_fsb = min(last_fsb, (xfs_fileoff_t)