Skip to content

Commit f9f28e5

Browse files
naotakdave
authored andcommitted
btrfs: zoned: fix negative space_info->bytes_readonly
Consider we have a using block group on zoned btrfs. |<- ZU ->|<- used ->|<---free--->| `- Alloc offset ZU: Zone unusable Marking the block group read-only will migrate the zone unusable bytes to the read-only bytes. So, we will have this. |<- RO ->|<- used ->|<--- RO --->| RO: Read only When marking it back to read-write, btrfs_dec_block_group_ro() subtracts the above "RO" bytes from the space_info->bytes_readonly. And, it moves the zone unusable bytes back and again subtracts those bytes from the space_info->bytes_readonly, leading to negative bytes_readonly. This can be observed in the output as eg.: Data, single: total=512.00MiB, used=165.21MiB, zone_unusable=16.00EiB Data, single: total=536870912, used=173256704, zone_unusable=18446744073603186688 This commit fixes the issue by reordering the operations. Link: naota#37 Reported-by: David Sterba <[email protected]> Fixes: 169e0da ("btrfs: zoned: track unusable bytes for zones") CC: [email protected] # 5.12+ Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent aefd7f7 commit f9f28e5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/btrfs/block-group.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,16 +2442,16 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
24422442
spin_lock(&sinfo->lock);
24432443
spin_lock(&cache->lock);
24442444
if (!--cache->ro) {
2445-
num_bytes = cache->length - cache->reserved -
2446-
cache->pinned - cache->bytes_super -
2447-
cache->zone_unusable - cache->used;
2448-
sinfo->bytes_readonly -= num_bytes;
24492445
if (btrfs_is_zoned(cache->fs_info)) {
24502446
/* Migrate zone_unusable bytes back */
24512447
cache->zone_unusable = cache->alloc_offset - cache->used;
24522448
sinfo->bytes_zone_unusable += cache->zone_unusable;
24532449
sinfo->bytes_readonly -= cache->zone_unusable;
24542450
}
2451+
num_bytes = cache->length - cache->reserved -
2452+
cache->pinned - cache->bytes_super -
2453+
cache->zone_unusable - cache->used;
2454+
sinfo->bytes_readonly -= num_bytes;
24552455
list_del_init(&cache->ro_list);
24562456
}
24572457
spin_unlock(&cache->lock);

0 commit comments

Comments
 (0)