diff mbox series

btrfs: prevent __btrfs_dump_space_info() to underflow its free space

Message ID 20210916124329.65141-1-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: prevent __btrfs_dump_space_info() to underflow its free space | expand

Commit Message

Qu Wenruo Sept. 16, 2021, 12:43 p.m. UTC
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.

Reported-by: Eli V <eliventer@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CAJtFHUSy4zgyhf-4d9T+KdJp9w=UgzC2A0V=VtmaeEpcGgm1-Q@mail.gmail.com/
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/space-info.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Anand Jain Sept. 16, 2021, 1:40 p.m. UTC | #1
On 16/09/2021 20:43, Qu Wenruo wrote:
> 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.

  Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks, Anand

> 
> Reported-by: Eli V <eliventer@gmail.com>
> Link: https://lore.kernel.org/linux-btrfs/CAJtFHUSy4zgyhf-4d9T+KdJp9w=UgzC2A0V=VtmaeEpcGgm1-Q@mail.gmail.com/
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   fs/btrfs/space-info.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index 5ada02e0e629..e9a562d96ba6 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -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",
>
David Sterba Sept. 17, 2021, 10:37 a.m. UTC | #2
On Thu, Sep 16, 2021 at 08:43:29PM +0800, Qu Wenruo wrote:
> 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.
> 
> Reported-by: Eli V <eliventer@gmail.com>
> Link: https://lore.kernel.org/linux-btrfs/CAJtFHUSy4zgyhf-4d9T+KdJp9w=UgzC2A0V=VtmaeEpcGgm1-Q@mail.gmail.com/
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 5ada02e0e629..e9a562d96ba6 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -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",