Bug 1665990

Summary: df reports negative IUsed value for prjquota set directories.
Product: Red Hat Enterprise Linux 7 Reporter: Achilles Gaikwad <agaikwad>
Component: kernelAssignee: Bill O'Donnell <billodo>
kernel sub component: XFS QA Contact: Zorro Lang <zlang>
Status: CLOSED ERRATA Docs Contact:
Severity: medium    
Priority: unspecified CC: esandeen, fs-maint, xzhou
Version: 7.6   
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: kernel-3.10.0-1015.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1665968 Environment:
Last Closed: 2019-08-06 12:25:30 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1665968    
Bug Blocks:    

Description Achilles Gaikwad 2019-01-14 15:53:48 UTC
+++ This bug was initially created as a clone of Bug #1665968 +++

Description of problem:

df will report negative IUsed for a directory which has project quotas enabled.

df for the prjquota dir:
Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/loop7         53 -524229 524282     - /mnt

Version-Release number of selected component (if applicable):
4.18.0-32.el8.x86_64

How reproducible:
Always

Steps to Reproduce:

1. Create a repro.sh file with following contents and make it executable. 

#!/bin/bash
truncate -s1G foo.img 
mkfs.xfs -K -f foo.img > /dev/null 
mount foo.img /mnt/ -o prjquota 
mkdir -p /mnt/test 
xfs_quota -x -c 'project -s -p /mnt/test 42' /mnt
echo df before setting up limits
echo df for mnt
df -i /mnt/
echo df for prjquota dir
df -i /mnt/test
xfs_quota -x -c 'limit -p isoft=53 test-bug' /mnt
echo inode soft limits set for /mnt/test
xfs_quota -x -c report /mnt
echo df after setup for mnt: 
     df -i /mnt
echo df for the prjquota dir: 
     df -i /mnt/test/

echo unmounting
umount /mnt/

2. Execute the script. DF will show negative value

Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/loop7         53 -524229 524282     - /mnt
unmounting

Actual results:

Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/loop7         53 -524229 524282     - /mnt

Expected results:

Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/loop7         53     0      53     - /mnt


Additional info:

This bug has been fixed in commit the following commit 

$ git show de7243057e7cefa923fa5f467c0f1ec24eef41d2
commit de7243057e7cefa923fa5f467c0f1ec24eef41d2
Author: Ye Yin <dbyin>
Date:   Fri Nov 23 09:55:18 2018 -0800

    fs/xfs: fix f_ffree value for statfs when project quota is set
    
    When project is set, we should use inode limit minus the used count
    
    Signed-off-by: Ye Yin <dbyin>
    Reviewed-by: Darrick J. Wong <darrick.wong>
    Signed-off-by: Darrick J. Wong <darrick.wong>

diff --git a/fs/xfs/xfs_qm_bhv.c b/fs/xfs/xfs_qm_bhv.c
index 73a1d77ec187..3091e4bc04ef 100644
--- a/fs/xfs/xfs_qm_bhv.c
+++ b/fs/xfs/xfs_qm_bhv.c
@@ -40,7 +40,7 @@ xfs_fill_statvfs_from_dquot(
                statp->f_files = limit;
                statp->f_ffree =
                        (statp->f_files > dqp->q_res_icount) ?
-                        (statp->f_ffree - dqp->q_res_icount) : 0;
+                        (statp->f_files - dqp->q_res_icount) : 0;
        }
 }
 

After applying the patch, I am not able to reproduce the issue.

Comment 5 Bruno Meneguele 2019-03-07 20:21:06 UTC
Patch(es) committed on kernel-3.10.0-1015.el7

Comment 10 errata-xmlrpc 2019-08-06 12:25:30 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:2029