]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: skip waiting on ordered range for special files
authorJeff Mahoney <jeffm@suse.com>
Sat, 12 Sep 2015 01:44:17 +0000 (21:44 -0400)
committerZefan Li <lizefan@huawei.com>
Wed, 27 Apr 2016 10:55:22 +0000 (18:55 +0800)
commit413e7340b4ceac04d90253c25472a221e2f529ff
treee9c68510b75f4825ad9811af38634d495710714d
parent557b53d8d4c7dbcc0615c2eeace00fd91bd2a17f
btrfs: skip waiting on ordered range for special files

commit a30e577c96f59b1e1678ea5462432b09bf7d5cbc upstream.

In btrfs_evict_inode, we properly truncate the page cache for evicted
inodes but then we call btrfs_wait_ordered_range for every inode as well.
It's the right thing to do for regular files but results in incorrect
behavior for device inodes for block devices.

filemap_fdatawrite_range gets called with inode->i_mapping which gets
resolved to the block device inode before getting passed to
wbc_attach_fdatawrite_inode and ultimately to inode_to_bdi.  What happens
next depends on whether there's an open file handle associated with the
inode.  If there is, we write to the block device, which is unexpected
behavior.  If there isn't, we through normally and inode->i_data is used.
We can also end up racing against open/close which can result in crashes
when i_mapping points to a block device inode that has been closed.

Since there can't be any page cache associated with special file inodes,
it's safe to skip the btrfs_wait_ordered_range call entirely and avoid
the problem.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=100911
Tested-by: Christoph Biedl <linux-kernel.bfrz@manchmal.in-ulm.de>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
fs/btrfs/inode.c