All of lore.kernel.org
 help / color / mirror / Atom feed
* nfs fstat st_blocks overreporting
@ 2003-10-13 14:53 Frank Cusack
  2003-10-13 15:29 ` Trond Myklebust
  2003-10-13 16:23 ` Linus Torvalds
  0 siblings, 2 replies; 4+ messages in thread
From: Frank Cusack @ 2003-10-13 14:53 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: Linus Torvalds, lkml

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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-14  1:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-13 14:53 nfs fstat st_blocks overreporting Frank Cusack
2003-10-13 15:29 ` Trond Myklebust
2003-10-14  1:00   ` Frank Cusack
2003-10-13 16:23 ` Linus Torvalds

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.