git: 88a795e80c03 - main - sys/fs: do not report blocks allocated for synthetic file systems

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Tue, 25 Apr 2023 08:00:37 UTC
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/src/commit/?id=88a795e80c03ff1d960d830ee273589664ab06cc

commit 88a795e80c03ff1d960d830ee273589664ab06cc
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2023-04-25 07:40:05 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2023-04-25 07:59:15 +0000

    sys/fs: do not report blocks allocated for synthetic file systems
    
    The pseudo file systems (devfs, fdescfs, procfs, etc.) report total
    and available blocks and inodes despite being synthetic with no
    underlying storage device to which those values could be applied.
    
    The current code of these file systems tends to report a fixed number
    of total blocks but no free blocks, and in the case of procfs,
    libprocfs, linsysfs also no free inodes.
    
    This can be irritating in e.g. the "df" output, since 100% of the
    resources seem to be in use, but it can also create warnings in
    monitoring tools used for capacity management.
    
    This patch makes these file systems return the same value for the
    total and free parameters, leading to 0% in use being displayed by
    "df". Since there is no resource that can be exhausted, this appears
    to be a sensible result.
    
    Reviewed by:    mckusick
    Differential Revision:  https://reviews.freebsd.org/D39442
---
 sys/fs/devfs/devfs_vfsops.c   | 4 ++--
 sys/fs/fdescfs/fdesc_vfsops.c | 4 ++--
 sys/fs/pseudofs/pseudofs.c    | 8 ++++----
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/sys/fs/devfs/devfs_vfsops.c b/sys/fs/devfs/devfs_vfsops.c
index 56297578ec2a..0fac2b68e2e1 100644
--- a/sys/fs/devfs/devfs_vfsops.c
+++ b/sys/fs/devfs/devfs_vfsops.c
@@ -230,8 +230,8 @@ devfs_statfs(struct mount *mp, struct statfs *sbp)
 	sbp->f_bsize = DEV_BSIZE;
 	sbp->f_iosize = DEV_BSIZE;
 	sbp->f_blocks = 2;		/* 1K to keep df happy */
-	sbp->f_bfree = 0;
-	sbp->f_bavail = 0;
+	sbp->f_bfree = 2;
+	sbp->f_bavail = 2;
 	sbp->f_files = 0;
 	sbp->f_ffree = 0;
 	return (0);
diff --git a/sys/fs/fdescfs/fdesc_vfsops.c b/sys/fs/fdescfs/fdesc_vfsops.c
index edc2cdd61847..2961c3bf6224 100644
--- a/sys/fs/fdescfs/fdesc_vfsops.c
+++ b/sys/fs/fdescfs/fdesc_vfsops.c
@@ -223,8 +223,8 @@ fdesc_statfs(struct mount *mp, struct statfs *sbp)
 	sbp->f_bsize = DEV_BSIZE;
 	sbp->f_iosize = DEV_BSIZE;
 	sbp->f_blocks = 2;		/* 1K to keep df happy */
-	sbp->f_bfree = 0;
-	sbp->f_bavail = 0;
+	sbp->f_bfree = 2;
+	sbp->f_bavail = 2;
 	sbp->f_files = lim + 1;		/* Allow for "." */
 	sbp->f_ffree = freefd;		/* See comments above */
 	return (0);
diff --git a/sys/fs/pseudofs/pseudofs.c b/sys/fs/pseudofs/pseudofs.c
index 29071b34bd06..15a714e23bc6 100644
--- a/sys/fs/pseudofs/pseudofs.c
+++ b/sys/fs/pseudofs/pseudofs.c
@@ -379,10 +379,10 @@ pfs_mount(struct pfs_info *pi, struct mount *mp)
 	vfs_mountedfrom(mp, pi->pi_name);
 	sbp->f_bsize = PAGE_SIZE;
 	sbp->f_iosize = PAGE_SIZE;
-	sbp->f_blocks = 1;
-	sbp->f_bfree = 0;
-	sbp->f_bavail = 0;
-	sbp->f_files = 1;
+	sbp->f_blocks = 2;
+	sbp->f_bfree = 2;
+	sbp->f_bavail = 2;
+	sbp->f_files = 0;
 	sbp->f_ffree = 0;
 
 	return (0);