diff mbox series

btrfs: fix nocow sequence in btrfs_run_delalloc_range()

Message ID 20210303125440.lub5c4qymhxo7mgh@fiona (mailing list archive)
State New, archived
Headers show
Series btrfs: fix nocow sequence in btrfs_run_delalloc_range() | expand

Commit Message

Goldwyn Rodrigues March 3, 2021, 12:54 p.m. UTC
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 <rgoldwyn@suse.com>
---
 fs/btrfs/inode.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Comments

David Sterba March 4, 2021, 1:36 p.m. UTC | #1
On Wed, Mar 03, 2021 at 06:54:40AM -0600, Goldwyn Rodrigues wrote:
> 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()

It would be better to send v2 of that patch, a cleanup with a fix should
be just one patch.
diff mbox series

Patch

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);