]> git.hungrycats.org Git - linux/commitdiff
btrfs: zoned: avoid underflow of space info bytes_zone_unusable
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Fri, 11 Sep 2026 11:41:12 +0000 (13:41 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:17 +0000 (21:36 +0100)
The two functions btrfs_free_reserved_bytes() and
btrfs_reset_unused_block_groups() both manipulate
space_info->bytes_zone_unusable without using the accessor function
btrfs_space_info_update_bytes_zone_unusable() potentially risking an
underflow (in case of btrfs_reset_unused_block_groups()).

Use btrfs_space_info_update_bytes_zone_unusable() in both function, in
the case of btrfs_free_reserved_bytes() it is mostly for documenting
purposes.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/zoned.c

index f2b55ffbdaef932b817c042c773ec5913636658d..f1c663e81d9d4310f026e108ecd797916576c688 100644 (file)
@@ -3727,7 +3727,7 @@ void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes,
        if (bg_ro)
                space_info->bytes_readonly += num_bytes;
        else if (btrfs_is_zoned(cache->fs_info))
-               space_info->bytes_zone_unusable += num_bytes;
+               btrfs_space_info_update_bytes_zone_unusable(space_info, num_bytes);
 
        space_info->bytes_reserved -= num_bytes;
        space_info->max_extent_size = 0;
index be00c3c76df9284f55e0562fc868995f84fa63e7..c0bd5e0868867f01d51be558956fd26dc9818af9 100644 (file)
@@ -3231,7 +3231,7 @@ int btrfs_reset_unused_block_groups(struct btrfs_space_info *space_info, u64 num
                ASSERT(reclaimed == bg->zone_capacity,
                       "reclaimed=%llu bg->zone_capacity=%llu", reclaimed, bg->zone_capacity);
                bg->free_space_ctl->free_space += reclaimed;
-               space_info->bytes_zone_unusable -= reclaimed;
+               btrfs_space_info_update_bytes_zone_unusable(space_info, -reclaimed);
                spin_unlock(&bg->lock);
                btrfs_return_free_space(space_info, reclaimed);
                spin_unlock(&space_info->lock);