Skip to contentSkip to conversation

btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent()

PATCH In review Mark Harmstone 3 participants 3 messages Apr 16 – Apr 21 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent()

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 a4fe134fc1d8, which is the same fix in cow_one_range().

Fixes 151a41bc46df ("Btrfs: fix what bits we clear when erroring out from delalloc")
---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 36bbf2297a9987..abedaeb45189a2 100644
@@ -1204,7 +1204,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
 				     NULL, &cached,
 				     EXTENT_LOCKED | EXTENT_DELALLOC |
 				     EXTENT_DELALLOC_NEW |
-				     EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
+				     EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV,
 				     PAGE_UNLOCK | PAGE_START_WRITEBACK |
 				     PAGE_END_WRITEBACK);
 	if (async_extent->cb)
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Mark Harmstone

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.

Quoted 5 lines

Fix this by replacing EXTENT_DO_ACCOUNTING with EXTENT_CLEAR_META_RESV. This parallels a4fe134fc1d8, which is the same fix in cow_one_range().

Fixes 151a41bc46df ("Btrfs: fix what bits we clear when erroring out from delalloc")

Thanks,
Qu

Quoted 17 lines
---
  fs/btrfs/inode.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
index 36bbf2297a9987..abedaeb45189a2 100644
@@ -1204,7 +1204,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
  				     NULL, &cached,
  				     EXTENT_LOCKED | EXTENT_DELALLOC |
  				     EXTENT_DELALLOC_NEW |
-				     EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING,
+				     EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV,
  				     PAGE_UNLOCK | PAGE_START_WRITEBACK |
  				     PAGE_END_WRITEBACK);
  	if (async_extent->cb)
#2 lore raw
In reply to Mark Harmstone
Quoted 11 lines · Mark Harmstone

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 a4fe134fc1d8, which is the same fix in cow_one_range().

                 ^^^^^^^^^^^^

Please for first occurence put the full commit reference, the same one as for the Fixes tag. Fixed in for-next.