Skip to content

Commit 0619b79

Browse files
adam900710kdave
authored andcommitted
btrfs: prevent __btrfs_dump_space_info() to underflow its free space
It's not uncommon where __btrfs_dump_space_info() gets called under over-commit situations. In that case free space would underflow as total allocated space is not enough to handle all the over-committed space. Such underflow values can sometimes cause confusion for users enabled enospc_debug mount option, and takes some seconds for developers to convert the underflow value to signed result. Just output the free space as s64 to avoid such problem. Reported-by: Eli V <[email protected]> Link: https://lore.kernel.org/linux-btrfs/CAJtFHUSy4zgyhf-4d9T+KdJp9w=UgzC2A0V=VtmaeEpcGgm1-Q@mail.gmail.com/ CC: [email protected] # 5.4+ Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6b225ba commit 0619b79

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/btrfs/space-info.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,10 @@ static void __btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
414414
{
415415
lockdep_assert_held(&info->lock);
416416

417-
btrfs_info(fs_info, "space_info %llu has %llu free, is %sfull",
417+
/* The free space could be negative in case of overcommit */
418+
btrfs_info(fs_info, "space_info %llu has %lld free, is %sfull",
418419
info->flags,
419-
info->total_bytes - btrfs_space_info_used(info, true),
420+
(s64)(info->total_bytes - btrfs_space_info_used(info, true)),
420421
info->full ? "" : "not ");
421422
btrfs_info(fs_info,
422423
"space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu zone_unusable=%llu",

0 commit comments

Comments
 (0)