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

iomap: zero newly allocated mapped blocks

File systems like gfs2 don't support delayed allocations or unwritten
extents and thus allocate normal mapped blocks to fill holes. To
cover the case of such file systems allocating new blocks to fill holes
also zero out mapped blocks with the new flag.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
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
009d8d84 760fea8b

+10 -2
+10 -2
fs/iomap/buffered-io.c
··· 203 203 SetPageUptodate(page); 204 204 } 205 205 206 + static inline bool iomap_block_needs_zeroing(struct inode *inode, 207 + struct iomap *iomap, loff_t pos) 208 + { 209 + return iomap->type != IOMAP_MAPPED || 210 + (iomap->flags & IOMAP_F_NEW) || 211 + pos >= i_size_read(inode); 212 + } 213 + 206 214 static loff_t 207 215 iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, 208 216 struct iomap *iomap) ··· 234 226 if (plen == 0) 235 227 goto done; 236 228 237 - if (iomap->type != IOMAP_MAPPED || pos >= i_size_read(inode)) { 229 + if (iomap_block_needs_zeroing(inode, iomap, pos)) { 238 230 zero_user(page, poff, plen); 239 231 iomap_set_range_uptodate(page, poff, plen); 240 232 goto done; ··· 540 532 struct bio_vec bvec; 541 533 struct bio bio; 542 534 543 - if (iomap->type != IOMAP_MAPPED || block_start >= i_size_read(inode)) { 535 + if (iomap_block_needs_zeroing(inode, iomap, block_start)) { 544 536 zero_user_segments(page, poff, from, to, poff + plen); 545 537 iomap_set_range_uptodate(page, poff, plen); 546 538 return 0;