need_force_cow will evaluate to false if both BTRFS_INODE_NODATACOW and BTRFS_INODE_PREALLOC are not set. Change the function to should_cow() instead and correct the conditions so should_nocow() returns true if either BTRFS_INODE_NODATACOW or BTRFS_INODE_PREALLOC, but it is not a defrag extent.
Fixes: 7e33213f8ccc btrfs: remove force argument from run_delalloc_nocow() Signed-off-by: Goldwyn Rodrigues <rgold...@suse.com> --- fs/btrfs/inode.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0b133fda4f5d..ceb6ca7c571d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1864,23 +1864,16 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, return ret; } -static inline int need_force_cow(struct btrfs_inode *inode, u64 start, u64 end) +static inline bool should_nocow(struct btrfs_inode *inode, u64 start, u64 end) { - - if (!(inode->flags & BTRFS_INODE_NODATACOW) && - !(inode->flags & BTRFS_INODE_PREALLOC)) - return 0; - - /* - * @defrag_bytes is a hint value, no spinlock held here, - * if is not zero, it means the file is defragging. - * Force cow if given extent needs to be defragged. - */ - if (inode->defrag_bytes && - test_range_bit(&inode->io_tree, start, end, EXTENT_DEFRAG, 0, NULL)) - return 1; - - return 0; + if (inode->flags & (BTRFS_INODE_NODATACOW | BTRFS_INODE_PREALLOC)) { + if (inode->defrag_bytes && + test_range_bit(&inode->io_tree, start, end, EXTENT_DEFRAG, + 0, NULL)) + return false; + return true; + } + return false; } /* @@ -1894,7 +1887,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page int ret; const bool zoned = btrfs_is_zoned(inode->root->fs_info); - if (!need_force_cow(inode, start, end)) { + if (should_nocow(inode, start, end)) { ASSERT(!zoned); ret = run_delalloc_nocow(inode, locked_page, start, end, page_started, nr_written); -- 2.30.1 -- Goldwyn