Skip to content

Commit c891bc9

Browse files
tytsogregkh
authored andcommitted
ext4: don't over-report free space or inodes in statvfs
commit f87d3af upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5a57f8e commit c891bc9

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

fs/ext4/super.c

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

6816-
if (limit && buf->f_blocks > limit) {
6816+
if (limit) {
6817+
uint64_t remaining = 0;
6818+
68176819
curblock = (dquot->dq_dqb.dqb_curspace +
68186820
dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
6819-
buf->f_blocks = limit;
6820-
buf->f_bfree = buf->f_bavail =
6821-
(buf->f_blocks > curblock) ?
6822-
(buf->f_blocks - curblock) : 0;
6821+
if (limit > curblock)
6822+
remaining = limit - curblock;
6823+
6824+
buf->f_blocks = min(buf->f_blocks, limit);
6825+
buf->f_bfree = min(buf->f_bfree, remaining);
6826+
buf->f_bavail = min(buf->f_bavail, remaining);
68236827
}
68246828

68256829
limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
68266830
dquot->dq_dqb.dqb_ihardlimit);
6827-
if (limit && buf->f_files > limit) {
6828-
buf->f_files = limit;
6829-
buf->f_ffree =
6830-
(buf->f_files > dquot->dq_dqb.dqb_curinodes) ?
6831-
(buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0;
6831+
if (limit) {
6832+
uint64_t remaining = 0;
6833+
6834+
if (limit > dquot->dq_dqb.dqb_curinodes)
6835+
remaining = limit - dquot->dq_dqb.dqb_curinodes;
6836+
6837+
buf->f_files = min(buf->f_files, limit);
6838+
buf->f_ffree = min(buf->f_ffree, remaining);
68326839
}
68336840

68346841
spin_unlock(&dquot->dq_dqb_lock);

0 commit comments

Comments
 (0)