]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: ensure fiemap doesn't race with writes when FIEMAP_FLAG_SYNC is given
authorFilipe Manana <fdmanana@suse.com>
Thu, 22 Feb 2024 12:29:34 +0000 (12:29 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:35:46 +0000 (16:35 +0200)
commit8cc484e85e0c6bf72ec7c3c8c697865355873cfb
tree67b5eae1d1392adedc2a684ac0d1f6a375c6d54d
parentfbc0a833c055a453d4bc1961c980a85ea1b0750d
btrfs: ensure fiemap doesn't race with writes when FIEMAP_FLAG_SYNC is given

[ Upstream commit 418b09027743d9a9fb39116bed46a192f868a3c3 ]

When FIEMAP_FLAG_SYNC is given to fiemap the expectation is that that
are no concurrent writes and we get a stable view of the inode's extent
layout.

When the flag is given we flush all IO (and wait for ordered extents to
complete) and then lock the inode in shared mode, however that leaves open
the possibility that a write might happen right after the flushing and
before locking the inode. So fix this by flushing again after locking the
inode - we leave the initial flushing before locking the inode to avoid
holding the lock and blocking other RO operations while waiting for IO
and ordered extents to complete. The second flushing while holding the
inode's lock will most of the time do nothing or very little since the
time window for new writes to have happened is small.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Stable-dep-of: 978b63f7464a ("btrfs: fix race when detecting delalloc ranges during fiemap")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/extent_io.c
fs/btrfs/inode.c