Skip to content

Commit cd241a8

Browse files
josefbacikkdave
authored andcommitted
btrfs: move can_cow_file_range_inline() outside of the extent lock
These checks aren't reliant on the extent lock. Move this up into cow_file_range_inline(), and then update encoded writes to call this check before calling __cow_file_range_inline(). This will allow us to skip the extent lock if we're not able to inline the given extent. Reviewed-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0ab5409 commit cd241a8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fs/btrfs/inode.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ static bool can_cow_file_range_inline(struct btrfs_inode *inode,
661661
* conditionally insert an inline extent into the file. This
662662
* does the checks required to make sure the data is small enough
663663
* to fit as an inline extent.
664+
*
665+
* If being used directly, you must have already checked we're allowed to cow
666+
* the range by getting true from can_cow_file_range_inline().
664667
*/
665668
static noinline int __cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
666669
u64 size, size_t compressed_size,
@@ -676,9 +679,6 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode, u64 offse
676679
int ret;
677680
struct btrfs_path *path;
678681

679-
if (!can_cow_file_range_inline(inode, offset, size, compressed_size))
680-
return 1;
681-
682682
path = btrfs_alloc_path();
683683
if (!path)
684684
return -ENOMEM;
@@ -750,6 +750,9 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
750750
u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1);
751751
int ret;
752752

753+
if (!can_cow_file_range_inline(inode, offset, size, compressed_size))
754+
return 1;
755+
753756
lock_extent(&inode->io_tree, offset, end, &cached);
754757
ret = __cow_file_range_inline(inode, offset, size, compressed_size,
755758
compress_type, compressed_folio,
@@ -10287,7 +10290,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
1028710290

1028810291
/* Try an inline extent first. */
1028910292
if (encoded->unencoded_len == encoded->len &&
10290-
encoded->unencoded_offset == 0) {
10293+
encoded->unencoded_offset == 0 &&
10294+
can_cow_file_range_inline(inode, start, encoded->len, orig_count)) {
1029110295
ret = __cow_file_range_inline(inode, start, encoded->len,
1029210296
orig_count, compression, folios[0],
1029310297
true);

0 commit comments

Comments
 (0)