git: 3f539826e12e - stable/13 - nfsd: Fix f_bavail and f_ffree for NFSv4 when negative

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Wed, 24 Nov 2021 22:34:53 UTC
The branch stable/13 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=3f539826e12e3177655add03f6297f49019ac08b

commit 3f539826e12e3177655add03f6297f49019ac08b
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2021-11-08 20:59:31 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2021-11-24 22:31:55 +0000

    nfsd: Fix f_bavail and f_ffree for NFSv4 when negative
    
    Since the NFS Space_available and Files_available are unsigned,
    the NFSv3 server sets them to 0 when negative, so that they
    do not appear to be large positive values for non-FreeBSD clients.
    This patch fixes the NFSv4 server to do the same.
    
    Found during a recent IEFT NFSv4 working group testing event.
    
    (cherry picked from commit d70ca5b00eede3367ce659a03b2f9cc9729cd0dd)
---
 sys/fs/nfs/nfs_commonsubs.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/fs/nfs/nfs_commonsubs.c b/sys/fs/nfs/nfs_commonsubs.c
index c8534982ee0e..144b2e215496 100644
--- a/sys/fs/nfs/nfs_commonsubs.c
+++ b/sys/fs/nfs/nfs_commonsubs.c
@@ -2511,6 +2511,17 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp,
 			}
 			NFSCLRSTATFS_ATTRBIT(retbitp);
 		}
+		/*
+		 * Since NFS handles these values as unsigned on the
+		 * wire, there is no way to represent negative values,
+		 * so set them to 0. Without this, they will appear
+		 * to be very large positive values for clients like
+		 * Solaris10.
+		 */
+		if (fs->f_bavail < 0)
+			fs->f_bavail = 0;
+		if (fs->f_ffree < 0)
+			fs->f_ffree = 0;
 	}
 #endif