]> git.hungrycats.org Git - linux/commit
btrfs: free queued remap chunks when balance bails out misc-next/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>
Mon, 2 Nov 2026 02:11:50 +0000 (21:11 -0500)
commitd0136e6493082d001aa33ed4174dae6062abb49a
tree68f58a5bfe0c9f57f5eba5dd190f24101d409c37
parent83cd81353093be02aa7e60874c413ec340e55bce
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