btrfs: fix error handling when in a COW window in run_delalloc_nocow
authorChristoph Hellwig <hch@lst.de>
Mon, 24 Jul 2023 14:22:38 +0000 (07:22 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Aug 2023 12:54:47 +0000 (14:54 +0200)
commit953fa5ced510c4937075002bbfc6405cd500efef
tree1fdd31a5cd29a45ae2c15e0f63c62054d5717e3d
parent332581bde2a419d5f12a93a1cdc2856af649a3cc
btrfs: fix error handling when in a COW window in run_delalloc_nocow

When run_delalloc_nocow has cow_start set to a value other than (u64)-1,
it has delayed COW writeback pending behind cur_offset.  When an error
occurs in such a window, the range going back to cow_start and not just
cur_offset needs to be unlocked, but only two error cases handle this
correctly  Move the code to handle unlock the COW range to the common
error handling label and document the logic.

To make things even more complicated, cow_file_range as called by
fallback_to_cow will unlock the range it is operating on when it fails as
well, so we need to reset cow_start right after caling fallback_to_cow
instead of only when it succeeded.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c