btrfs: fix nocow sequence in btrfs_run_delalloc_range()
PATCH 1/1 btrfs: fix nocow sequence in btrfs_run_delalloc_range()
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.
--- fs/btrfs/inode.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
fs/btrfs/inode.c +10 -17
@@ -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_pageint 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);
Signature · 5 lines
2.30.1 -- Goldwyn
Quoted 8 lines · Goldwyn Rodrigues
need_force_cowwill evaluate to false if bothBTRFS_INODE_NODATACOWandBTRFS_INODE_PREALLOCare not set. Change the function toshould_cow()instead and correct the conditions soshould_nocow()returns true if eitherBTRFS_INODE_NODATACOWorBTRFS_INODE_PREALLOC, but it is not a defrag extent.Fixes 7e33213f8ccc btrfs: remove force argument from run_delalloc_nocow()Signed-off-by Goldwyn Rodrigues <[email protected]>
This fixes the ASSERT() I've seen with zoned filesystems.
Thanks,
Johannes
Quoted 7 lines · Goldwyn Rodrigues
need_force_cowwill evaluate to false if bothBTRFS_INODE_NODATACOWandBTRFS_INODE_PREALLOCare not set. Change the function toshould_cow()instead and correct the conditions soshould_nocow()returns true if eitherBTRFS_INODE_NODATACOWorBTRFS_INODE_PREALLOC, but it is not a defrag extent.Fixes 7e33213f8ccc btrfs: remove force argument from run_delalloc_nocow()
It would be better to send v2 of that patch, a cleanup with a fix should be just one patch.