Skip to content

Commit 7112abc

Browse files
Christoph Hellwiggregkh
authored andcommitted
btrfs: properly clear end of the unreserved range in cow_file_range
commit 12b2d64 upstream. When the call to btrfs_reloc_clone_csums in cow_file_range returns an error, we jump to the out_unlock label with the extent_reserved variable set to false. The cleanup at the label will then call extent_clear_unlock_delalloc on the range from start to end. But we've already added cur_alloc_size to start before the jump, so there might no range be left from the newly incremented start to end. Move the check for 'start < end' so that it is reached by also for the !extent_reserved case. CC: stable@vger.kernel.org # 6.1+ Fixes: a315e68 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range") Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 504d81c commit 7112abc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/btrfs/inode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14291429
clear_bits,
14301430
page_ops);
14311431
start += cur_alloc_size;
1432-
if (start >= end)
1433-
return ret;
14341432
}
14351433

14361434
/*
@@ -1439,9 +1437,11 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14391437
* space_info's bytes_may_use counter, reserved in
14401438
* btrfs_check_data_free_space().
14411439
*/
1442-
extent_clear_unlock_delalloc(inode, start, end, locked_page,
1443-
clear_bits | EXTENT_CLEAR_DATA_RESV,
1444-
page_ops);
1440+
if (start < end) {
1441+
clear_bits |= EXTENT_CLEAR_DATA_RESV;
1442+
extent_clear_unlock_delalloc(inode, start, end, locked_page,
1443+
clear_bits, page_ops);
1444+
}
14451445
return ret;
14461446
}
14471447

0 commit comments

Comments
 (0)