Skip to content

Commit 7034674

Browse files
josefbacikkdave
authored andcommitted
btrfs: lock extent when doing inline extent in compression
We currently don't lock the extent when we're doing a cow_file_range_inline() for a compressed extent. This isn't a problem necessarily, but it's inconsistent with the rest of our usage of cow_file_range_inline(). This also leads to some extra weird logic around whether the extent is locked or not. Fix this to lock the extent before calling cow_file_range_inline() in compression to make it consistent with the rest of the inline users. In future patches this will be pushed down into the cow_file_range_inline() helper, so we're fine with the quick and dirty locking here. This patch exists to make the behavior change obvious. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0586d0a commit 7034674

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

fs/btrfs/inode.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,10 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
742742
size_t compressed_size,
743743
int compress_type,
744744
struct folio *compressed_folio,
745-
bool update_i_size, bool locked)
745+
bool update_i_size)
746746
{
747747
unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
748-
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING;
748+
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED;
749749
u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1);
750750
int ret;
751751

@@ -755,9 +755,6 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset,
755755
if (ret > 0)
756756
return ret;
757757

758-
if (locked)
759-
clear_flags |= EXTENT_LOCKED;
760-
761758
extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags,
762759
PAGE_UNLOCK | PAGE_START_WRITEBACK |
763760
PAGE_END_WRITEBACK);
@@ -1031,18 +1028,19 @@ static void compress_file_range(struct btrfs_work *work)
10311028
* Check cow_file_range() for why we don't even try to create inline
10321029
* extent for the subpage case.
10331030
*/
1031+
lock_extent(&inode->io_tree, start, end, NULL);
10341032
if (total_in < actual_end)
10351033
ret = cow_file_range_inline(inode, start, end, 0,
1036-
BTRFS_COMPRESS_NONE, NULL, false,
1037-
false);
1034+
BTRFS_COMPRESS_NONE, NULL, false);
10381035
else
10391036
ret = cow_file_range_inline(inode, start, end, total_compressed,
1040-
compress_type, folios[0], false, false);
1037+
compress_type, folios[0], false);
10411038
if (ret <= 0) {
10421039
if (ret < 0)
10431040
mapping_set_error(mapping, -EIO);
10441041
goto free_pages;
10451042
}
1043+
unlock_extent(&inode->io_tree, start, end, NULL);
10461044

10471045
/*
10481046
* We aren't doing an inline extent. Round the compressed size up to a
@@ -1352,8 +1350,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
13521350
if (!no_inline) {
13531351
/* lets try to make an inline extent */
13541352
ret = cow_file_range_inline(inode, start, end, 0,
1355-
BTRFS_COMPRESS_NONE, NULL, false,
1356-
true);
1353+
BTRFS_COMPRESS_NONE, NULL, false);
13571354
if (ret <= 0) {
13581355
/*
13591356
* We succeeded, return 1 so the caller knows we're done

0 commit comments

Comments
 (0)