]> git.dujemihanovic.xyz Git - linux.git/commit
btrfs: zoned: fix zone_unusable accounting on making block group read-write again
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 15 Feb 2023 00:18:02 +0000 (09:18 +0900)
committerDavid Sterba <dsterba@suse.com>
Mon, 29 Jul 2024 17:21:19 +0000 (19:21 +0200)
commit8cd44dd1d17a23d5cc8c443c659ca57aa76e2fa5
tree0f3e91d595360d715d0d087a4413a1db817bdd61
parentd89c285d28491d8f10534c262ac9e6bdcbe1b4d2
btrfs: zoned: fix zone_unusable accounting on making block group read-write again

When btrfs makes a block group read-only, it adds all free regions in the
block group to space_info->bytes_readonly. That free space excludes
reserved and pinned regions. OTOH, when btrfs makes the block group
read-write again, it moves all the unused regions into the block group's
zone_unusable. That unused region includes reserved and pinned regions.
As a result, it counts too much zone_unusable bytes.

Fortunately (or unfortunately), having erroneous zone_unusable does not
affect the calculation of space_info->bytes_readonly, because free
space (num_bytes in btrfs_dec_block_group_ro) calculation is done based on
the erroneous zone_unusable and it reduces the num_bytes just to cancel the
error.

This behavior can be easily discovered by adding a WARN_ON to check e.g,
"bg->pinned > 0" in btrfs_dec_block_group_ro(), and running fstests test
case like btrfs/282.

Fix it by properly considering pinned and reserved in
btrfs_dec_block_group_ro(). Also, add a WARN_ON and introduce
btrfs_space_info_update_bytes_zone_unusable() to catch a similar mistake.

Fixes: 169e0da91a21 ("btrfs: zoned: track unusable bytes for zones")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/space-info.c
fs/btrfs/space-info.h
include/trace/events/btrfs.h