]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: handle discarding fully-remapped block groups
authorMark Harmstone <mark@harmstone.com>
Wed, 7 Jan 2026 14:09:16 +0000 (14:09 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Feb 2026 06:54:36 +0000 (07:54 +0100)
commit7cddbb4339d4be16aa5341e3a27e63c34d2c4e0d
treeded9f248dc1683e81c6e1636aa4ecd1f6df0b684
parent81e5a4551c32b454468f5aa3fe45dabb6bccb854
btrfs: handle discarding fully-remapped block groups

Discard normally works by iterating over the free-space entries of a
block group. This doesn't work for fully-remapped block groups, as we
removed their free-space entries when we started relocation.

For sync discard, call btrfs_discard_extent() when we commit the
transaction in which the last identity remap was removed.

For async discard, add a new function btrfs_trim_fully_remapped_block_group()
to be called by the discard worker, which iterates over the block
group's range using the normal async discard rules. Once we reach the
end, remove the chunk's stripes and device extents to get back its free
space.

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/block-group.c
fs/btrfs/block-group.h
fs/btrfs/discard.c
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/free-space-cache.h