Ext4: df: fix df to report reserved bytes in quota

Message ID 1525770043-36347-1-git-send-email-bo.liu@linux.alibaba.com
State New
Headers show
Series
  • Ext4: df: fix df to report reserved bytes in quota
Related show

Commit Message

Liu Bo May 8, 2018, 9 a.m.
Without quota, df takes both on-disk allocated blocks and dirty reserved
blocks as used, while with quota, df only takes on-disk allocated blocks
by reading quota's information.

To avoid confusing users, this fixes df to read quota's reservd bytes
also.

Signed-off-by: Qixuan Wu <qixuan.wu@linux.alibaba.com>
Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
 fs/ext4/super.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index eb104e8476f0..a49d3709c928 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5240,7 +5240,7 @@  static int ext4_statfs_project(struct super_block *sb,
 	struct kqid qid;
 	struct dquot *dquot;
 	u64 limit;
-	u64 curblock;
+	u64 curblock, rsvblock;
 
 	qid = make_kqid_projid(projid);
 	dquot = dqget(sb, qid);
@@ -5253,10 +5253,11 @@  static int ext4_statfs_project(struct super_block *sb,
 		 dquot->dq_dqb.dqb_bhardlimit) >> sb->s_blocksize_bits;
 	if (limit && buf->f_blocks > limit) {
 		curblock = dquot->dq_dqb.dqb_curspace >> sb->s_blocksize_bits;
+		rsvblock = dquot->dq_dqb.dqb_rsvspace >> sb->s_blocksize_bits;
 		buf->f_blocks = limit;
 		buf->f_bfree = buf->f_bavail =
-			(buf->f_blocks > curblock) ?
-			 (buf->f_blocks - curblock) : 0;
+			(buf->f_blocks > (curblock + rsvblock)) ?
+			 (buf->f_blocks - (curblock + rsvblock)) : 0;
 	}
 
 	limit = dquot->dq_dqb.dqb_isoftlimit ?