[rh8,3/9] ext4: Teach statfs to report reduced disk usage

Submitted by Konstantin Khorenko on March 3, 2021, 4:31 p.m.

Details

Message ID 20210303163118.294216-4-khorenko@virtuozzo.com
State New
Series "ext4: Port balloon code and other ext4 fixes"
Headers show

Commit Message

Konstantin Khorenko March 3, 2021, 4:31 p.m.
From: "Maxim V. Patlasov" <MPatlasov@parallels.com>

The magic 9 in there came from 512 bytes - the i_blocks is accounted
in these units in any case.

(cherry picked from vz7 commit 4b10f27018d330d9e03e932a98a41a3e55da81fb)
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/ext4/super.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 663fb3ea9315..7a41751364ab 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5818,6 +5818,22 @@  static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
 	    sb_has_quota_limits_enabled(sb, PRJQUOTA))
 		ext4_statfs_project(sb, EXT4_I(dentry->d_inode)->i_projid, buf);
 #endif
+
+	if (sbi->s_balloon_ino) {
+		struct ext4_inode_info *ei;
+		blkcnt_t balloon_blocks;
+
+		balloon_blocks = sbi->s_balloon_ino->i_blocks;
+		ei = EXT4_I(sbi->s_balloon_ino);
+		spin_lock(&ei->i_block_reservation_lock);
+		balloon_blocks += ei->i_reserved_data_blocks;
+		spin_unlock(&ei->i_block_reservation_lock);
+
+		BUG_ON(sbi->s_balloon_ino->i_blkbits < 9);
+		buf->f_blocks -= balloon_blocks >>
+				 (sbi->s_balloon_ino->i_blkbits - 9);
+	}
+
 	return 0;
 }