Skip to content

Commit 1364a3c

Browse files
Sarthak Kukretiaxboe
authored andcommitted
block: Don't invalidate pagecache for invalid falloc modes
Only call truncate_bdev_range() if the fallocate mode is supported. This fixes a bug where data in the pagecache could be invalidated if the fallocate() was called on the block device with an invalid mode. Fixes: 25f4c41 ("block: implement (some of) fallocate for block devices") Cc: [email protected] Reported-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Sarthak Kukreti <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Fixes: line? I've never seen those wrapped. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 07a1141 commit 1364a3c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

block/fops.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,24 +772,35 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
772772

773773
filemap_invalidate_lock(inode->i_mapping);
774774

775-
/* Invalidate the page cache, including dirty pages. */
776-
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
777-
if (error)
778-
goto fail;
779-
775+
/*
776+
* Invalidate the page cache, including dirty pages, for valid
777+
* de-allocate mode calls to fallocate().
778+
*/
780779
switch (mode) {
781780
case FALLOC_FL_ZERO_RANGE:
782781
case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE:
782+
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
783+
if (error)
784+
goto fail;
785+
783786
error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
784787
len >> SECTOR_SHIFT, GFP_KERNEL,
785788
BLKDEV_ZERO_NOUNMAP);
786789
break;
787790
case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE:
791+
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
792+
if (error)
793+
goto fail;
794+
788795
error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
789796
len >> SECTOR_SHIFT, GFP_KERNEL,
790797
BLKDEV_ZERO_NOFALLBACK);
791798
break;
792799
case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE:
800+
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
801+
if (error)
802+
goto fail;
803+
793804
error = blkdev_issue_discard(bdev, start >> SECTOR_SHIFT,
794805
len >> SECTOR_SHIFT, GFP_KERNEL);
795806
break;

0 commit comments

Comments
 (0)