The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Frank Cusack <fcusack@fcusack.com>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Linus Torvalds <torvalds@osdl.org>, lkml <linux-kernel@vger.kernel.org>
Subject: nfs fstat st_blocks overreporting
Date: Mon, 13 Oct 2003 07:53:16 -0700	[thread overview]
Message-ID: <20031013075316.A16032@google.com> (raw)

While you know I disagree that s_blocksize should be wtmult (ie, it
is wtmult?wtmult:512 and I think it should be MAX(rsize,wsize)), in
any event the blocks used reporting is incorrect in that it assumes
a 512 byte blocksize.

I don't know why blockbits is an unsigned char instead of an int; I
just copied it from a similar block of code in fs/nfs/inode.c.

--- 26t7.1/fs/nfs/inode.c	2003-10-13 06:59:34.000000000 -0700
+++ 26t7.2/fs/nfs/inode.c	2003-10-13 07:50:34.000000000 -0700
@@ -207,13 +207,17 @@ nfs_block_bits(unsigned long bsize, unsi
 }
 
 /*
- * Calculate the number of 512byte blocks used.
+ * Calculate the number of 2^blockbits -byte blocks used.
  */
 static inline unsigned long
-nfs_calc_block_size(u64 tsize)
+nfs_calc_blocks_used(u64 tsize, unsigned char blockbits)
 {
-	loff_t used = (tsize + 511) >> 9;
-	return (used > ULONG_MAX) ? ULONG_MAX : used;
+	unsigned long blockres;
+	loff_t used;
+
+	blockres = (1 << blockbits) - 1;
+	used = (tsize + blockres) >> blockbits;
+	return (used > ULONG_MAX) ? ULONG_MAX : used;
 }
 
 /*
@@ -762,9 +766,9 @@ nfs_fhget(struct super_block *sb, struct
 		inode->i_gid = fattr->gid;
 		if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
 			/*
-			 * report the blocks in 512byte units
+			 * report the blocks in s_blocksize units
 			 */
-			inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
+			inode->i_blocks = nfs_calc_blocks_used(fattr->du.nfs3.used, inode->i_sb->s_blocksize_bits);
 			inode->i_blksize = inode->i_sb->s_blocksize;
 		} else {
 			inode->i_blocks = fattr->du.nfs2.blocks;
@@ -1181,9 +1185,10 @@ __nfs_refresh_inode(struct inode *inode,
 
 	if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
 		/*
-		 * report the blocks in 512byte units
+		 * report the blocks in s_blocksize units
 		 */
-		inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
+		inode->i_blocks = nfs_calc_blocks_used(fattr->du.nfs3.used,
+					inode->i_sb->s_blocksize_bits);
 		inode->i_blksize = inode->i_sb->s_blocksize;
  	} else {
  		inode->i_blocks = fattr->du.nfs2.blocks;

             reply	other threads:[~2003-10-13 14:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-13 14:53 Frank Cusack [this message]
2003-10-13 15:29 ` nfs fstat st_blocks overreporting Trond Myklebust
2003-10-14  1:00   ` Frank Cusack
2003-10-13 16:23 ` Linus Torvalds

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=20031013075316.A16032@google.com \
    --to=fcusack@fcusack.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=trond.myklebust@fys.uio.no \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox