Skip to content

Commit a30e577

Browse files
jeffmahoneyfdmanana
authored andcommitted
btrfs: skip waiting on ordered range for special files
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. Cc: <stable@vger.kernel.org> 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>
1 parent 005efed commit a30e577

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5080,7 +5080,8 @@ void btrfs_evict_inode(struct inode *inode)
50805080
goto no_delete;
50815081
}
50825082
/* do we really want it for ->i_nlink > 0 and zero btrfs_root_refs? */
5083-
btrfs_wait_ordered_range(inode, 0, (u64)-1);
5083+
if (!special_file(inode->i_mode))
5084+
btrfs_wait_ordered_range(inode, 0, (u64)-1);
50845085

50855086
btrfs_free_io_failure_record(inode, 0, (u64)-1);
50865087

0 commit comments

Comments
 (0)