[PATCH 12/14] PMFS: Fix a couple of bugs in pmfs_inode_count_iblocks()

Matthew Wilcox matthew.r.wilcox at intel.com
Mon Oct 7 09:37:50 EDT 2013


From: Matthew Wilcox <willy at linux.intel.com>

pmfs_inode_count_iblocks_recursive() was taking its 'block' number
as an unsigned long, which would be truncated on a 32-bit system.
Change it to take a __le64 instead, and adjust the callers.  This fixes
an endianness bug as the caller of pmfs_inode_count_iblocks() was not
swapping its argument.

I could have made a smaller change here by leaving 'root' as u64, and
addng byteswapping to the caller, but this way feels more similar to
the way the rest of the file handles block types.

Signed-off-by: Matthew Wilcox <matthew.r.wilcox at intel.com>
---
 fs/pmfs/inode.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/fs/pmfs/inode.c b/fs/pmfs/inode.c
index e9f4292..3fb1a41 100644
--- a/fs/pmfs/inode.c
+++ b/fs/pmfs/inode.c
@@ -392,32 +392,31 @@ update_root_and_height:
 }
 
 static unsigned long pmfs_inode_count_iblocks_recursive(struct super_block *sb,
-		unsigned long block, u32 height)
+		__le64 block, u32 height)
 {
-	u64 *node;
+	__le64 *node;
 	unsigned int i;
 	unsigned long i_blocks = 0;
 
 	if (height == 0)
 		return 1;
-	node = pmfs_get_block(sb, block);
+	node = pmfs_get_block(sb, le64_to_cpu(block));
 	for (i = 0; i < (1 << META_BLK_SHIFT); i++) {
 		if (node[i] == 0)
 			continue;
-		i_blocks += pmfs_inode_count_iblocks_recursive(sb,
-			le64_to_cpu(node[i]), height - 1);
+		i_blocks += pmfs_inode_count_iblocks_recursive(sb, node[i],
+								height - 1);
 	}
 	return i_blocks;
 }
 
 static inline unsigned long pmfs_inode_count_iblocks (struct super_block *sb,
-	struct pmfs_inode *pi, u64 root)
+	struct pmfs_inode *pi, __le64 root)
 {
 	unsigned long iblocks;
 	if (root == 0)
 		return 0;
-	iblocks = pmfs_inode_count_iblocks_recursive(sb, le64_to_cpu(root),
- 						pi->height);
+	iblocks = pmfs_inode_count_iblocks_recursive(sb, root, pi->height);
 	return (iblocks << (pmfs_inode_blk_shift(pi) - sb->s_blocksize_bits));
 }
 
-- 
1.8.4.rc3




More information about the Linux-pmfs mailing list