]> git.hungrycats.org Git - linux/commit
btrfs: free queued remap chunks when balance bails out 7.3/topics/remap-balance-leak
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 13 Oct 2026 05:05:21 +0000 (01:05 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 06:08:41 +0000 (01:08 -0500)
commit54ae1bd4296016d1cb54fd1f821ff8ed9a76e995
treea723a077485272ff62c648cf15205e3bca78ee73
parentd50d994bffa3c7c6db2d8bc4c5f0c55e3f46b0cd
btrfs: free queued remap chunks when balance bails out

__btrfs_balance() queues METADATA_REMAP chunks on a local list and
balances them only after the main loop, in balance_remap_chunks(), which
also frees the entries.  Every path that leaves the loop through the
error label skips that call: a pause or cancel request, a chunk tree
search error, should_balance_chunk() failing, btrfs_may_alloc_data_chunk()
or relocation errors, or the allocation of a later entry failing.  The
entries queued so far are leaked.

Free the leftover entries at the error label.  Nothing else needs undoing:
the block group lookup, the reference and the read-only count are all
taken inside balance_remap_chunks(), so a queued entry holds no block
group and none is left read-only.

Fixes: 81e5a4551c32 ("btrfs: allow balancing remap tree")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/volumes.c