]> git.hungrycats.org Git - linux/commit
btrfs: give back the limit of queued remap chunks when balance bails out
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:31 +0000 (00:32 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:31 +0000 (00:32 -0500)
commitd0f2ca5a3c8bed7bcbac5259c956322c3942411a
tree994f7aa8e977a600295ae518d2aca63ed348c57e
parentd0136e6493082d001aa33ed4174dae6062abb49a
btrfs: give back the limit of queued remap chunks when balance bails out

__btrfs_balance() does not relocate METADATA_REMAP chunks in its chunk
walk: it queues them and balances them all after the walk, in
balance_remap_chunks().  should_balance_chunk() selects them as metadata
chunks, and a metadata limit filter counts them down when it selects
them, like any other chunk.

A pause request ends the walk at the error label, which drops the queue:
the queued chunks are not balanced, but the metadata limit still counts
them.  The balance control stays in memory for the resume, which then
sees the chunks again and finds the limit already used up for them.  For
example, with -mlimit=1 and the remap chunk selected as the one metadata
chunk, a balance paused while it relocates the data chunks below the
remap chunk relocates no metadata chunk at all after the resume.

Add the dropped chunks back to the metadata limit (limit, or limit_max of
a range, whichever should_balance_chunk() counted down) at the error
label.  For the other ways out through the label (cancel, errors) the
balance ends and the count does not matter.

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