[Devel] [PATCH vz9 02/10] ext4: Teach statfs to report reduced disk usage

Konstantin Khorenko khorenko at virtuozzo.com
Thu Nov 28 19:51:46 MSK 2024


From: "Maxim V. Patlasov" <MPatlasov at 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 at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
Feature: fs/ext4: fast online shrink support
---
 fs/ext4/super.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index c5aef54cc07b..f93fd231a459 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -6867,6 +6867,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;
 }
 
-- 
2.43.5



More information about the Devel mailing list