Skip to content

Commit 105e7e3

Browse files
committed
Merge: Fix over reporting of free space or inodes in statvfs
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/851 JIRA: https://issues.redhat.com/browse/RHEL-87016 This requires the backport of a couple dependencies. Omitted-fix: f87d3af (ext4 counterpart, not relevant to xfs) Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> Approved-by: Bill O'Donnell <bodonnel@redhat.com> Approved-by: Brian Foster <bfoster@redhat.com> Approved-by: Andrey Albershteyn <aalbersh@redhat.com> Merged-by: Julio Faracco <jfaracco@redhat.com>
2 parents 1af8ab8 + 8507aa5 commit 105e7e3

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

fs/xfs/xfs_qm_bhv.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,41 @@
1919
STATIC void
2020
xfs_fill_statvfs_from_dquot(
2121
struct kstatfs *statp,
22+
struct xfs_inode *ip,
2223
struct xfs_dquot *dqp)
2324
{
25+
struct xfs_dquot_res *blkres = &dqp->q_blk;
2426
uint64_t limit;
2527

26-
limit = dqp->q_blk.softlimit ?
27-
dqp->q_blk.softlimit :
28-
dqp->q_blk.hardlimit;
29-
if (limit && statp->f_blocks > limit) {
30-
statp->f_blocks = limit;
31-
statp->f_bfree = statp->f_bavail =
32-
(statp->f_blocks > dqp->q_blk.reserved) ?
33-
(statp->f_blocks - dqp->q_blk.reserved) : 0;
28+
if (XFS_IS_REALTIME_MOUNT(ip->i_mount) &&
29+
(ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME)))
30+
blkres = &dqp->q_rtb;
31+
32+
limit = blkres->softlimit ?
33+
blkres->softlimit :
34+
blkres->hardlimit;
35+
if (limit) {
36+
uint64_t remaining = 0;
37+
38+
if (limit > blkres->reserved)
39+
remaining = limit - blkres->reserved;
40+
41+
statp->f_blocks = min(statp->f_blocks, limit);
42+
statp->f_bfree = min(statp->f_bfree, remaining);
43+
statp->f_bavail = min(statp->f_bavail, remaining);
3444
}
3545

3646
limit = dqp->q_ino.softlimit ?
3747
dqp->q_ino.softlimit :
3848
dqp->q_ino.hardlimit;
39-
if (limit && statp->f_files > limit) {
40-
statp->f_files = limit;
41-
statp->f_ffree =
42-
(statp->f_files > dqp->q_ino.reserved) ?
43-
(statp->f_files - dqp->q_ino.reserved) : 0;
49+
if (limit) {
50+
uint64_t remaining = 0;
51+
52+
if (limit > dqp->q_ino.reserved)
53+
remaining = limit - dqp->q_ino.reserved;
54+
55+
statp->f_files = min(statp->f_files, limit);
56+
statp->f_ffree = min(statp->f_ffree, remaining);
4457
}
4558
}
4659

@@ -61,7 +74,7 @@ xfs_qm_statvfs(
6174
struct xfs_dquot *dqp;
6275

6376
if (!xfs_qm_dqget(mp, ip->i_projid, XFS_DQTYPE_PROJ, false, &dqp)) {
64-
xfs_fill_statvfs_from_dquot(statp, dqp);
77+
xfs_fill_statvfs_from_dquot(statp, ip, dqp);
6578
xfs_qm_dqput(dqp);
6679
}
6780
}

fs/xfs/xfs_super.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,6 @@ xfs_fs_statfs(
873873
ffree = statp->f_files - (icount - ifree);
874874
statp->f_ffree = max_t(int64_t, ffree, 0);
875875

876-
877-
if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
878-
((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
879-
(XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
880-
xfs_qm_statvfs(ip, statp);
881-
882876
if (XFS_IS_REALTIME_MOUNT(mp) &&
883877
(ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
884878
s64 freertx;
@@ -888,6 +882,11 @@ xfs_fs_statfs(
888882
statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx);
889883
}
890884

885+
if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
886+
((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
887+
(XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
888+
xfs_qm_statvfs(ip, statp);
889+
891890
return 0;
892891
}
893892

0 commit comments

Comments
 (0)