Patch "xfs: don't over-report free space or inodes in statvfs" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    xfs: don't over-report free space or inodes in statvfs

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     xfs-don-t-over-report-free-space-or-inodes-in-statvf.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 35cf2745ab54f703c778943469cba35671d51a93
Author: Darrick J. Wong <djwong@xxxxxxxxxx>
Date:   Thu Dec 12 14:37:56 2024 -0800

    xfs: don't over-report free space or inodes in statvfs
    
    [ Upstream commit 4b8d867ca6e2fc6d152f629fdaf027053b81765a ]
    
    Emmanual Florac reports a strange occurrence when project quota limits
    are enabled, free space is lower than the remaining quota, and someone
    runs statvfs:
    
      # mkfs.xfs -f /dev/sda
      # mount /dev/sda /mnt -o prjquota
      # xfs_quota  -x -c 'limit -p bhard=2G 55' /mnt
      # mkdir /mnt/dir
      # xfs_io -c 'chproj 55' -c 'chattr +P' -c 'stat -vvvv' /mnt/dir
      # fallocate -l 19g /mnt/a
      # df /mnt /mnt/dir
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/sda         20G   20G  345M  99% /mnt
      /dev/sda        2.0G     0  2.0G   0% /mnt
    
    I think the bug here is that xfs_fill_statvfs_from_dquot unconditionally
    assigns to f_bfree without checking that the filesystem has enough free
    space to fill the remaining project quota.  However, this is a
    longstanding behavior of xfs so it's unclear what to do here.
    
    Cc: <stable@xxxxxxxxxxxxxxx> # v2.6.18
    Fixes: 932f2c323196c2 ("[XFS] statvfs component of directory/project quota support, code originally by Glen.")
    Reported-by: Emmanuel Florac <eflorac@xxxxxxxxxxxxxx>
    Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx>
    Reviewed-by: Christoph Hellwig <hch@xxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/xfs/xfs_qm_bhv.c b/fs/xfs/xfs_qm_bhv.c
index 268a07218c777..26b2c449f3c66 100644
--- a/fs/xfs/xfs_qm_bhv.c
+++ b/fs/xfs/xfs_qm_bhv.c
@@ -32,21 +32,28 @@ xfs_fill_statvfs_from_dquot(
 	limit = blkres->softlimit ?
 		blkres->softlimit :
 		blkres->hardlimit;
-	if (limit && statp->f_blocks > limit) {
-		statp->f_blocks = limit;
-		statp->f_bfree = statp->f_bavail =
-			(statp->f_blocks > blkres->reserved) ?
-			 (statp->f_blocks - blkres->reserved) : 0;
+	if (limit) {
+		uint64_t	remaining = 0;
+
+		if (limit > blkres->reserved)
+			remaining = limit - blkres->reserved;
+
+		statp->f_blocks = min(statp->f_blocks, limit);
+		statp->f_bfree = min(statp->f_bfree, remaining);
+		statp->f_bavail = min(statp->f_bavail, remaining);
 	}
 
 	limit = dqp->q_ino.softlimit ?
 		dqp->q_ino.softlimit :
 		dqp->q_ino.hardlimit;
-	if (limit && statp->f_files > limit) {
-		statp->f_files = limit;
-		statp->f_ffree =
-			(statp->f_files > dqp->q_ino.reserved) ?
-			 (statp->f_files - dqp->q_ino.reserved) : 0;
+	if (limit) {
+		uint64_t	remaining = 0;
+
+		if (limit > dqp->q_ino.reserved)
+			remaining = limit - dqp->q_ino.reserved;
+
+		statp->f_files = min(statp->f_files, limit);
+		statp->f_ffree = min(statp->f_ffree, remaining);
 	}
 }
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux