Skip to content

Commit f87d3af

Browse files
committed
ext4: don't over-report free space or inodes in statvfs
This fixes an analogus bug that was fixed in xfs in commit 4b8d867 ("xfs: don't over-report free space or inodes in statvfs") where statfs can report misleading / incorrect information where project quota is enabled, and the free space is less than the remaining quota. This commit will resolve a test failure in generic/762 which tests for this bug. Cc: stable@kernel.org Fixes: 689c958 ("ext4: add project quota support") Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
1 parent 5f1cf94 commit f87d3af

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

fs/ext4/super.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,22 +6820,29 @@ static int ext4_statfs_project(struct super_block *sb,
68206820
dquot->dq_dqb.dqb_bhardlimit);
68216821
limit >>= sb->s_blocksize_bits;
68226822

6823-
if (limit && buf->f_blocks > limit) {
6823+
if (limit) {
6824+
uint64_t remaining = 0;
6825+
68246826
curblock = (dquot->dq_dqb.dqb_curspace +
68256827
dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
6826-
buf->f_blocks = limit;
6827-
buf->f_bfree = buf->f_bavail =
6828-
(buf->f_blocks > curblock) ?
6829-
(buf->f_blocks - curblock) : 0;
6828+
if (limit > curblock)
6829+
remaining = limit - curblock;
6830+
6831+
buf->f_blocks = min(buf->f_blocks, limit);
6832+
buf->f_bfree = min(buf->f_bfree, remaining);
6833+
buf->f_bavail = min(buf->f_bavail, remaining);
68306834
}
68316835

68326836
limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
68336837
dquot->dq_dqb.dqb_ihardlimit);
6834-
if (limit && buf->f_files > limit) {
6835-
buf->f_files = limit;
6836-
buf->f_ffree =
6837-
(buf->f_files > dquot->dq_dqb.dqb_curinodes) ?
6838-
(buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0;
6838+
if (limit) {
6839+
uint64_t remaining = 0;
6840+
6841+
if (limit > dquot->dq_dqb.dqb_curinodes)
6842+
remaining = limit - dquot->dq_dqb.dqb_curinodes;
6843+
6844+
buf->f_files = min(buf->f_files, limit);
6845+
buf->f_ffree = min(buf->f_ffree, remaining);
68396846
}
68406847

68416848
spin_unlock(&dquot->dq_dqb_lock);

0 commit comments

Comments
 (0)