btrfs: move common NOCOW checks against a file extent into a helper
authorFilipe Manana <fdmanana@suse.com>
Wed, 30 Mar 2022 14:31:06 +0000 (15:31 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 16 May 2022 15:03:11 +0000 (17:03 +0200)
commit619104ba453ad0965660d643f64ffbeb721906f5
tree5d3a2354640d652579d1510c3e66b574dafeb473
parent395cb57e85604715110bc28bd51bdf532394b68d
btrfs: move common NOCOW checks against a file extent into a helper

Verifying if we can do a NOCOW write against a range fully or partially
covered by a file extent item requires verifying several constraints, and
these are currently duplicated at two different places: can_nocow_extent()
and run_delalloc_nocow().

This change moves those checks into a common helper function to avoid
duplication. It adds some comments and also preserves all existing
behaviour like for example can_nocow_extent() treating errors from the
calls to btrfs_cross_ref_exist() and csum_exist_in_range() as meaning
we can not NOCOW, instead of propagating the error back to the caller.
That specific behaviour is questionable but also reasonable to some
degree.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c