Skip to contentSkip to conversation

btrfs: prevent __btrfs_dump_space_info() to underflow its free space

PATCH In review Qu Wenruo 3 participants 3 messages Sep 16, 2021 – Sep 17, 2021 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: prevent __btrfs_dump_space_info() to underflow its free space

It's not uncommon where __btrfs_dump_space_info() get 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.

---
 fs/btrfs/space-info.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/space-info.c +2 -2
index 5ada02e0e629..e9a562d96ba6 100644
@@ -414,9 +414,9 @@ static void __btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
 {
 	lockdep_assert_held(&info->lock);
 
-	btrfs_info(fs_info, "space_info %llu has %llu free, is %sfull",
+	btrfs_info(fs_info, "space_info %llu has %lld free, is %sfull",
 		   info->flags,
-		   info->total_bytes - btrfs_space_info_used(info, true),
+		   (s64)(info->total_bytes - btrfs_space_info_used(info, true)),
 		   info->full ? "" : "not ");
 	btrfs_info(fs_info,
 		"space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu zone_unusable=%llu",
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Qu Wenruo

It's not uncommon where __btrfs_dump_space_info() get 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.

Yeah. I don't see any reason not to.

Thanks, Anand

Quoted 25 lines
---
  fs/btrfs/space-info.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/space-info.c +2 -2
index 5ada02e0e629..e9a562d96ba6 100644
@@ -414,9 +414,9 @@ static void __btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
  {
  	lockdep_assert_held(&info->lock);
 
-	btrfs_info(fs_info, "space_info %llu has %llu free, is %sfull",
+	btrfs_info(fs_info, "space_info %llu has %lld free, is %sfull",
  		   info->flags,
-		   info->total_bytes - btrfs_space_info_used(info, true),
+		   (s64)(info->total_bytes - btrfs_space_info_used(info, true)),
  		   info->full ? "" : "not ");
  	btrfs_info(fs_info,
  		"space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu zone_unusable=%llu",
#2 lore raw
In reply to Qu Wenruo
Quoted 10 lines · Qu Wenruo

It's not uncommon where __btrfs_dump_space_info() get 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.

Quoted 5 lines

Just output the free space as s64 to avoid such problem.

Added to misc-next, thanks.