btrfs: use correct count in btrfs_file_write_iter()
authorOmar Sandoval <osandov@fb.com>
Thu, 15 Aug 2019 21:04:02 +0000 (14:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jan 2020 13:51:12 +0000 (14:51 +0100)
commit6ec047a0b80c0d1288f5d3424dfc699aa3ea76a1
tree16fdaf17ff14af360c1d0482604d24b8b0963a9c
parentcbbc34abc395d3cf91265f3b35a29ca76f7c0c04
btrfs: use correct count in btrfs_file_write_iter()

[ Upstream commit c09767a8960ca0500fb636bf73686723337debf4 ]

generic_write_checks() may modify iov_iter_count(), so we must get the
count after the call, not before. Using the wrong one has a couple of
consequences:

1. We check a longer range in check_can_nocow() for nowait than we're
   actually writing.
2. We create extra hole extent maps in btrfs_cont_expand(). As far as I
   can tell, this is harmless, but I might be missing something.

These issues are pretty minor, but let's fix it before something more
important trips on it.

Fixes: edf064e7c6fe ("btrfs: nowait aio support")
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/file.c