Skip to contentSkip to conversation

Btrfs: fix wrong file range cleanup after an error filling dealloc range

PATCH In review [email protected] 2 participants 4 messages May 27, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Btrfs: fix wrong file range cleanup after an error filling dealloc range

From: Filipe Manana <[email protected]>

If an error happens while running dellaloc in COW mode for a range, we can end up calling extent_clear_unlock_delalloc() for a range that goes beyond our range's end offset by 1 byte, which affects 1 extra page. This results in clearing bits and doing page operations (such as a page unlock) outside our target range.

Fix that by calling extent_clear_unlock_delalloc() with an inclusive end offset, instead of an exclusive end offset, at cow_file_range().

Fixes a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")
---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 320d1062068d..79f833f920d3 100644
@@ -1142,7 +1142,7 @@ static noinline int cow_file_range(struct inode *inode,
 	 */
 	if (extent_reserved) {
 		extent_clear_unlock_delalloc(inode, start,
-					     start + cur_alloc_size,
+					     start + cur_alloc_size - 1,
 					     locked_page,
 					     clear_bits,
 					     page_ops);
Signature · 1 line
2.11.0
#1 lore raw
Quoted 8 lines · On Wed, May 27, 2020 at 11:15:53AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

If an error happens while running dellaloc in COW mode for a range, we can end up calling extent_clear_unlock_delalloc() for a range that goes beyond our range's end offset by 1 byte, which affects 1 extra page. This results in clearing bits and doing page operations (such as a page unlock) outside our target range.

Quoted 5 lines

Fix that by calling extent_clear_unlock_delalloc() with an inclusive end offset, instead of an exclusive end offset, at cow_file_range().

Fixes a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")

1-3 added to misc-next, thanks.

#2 lore raw
Quoted 10 lines · David Sterba
Quoted 8 lines · On Wed, May 27, 2020 at 11:15:53AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

If an error happens while running dellaloc in COW mode for a range, we can end up calling extent_clear_unlock_delalloc() for a range that goes beyond our range's end offset by 1 byte, which affects 1 extra page. This results in clearing bits and doing page operations (such as a page unlock) outside our target range.

Quoted 7 lines
Quoted 5 lines

Fix that by calling extent_clear_unlock_delalloc() with an inclusive end offset, instead of an exclusive end offset, at cow_file_range().

Fixes a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")

1-3 added to misc-next, thanks.

So I noticed earlier that in patch 3/3, I mention "generic/061" instead of "btrfs/061". Would you mind amending the changelog with just that?

Thanks.

#3 lore raw
Quoted 14 lines · Filipe Manana
Quoted 13 lines · David Sterba
Quoted 11 lines · On Wed, May 27, 2020 at 11:15:53AM +0100, [email protected] wrote:

From: Filipe Manana <[email protected]>

If an error happens while running dellaloc in COW mode for a range, we can end up calling extent_clear_unlock_delalloc() for a range that goes beyond our range's end offset by 1 byte, which affects 1 extra page. This results in clearing bits and doing page operations (such as a page unlock) outside our target range.

Fix that by calling extent_clear_unlock_delalloc() with an inclusive end offset, instead of an exclusive end offset, at cow_file_range().

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")

1-3 added to misc-next, thanks.

So I noticed earlier that in patch 3/3, I mention "generic/061" instead of "btrfs/061". Would you mind amending the changelog with just that?

Changelog updated, thanks.