Skip to content

Commit 2393eb5

Browse files
maharmstonegregkh
authored andcommitted
btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent()
[ Upstream commit 82323b1 ] submit_one_async_extent() calls btrfs_reserve_extent(), which decrements bytes_may_use. If the call btrfs_create_io_em() fails, we jump to out_free_reserve, which calls extent_clear_unlock_delalloc(). Because we're specifying EXTENT_DO_ACCOUNTING, i.e. EXTENT_CLEAR_META_RESV | EXTENT_CLEAR_DATA_RESV, this decreases bytes_may_use again. This can lead to problems later on, as an initial write can fail only for the writeback to silently ENOSPC. Fix this by replacing EXTENT_DO_ACCOUNTING with EXTENT_CLEAR_META_RESV. This parallels a4fe134 ("btrfs: fix a double release on reserved extents in cow_one_range()"), which is the same fix in cow_one_range(). Fixes: 151a41b ("Btrfs: fix what bits we clear when erroring out from delalloc") Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Mark Harmstone <mark@harmstone.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8c8afa6 commit 2393eb5

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
12881288
NULL, &cached,
12891289
EXTENT_LOCKED | EXTENT_DELALLOC |
12901290
EXTENT_DELALLOC_NEW |
1291-
EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
1291+
EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV,
12921292
PAGE_UNLOCK | PAGE_START_WRITEBACK |
12931293
PAGE_END_WRITEBACK);
12941294
free_async_extent_pages(async_extent);

0 commit comments

Comments
 (0)