All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frank van der Linden <fllinden@amazon.com>
To: <linux-nfs@vger.kernel.org>, <anna.schumaker@netapp.com>,
	<trond.myklebust@hammerspace.com>, <dhowells@redhat.com>
Cc: Frank van der Linden <fllinden@amazon.com>
Subject: [PATCH] nfs: round down reported block numbers in statfs
Date: Thu, 10 Sep 2020 20:06:44 +0000	[thread overview]
Message-ID: <20200910200644.8165-1-fllinden@amazon.com> (raw)

nfs_statfs rounds up the numbers of blocks as computed
from the numbers the server return values.

This works out well if the client block size, which is
the same as wrsize, is smaller than or equal to the actual
filesystem block size on the server.

But, for NFS4, the size is usually larger (1M), meaning
that statfs reports more free space than actually is
available. This confuses, for example, fstest generic/103.

Given a choice between reporting too much or too little
space, the latter is the safer option, so don't round
up the number of blocks. This also simplifies the code.

Signed-off-by: Frank van der Linden <fllinden@amazon.com>
---
 fs/nfs/super.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 7a70287f21a2..45d368a5cc95 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -217,8 +217,6 @@ EXPORT_SYMBOL_GPL(nfs_client_for_each_server);
 int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct nfs_server *server = NFS_SB(dentry->d_sb);
-	unsigned char blockbits;
-	unsigned long blockres;
 	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
 	struct nfs_fsstat res;
 	int error = -ENOMEM;
@@ -241,26 +239,11 @@ int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 
 	buf->f_type = NFS_SUPER_MAGIC;
 
-	/*
-	 * Current versions of glibc do not correctly handle the
-	 * case where f_frsize != f_bsize.  Eventually we want to
-	 * report the value of wtmult in this field.
-	 */
-	buf->f_frsize = dentry->d_sb->s_blocksize;
-
-	/*
-	 * On most *nix systems, f_blocks, f_bfree, and f_bavail
-	 * are reported in units of f_frsize.  Linux hasn't had
-	 * an f_frsize field in its statfs struct until recently,
-	 * thus historically Linux's sys_statfs reports these
-	 * fields in units of f_bsize.
-	 */
 	buf->f_bsize = dentry->d_sb->s_blocksize;
-	blockbits = dentry->d_sb->s_blocksize_bits;
-	blockres = (1 << blockbits) - 1;
-	buf->f_blocks = (res.tbytes + blockres) >> blockbits;
-	buf->f_bfree = (res.fbytes + blockres) >> blockbits;
-	buf->f_bavail = (res.abytes + blockres) >> blockbits;
+
+	buf->f_blocks = res.tbytes / buf->f_bsize;
+	buf->f_bfree = res.fbytes / buf->f_bsize;
+	buf->f_bavail = res.abytes / buf->f_bsize;
 
 	buf->f_files = res.tfiles;
 	buf->f_ffree = res.afiles;
-- 
2.16.6


             reply	other threads:[~2020-09-10 20:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 20:06 Frank van der Linden [this message]
2020-09-10 20:31 ` [PATCH] nfs: round down reported block numbers in statfs Frank van der Linden
2020-09-11  4:32 ` kernel test robot
2020-09-11  4:32   ` kernel test robot
2020-09-11  4:36 ` kernel test robot
2020-09-11  4:36   ` kernel test robot
2020-09-11 21:59   ` Frank van der Linden
2020-09-16 15:14 ` Trond Myklebust
2020-09-16 16:35   ` Frank van der Linden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200910200644.8165-1-fllinden@amazon.com \
    --to=fllinden@amazon.com \
    --cc=anna.schumaker@netapp.com \
    --cc=dhowells@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.