]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: move existing remaps before relocating block group
authorMark Harmstone <mark@harmstone.com>
Wed, 7 Jan 2026 14:09:12 +0000 (14:09 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Feb 2026 06:54:35 +0000 (07:54 +0100)
commitbbea42dfb91f6901243958c83f26bbbd3a4a85fa
tree64d6792d7a7880acd2024c77566735eea6f44746
parentb56f35560b82e7f8d79aa9ee72720b06639a473c
btrfs: move existing remaps before relocating block group

If when relocating a block group we find that `remap_bytes` > 0 in its
block group item, that means that it has been the destination block
group for another that has been remapped.

We need to search the remap tree for any remap backrefs within this
range, and move the data to a third block group. This is because
otherwise btrfs_translate_remap() could end up following an unbounded
chain of remaps, which would only get worse over time.

We only relocate one block group at a time, so `remap_bytes` will only
ever go down while we are doing this. Once we're finished we set the
REMAPPED flag on the block group, which will permanently prevent any
other data from being moved to within it.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Mark Harmstone <mark@harmstone.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/bio.c
fs/btrfs/bio.h
fs/btrfs/extent-tree.c
fs/btrfs/relocation.c