Skip to content

Commit

Permalink
bdev: Do not return EBUSY if bdev discard races with write
Browse files Browse the repository at this point in the history
blkdev_fallocate() tries to detect whether a discard raced with an
overlapping write by calling invalidate_inode_pages2_range(). However
this check can give both false negatives (when writing using direct IO
or when writeback already writes out the written pagecache range) and
false positives (when write is not actually overlapping but ends in the
same page when blocksize < pagesize). This actually causes issues for
qemu which is getting confused by EBUSY errors.

Fix the problem by removing this conflicting write detection since it is
inherently racy and thus of little use anyway.

Reported-by: Maxim Levitsky <[email protected]>
CC: "Darrick J. Wong" <[email protected]>
Link: https://lore.kernel.org/qemu-devel/[email protected]
Signed-off-by: Jan Kara <[email protected]>
Reviewed-by: Maxim Levitsky <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
jankara authored and axboe committed Jan 26, 2021
1 parent 46bbf65 commit 767630c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,13 +1801,11 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
return error;

/*
* Invalidate again; if someone wandered in and dirtied a page,
* the caller will be given -EBUSY. The third argument is
* inclusive, so the rounding here is safe.
* Invalidate the page cache again; if someone wandered in and dirtied
* a page, we just discard it - userspace has no way of knowing whether
* the write happened before or after discard completing...
*/
return invalidate_inode_pages2_range(bdev->bd_inode->i_mapping,
start >> PAGE_SHIFT,
end >> PAGE_SHIFT);
return truncate_bdev_range(bdev, file->f_mode, start, end);
}

const struct file_operations def_blk_fops = {
Expand Down

0 comments on commit 767630c

Please sign in to comment.