]> git.baikalelectronics.ru Git - kernel.git/commit
Btrfs: check for the full sync flag while holding the inode lock during fsync
authorFilipe Manana <fdmanana@suse.com>
Wed, 16 Oct 2019 15:28:52 +0000 (16:28 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 17 Oct 2019 18:36:02 +0000 (20:36 +0200)
commitbf1fe8f0b71b92b4c03d6976ec04ee00596f0b7f
tree04b984a30d1a5f79ddf3cb7920f4f4ef0c08814a
parent2b9a1c98e5aa5d82051e783c0b1d00e7fb4c8816
Btrfs: check for the full sync flag while holding the inode lock during fsync

We were checking for the full fsync flag in the inode before locking the
inode, which is racy, since at that that time it might not be set but
after we acquire the inode lock some other task set it. One case where
this can happen is on a system low on memory and some concurrent task
failed to allocate an extent map and therefore set the full sync flag on
the inode, to force the next fsync to work in full mode.

A consequence of missing the full fsync flag set is hitting the problems
fixed by commit 19ee5b4359c6 ("Btrfs: fix race between ranged fsync and
writeback of adjacent ranges"), BUG_ON() when dropping extents from a log
tree, hitting assertion failures at tree-log.c:copy_items() or all sorts
of weird inconsistencies after replaying a log due to file extents items
representing ranges that overlap.

So just move the check such that it's done after locking the inode and
before starting writeback again.

Fixes: 19ee5b4359c6 ("Btrfs: fix race between ranged fsync and writeback of adjacent ranges")
CC: stable@vger.kernel.org # 5.2+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c