Commit 0ab54099 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba
Browse files

btrfs: push lock_extent into cow_file_range_inline



Now that we've pushed the lock_extent() into cow_file_range() we can
push the extent locking into cow_file_range_inline() and move the
lock_extent in cow_file_range() to after we call
cow_file_range_inline().

Reviewed-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a0766d8f
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -744,17 +744,22 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
					  struct folio *compressed_folio,
					  bool update_i_size)
{
	struct extent_state *cached = NULL;
	unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
		EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED;
	u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1);
	int ret;

	lock_extent(&inode->io_tree, offset, end, &cached);
	ret = __cow_file_range_inline(inode, offset, size, compressed_size,
				      compress_type, compressed_folio,
				      update_i_size);
	if (ret > 0)
	if (ret > 0) {
		unlock_extent(&inode->io_tree, offset, end, &cached);
		return ret;
	}

	free_extent_state(cached);
	extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags,
				     PAGE_UNLOCK | PAGE_START_WRITEBACK |
				     PAGE_END_WRITEBACK);
@@ -1028,7 +1033,6 @@ static void compress_file_range(struct btrfs_work *work)
	 * Check cow_file_range() for why we don't even try to create inline
	 * extent for the subpage case.
	 */
	lock_extent(&inode->io_tree, start, end, NULL);
	if (total_in < actual_end)
		ret = cow_file_range_inline(inode, start, end, 0,
					    BTRFS_COMPRESS_NONE, NULL, false);
@@ -1040,7 +1044,6 @@ static void compress_file_range(struct btrfs_work *work)
			mapping_set_error(mapping, -EIO);
		goto free_pages;
	}
	unlock_extent(&inode->io_tree, start, end, NULL);

	/*
	 * We aren't doing an inline extent. Round the compressed size up to a
@@ -1336,8 +1339,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
	bool extent_reserved = false;
	int ret = 0;

	lock_extent(&inode->io_tree, start, end, NULL);

	if (btrfs_is_free_space_inode(inode)) {
		ret = -EINVAL;
		goto out_unlock;
@@ -1367,6 +1368,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
		}
	}

	lock_extent(&inode->io_tree, start, end, NULL);

	alloc_hint = get_extent_allocation_hint(inode, start, num_bytes);

	/*