]> git.hungrycats.org Git - linux/commit
btrfs: zoned: only change active zone counter on successful (de)activation
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Wed, 9 Sep 2026 06:47:25 +0000 (08:47 +0200)
committerJohannes Thumshirn <johannes.thumshirn@wdc.com>
Wed, 21 Oct 2026 08:03:34 +0000 (10:03 +0200)
commit0be761ecf1a9cb32ce3bfd9e0469a331b9920483
tree00e4424b6802cbe68ea45f473bab0699097134b2
parentfe5627eaeeadd3faa2ec0d510c87f329d6b96b56
btrfs: zoned: only change active zone counter on successful (de)activation

btrfs_zone_activate() unconditionally decrements the reserved_active_zones
counter regardless if btrfs_dev_set_active_zone() fails to set the zone
active, i.e. because it raced with another call that already set the bit
in the bitmask, or not.

This can lead to a double decrement of the counter in case the bit has
already been set.

Only decrement the counter *iff* btrfs_dev_set_active_zone() successfully
marked the zone in the bitmap.

Mirror this behaviour when clearing the bit again.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Fixes: a7e1ac7bdc5a ("btrfs: zoned: reserve zones for an active metadata/system block group")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
fs/btrfs/zoned.c