On Thu, Jun 17, 2021 at 01:56:18PM +0900, Naohiro Aota wrote:
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 commit fixes the issue by reordering the operations.
I've copied the 'fi df' output to changelog.
Fixes: 169e0da91a21 ("btrfs: zoned: track unusable bytes for zones") Cc: stable@vger.kernel.org # 5.12+ Signed-off-by: Naohiro Aota naohiro.aota@wdc.com
Added to misc-next, thanks.