mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-11 11:55:28 +02:00
btrfs: zoned: fix initial free space detection
commitb9fd2affe4
upstream. When creating a new block group, it calls btrfs_add_new_free_space() to add the entire block group range into the free space accounting. __btrfs_add_free_space_zoned() checks if size == block_group->length to detect the initial free space adding, and proceed that case properly. However, if the zone_capacity == zone_size and the over-write speed is fast enough, the entire zone can be over-written within one transaction. That confuses __btrfs_add_free_space_zoned() to handle it as an initial free space accounting. As a result, that block group becomes a strange state: 0 used bytes, 0 zone_unusable bytes, but alloc_offset == zone_capacity (no allocation anymore). The initial free space accounting can properly be checked by checking alloc_offset too. Fixes:98173255bd
("btrfs: zoned: calculate free space from zone capacity") CC: stable@vger.kernel.org # 6.1+ Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
91878a2bc8
commit
a0bfefcb61
|
@ -2695,7 +2695,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
|
||||||
u64 offset = bytenr - block_group->start;
|
u64 offset = bytenr - block_group->start;
|
||||||
u64 to_free, to_unusable;
|
u64 to_free, to_unusable;
|
||||||
int bg_reclaim_threshold = 0;
|
int bg_reclaim_threshold = 0;
|
||||||
bool initial = (size == block_group->length);
|
bool initial = ((size == block_group->length) && (block_group->alloc_offset == 0));
|
||||||
u64 reclaimable_unusable;
|
u64 reclaimable_unusable;
|
||||||
|
|
||||||
WARN_ON(!initial && offset + size > block_group->zone_capacity);
|
WARN_ON(!initial && offset + size > block_group->zone_capacity);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user