Skip to content

Commit c07ec83

Browse files
tytsogregkh
authored andcommitted
ext4: don't over-report free space or inodes in statvfs
commit f87d3af7419307ae26e705a2b2db36140db367a2 upstream. This fixes an analogus bug that was fixed in xfs in commit 4b8d867ca6e2 ("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: [email protected] Fixes: 689c958 ("ext4: add project quota support") Signed-off-by: Theodore Ts'o <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cf18760 commit c07ec83

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
@@ -6685,22 +6685,29 @@ static int ext4_statfs_project(struct super_block *sb,
66856685
dquot->dq_dqb.dqb_bhardlimit);
66866686
limit >>= sb->s_blocksize_bits;
66876687

6688-
if (limit && buf->f_blocks > limit) {
6688+
if (limit) {
6689+
uint64_t remaining = 0;
6690+
66896691
curblock = (dquot->dq_dqb.dqb_curspace +
66906692
dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
6691-
buf->f_blocks = limit;
6692-
buf->f_bfree = buf->f_bavail =
6693-
(buf->f_blocks > curblock) ?
6694-
(buf->f_blocks - curblock) : 0;
6693+
if (limit > curblock)
6694+
remaining = limit - curblock;
6695+
6696+
buf->f_blocks = min(buf->f_blocks, limit);
6697+
buf->f_bfree = min(buf->f_bfree, remaining);
6698+
buf->f_bavail = min(buf->f_bavail, remaining);
66956699
}
66966700

66976701
limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
66986702
dquot->dq_dqb.dqb_ihardlimit);
6699-
if (limit && buf->f_files > limit) {
6700-
buf->f_files = limit;
6701-
buf->f_ffree =
6702-
(buf->f_files > dquot->dq_dqb.dqb_curinodes) ?
6703-
(buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0;
6703+
if (limit) {
6704+
uint64_t remaining = 0;
6705+
6706+
if (limit > dquot->dq_dqb.dqb_curinodes)
6707+
remaining = limit - dquot->dq_dqb.dqb_curinodes;
6708+
6709+
buf->f_files = min(buf->f_files, limit);
6710+
buf->f_ffree = min(buf->f_ffree, remaining);
67046711
}
67056712

67066713
spin_unlock(&dquot->dq_dqb_lock);

0 commit comments

Comments
 (0)