[XFS] Don't do I/O beyond eof when unreserving space

When unreserving space with boundaries that are not block aligned we round
up the start and round down the end boundaries and then use this function,
xfs_zero_remaining_bytes(), to zero the parts of the blocks that got
dropped during the rounding. The problem is we don't consider if these
blocks are beyond eof. Worse still is if we encounter delayed allocations
beyond eof we will try to use the magic delayed allocation block number as
a real block number. If the file size is ever extended to expose these
blocks then we'll go through xfs_zero_eof() to zero them anyway.

SGI-PV: 983683

SGI-Modid: xfs-linux-melb:xfs-kern:32055a

Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Signed-off-by: Christoph Hellwig <hch@infradead.org>

authored by Lachlan McIlroy and committed by Lachlan McIlroy 2fd6f6ec e1f5dbd7

+18
+18
fs/xfs/xfs_vnodeops.c
··· 3160 3160 /* 3161 3161 * Zero file bytes between startoff and endoff inclusive. 3162 3162 * The iolock is held exclusive and no blocks are buffered. 3163 + * 3164 + * This function is used by xfs_free_file_space() to zero 3165 + * partial blocks when the range to free is not block aligned. 3166 + * When unreserving space with boundaries that are not block 3167 + * aligned we round up the start and round down the end 3168 + * boundaries and then use this function to zero the parts of 3169 + * the blocks that got dropped during the rounding. 3163 3170 */ 3164 3171 STATIC int 3165 3172 xfs_zero_remaining_bytes( ··· 3182 3175 xfs_mount_t *mp = ip->i_mount; 3183 3176 int nimap; 3184 3177 int error = 0; 3178 + 3179 + /* 3180 + * Avoid doing I/O beyond eof - it's not necessary 3181 + * since nothing can read beyond eof. The space will 3182 + * be zeroed when the file is extended anyway. 3183 + */ 3184 + if (startoff >= ip->i_size) 3185 + return 0; 3186 + 3187 + if (endoff > ip->i_size) 3188 + endoff = ip->i_size; 3185 3189 3186 3190 bp = xfs_buf_get_noaddr(mp->m_sb.sb_blocksize, 3187 3191 XFS_IS_REALTIME_INODE(ip) ?