Skip to content

Commit d55966c

Browse files
josefbacikkdave
authored andcommitted
btrfs: do not zero f_bavail if we have available space
There was some logic added a while ago to clear out f_bavail in statfs() if we did not have enough free metadata space to satisfy our global reserve. This was incorrect at the time, however didn't really pose a problem for normal file systems because we would often allocate chunks if we got this low on free metadata space, and thus wouldn't really hit this case unless we were actually full. Fast forward to today and now we are much better about not allocating metadata chunks all of the time. Couple this with d792b0f ("btrfs: always reserve our entire size for the global reserve") which now means we'll easily have a larger global reserve than our free space, we are now more likely to trip over this while still having plenty of space. Fix this by skipping this logic if the global rsv's space_info is not full. space_info->full is 0 unless we've attempted to allocate a chunk for that space_info and that has failed. If this happens then the space for the global reserve is definitely sacred and we need to report b_avail == 0, but before then we can just use our calculated b_avail. Reported-by: Martin Steigerwald <[email protected]> Fixes: ca8a51b ("btrfs: statfs: report zero available if metadata are exhausted") CC: [email protected] # 4.5+ Reviewed-by: Qu Wenruo <[email protected]> Tested-By: Martin Steigerwald <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9722b10 commit d55966c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/btrfs/super.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,15 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
21352135
*/
21362136
thresh = SZ_4M;
21372137

2138-
if (!mixed && total_free_meta - thresh < block_rsv->size)
2138+
/*
2139+
* We only want to claim there's no available space if we can no longer
2140+
* allocate chunks for our metadata profile and our global reserve will
2141+
* not fit in the free metadata space. If we aren't ->full then we
2142+
* still can allocate chunks and thus are fine using the currently
2143+
* calculated f_bavail.
2144+
*/
2145+
if (!mixed && block_rsv->space_info->full &&
2146+
total_free_meta - thresh < block_rsv->size)
21392147
buf->f_bavail = 0;
21402148

21412149
buf->f_type = BTRFS_SUPER_MAGIC;

0 commit comments

Comments
 (0)