diff mbox series

btrfs: properly report 0 avail for very full file systems

Message ID a9e6b02e9eb7a0532c401a898661b0511c31d0e8.1695047676.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs: properly report 0 avail for very full file systems | expand

Commit Message

Josef Bacik Sept. 18, 2023, 2:34 p.m. UTC
A user reported some issues with smaller file systems that get very
full.  While investigating this issue I noticed that df wasn't showing
100% full, despite having 0 chunk space and having < 1mib of available
metadata space.

This turns out to be an overflow issue, we're doing

total_available_metadata_space - SZ_4M < global_block_rsv_size

to determine if there's not enough space to make metadata allocations,
which overflows if total_available_metadata_space is < 4M.  Fix this by
checking to see if our available space is greater than the 4M threshold.
This makes df properly report 100% usage on the file system.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/super.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Sterba Sept. 18, 2023, 9:20 p.m. UTC | #1
On Mon, Sep 18, 2023 at 10:34:51AM -0400, Josef Bacik wrote:
> A user reported some issues with smaller file systems that get very
> full.  While investigating this issue I noticed that df wasn't showing
> 100% full, despite having 0 chunk space and having < 1mib of available
> metadata space.
> 
> This turns out to be an overflow issue, we're doing
> 
> total_available_metadata_space - SZ_4M < global_block_rsv_size
> 
> to determine if there's not enough space to make metadata allocations,
> which overflows if total_available_metadata_space is < 4M.  Fix this by
> checking to see if our available space is greater than the 4M threshold.
> This makes df properly report 100% usage on the file system.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index cffdd6f7f8e8..470ca9238544 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2117,7 +2117,8 @@  static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	 * calculated f_bavail.
 	 */
 	if (!mixed && block_rsv->space_info->full &&
-	    total_free_meta - thresh < block_rsv->size)
+	    (total_free_meta < thresh ||
+	     total_free_meta - thresh < block_rsv->size))
 		buf->f_bavail = 0;
 
 	buf->f_type = BTRFS_SUPER_MAGIC;