Skip to content

Commit be3f193

Browse files
fcmaplekdave
authored andcommitted
btrfs: fix COW handling in run_delalloc_nocow()
In run_delalloc_nocow(), when the found btrfs_key's offset > cur_offset, it indicates a gap between the current processing region and the next file extent. The original code would directly jump to the "must_cow" label, which increments the slot and forces a fallback to COW. This behavior might skip an extent item and result in an overestimated COW fallback range. This patch modifies the logic so that when a gap is detected: - If no COW range is already being recorded (cow_start is unset), cow_start is set to cur_offset. - cur_offset is then advanced to the beginning of the next extent. - Instead of jumping to "must_cow", control flows directly to "next_slot" so that the same extent item can be reexamined properly. The change ensures that we accurately account for the extent gap and avoid accidentally extending the range that needs to fallback to COW. CC: [email protected] # 6.6+ Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Dave Chen <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 866bafa commit be3f193

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

fs/btrfs/inode.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -2129,12 +2129,13 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
21292129

21302130
/*
21312131
* If the found extent starts after requested offset, then
2132-
* adjust extent_end to be right before this extent begins
2132+
* adjust cur_offset to be right before this extent begins.
21332133
*/
21342134
if (found_key.offset > cur_offset) {
2135-
extent_end = found_key.offset;
2136-
extent_type = 0;
2137-
goto must_cow;
2135+
if (cow_start == (u64)-1)
2136+
cow_start = cur_offset;
2137+
cur_offset = found_key.offset;
2138+
goto next_slot;
21382139
}
21392140

21402141
/*

0 commit comments

Comments
 (0)