All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: linux-ext4@vger.kernel.org
Cc: adilger@clusterfs.com, cmm@us.ibm.com,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [PATCH 3/7] ext4: Convert s_blocks_count_hi and s_blocks_count to le32_t
Date: Tue, 25 Sep 2007 14:33:48 +0530	[thread overview]
Message-ID: <11907110613446-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <11907110501570-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

Convert s_blocks_count_hi and s_blocks_count to le32_t
This helps in finding BUGs due to direct partial access of
these split 64 bit values

Also fix direct partial access in ext4 code

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/ext4/mballoc.c       |    4 ++--
 fs/ext4/super.c         |    4 ++--
 include/linux/ext4_fs.h |   12 ++++++------
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index c4e6c92..5b804b2 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4036,7 +4036,7 @@ int ext4_mb_initialize_context(struct ext4_allocation_context *ac,
 	/* start searching from the goal */
 	goal = ar->goal;
 	if (goal < le32_to_cpu(es->s_first_data_block) ||
-			goal >= le32_to_cpu(es->s_blocks_count))
+			goal >= ext4_blocks_count(es))
 		goal = le32_to_cpu(es->s_first_data_block);
 	ext4_get_group_no_and_offset(sb, goal, &group, &block);
 
@@ -4337,7 +4337,7 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode,
 	es = EXT4_SB(sb)->s_es;
 	if (block < le32_to_cpu(es->s_first_data_block) ||
 	    block + count < block ||
-	    block + count > le32_to_cpu(es->s_blocks_count)) {
+	    block + count > ext4_blocks_count(es)) {
 		ext4_error(sb, __FUNCTION__,
 			    "Freeing blocks not in datazone - "
 			    "block = %lu, count = %lu", block, count);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b9dda19..069d5f3 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2653,7 +2653,7 @@ static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf)
 
 	if (test_opt(sb, MINIX_DF)) {
 		sbi->s_overhead_last = 0;
-	} else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
+	} else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
 		unsigned long ngroups = sbi->s_groups_count, i;
 		ext4_fsblk_t overhead = 0;
 		smp_rmb();
@@ -2688,7 +2688,7 @@ static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf)
 		overhead += ngroups * (2 + sbi->s_itb_per_group);
 		sbi->s_overhead_last = overhead;
 		smp_wmb();
-		sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
+		sbi->s_blocks_last = ext4_blocks_count(es);
 	}
 
 	buf->f_type = EXT4_SUPER_MAGIC;
diff --git a/include/linux/ext4_fs.h b/include/linux/ext4_fs.h
index 84ef557..53a8665 100644
--- a/include/linux/ext4_fs.h
+++ b/include/linux/ext4_fs.h
@@ -563,7 +563,7 @@ do {									       \
  */
 struct ext4_super_block {
 /*00*/	__le32	s_inodes_count;		/* Inodes count */
-	__le32	s_blocks_count;		/* Blocks count */
+	le32_t	s_blocks_count;		/* Blocks count */
 	__le32	s_r_blocks_count;	/* Reserved blocks count */
 	__le32	s_free_blocks_count;	/* Free blocks count */
 /*10*/	__le32	s_free_inodes_count;	/* Free inodes count */
@@ -633,7 +633,7 @@ struct ext4_super_block {
 	__le32	s_mkfs_time;		/* When the filesystem was created */
 	__le32	s_jnl_blocks[17];	/* Backup of the journal inode */
 	/* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
-/*150*/	__le32	s_blocks_count_hi;	/* Blocks count */
+/*150*/	le32_t	s_blocks_count_hi;	/* Blocks count */
 	__le32	s_r_blocks_count_hi;	/* Reserved blocks count */
 	__le32	s_free_blocks_count_hi;	/* Free blocks count */
 	__le16	s_min_extra_isize;	/* All inodes have at least # bytes */
@@ -1066,8 +1066,8 @@ extern void ext4_inode_table_set(struct super_block *sb,
 
 static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
 {
-	return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
-		le32_to_cpu(es->s_blocks_count);
+	return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi.value) << 32) |
+		le32_to_cpu(es->s_blocks_count.value);
 }
 
 static inline ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
@@ -1085,8 +1085,8 @@ static inline ext4_fsblk_t ext4_free_blocks_count(struct ext4_super_block *es)
 static inline void ext4_blocks_count_set(struct ext4_super_block *es,
 					 ext4_fsblk_t blk)
 {
-	es->s_blocks_count = cpu_to_le32((u32)blk);
-	es->s_blocks_count_hi = cpu_to_le32(blk >> 32);
+	es->s_blocks_count.value = cpu_to_le32((u32)blk);
+	es->s_blocks_count_hi.value = cpu_to_le32(blk >> 32);
 }
 
 static inline void ext4_free_blocks_count_set(struct ext4_super_block *es,
-- 
1.5.3.1.91.gd3392-dirty

  reply	other threads:[~2007-09-25  9:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-25  9:03 [PATCH 1/7] ext4: Introduce le32_t and le16_t Aneesh Kumar K.V
2007-09-25  9:03 ` [PATCH 2/7] ext4: Convert bg_inode_bitmap and bg_inode_table to new type Aneesh Kumar K.V
2007-09-25  9:03   ` Aneesh Kumar K.V [this message]
2007-09-25  9:03     ` [PATCH 4/7] ext4: Convert s_r_blocks_count[_hi] s_free_blocks_count[_hi] to le32_t Aneesh Kumar K.V
2007-09-25  9:03       ` [PATCH 5/7] ext4: Convert ext4_extent.ee_start and ee_start_hi to le32_t and le16_t Aneesh Kumar K.V
2007-09-25  9:03         ` [PATCH 6/7] ext4: Convert ext4_extent_idx.ei_leaf and ei_leaf_hi " Aneesh Kumar K.V
2007-09-25  9:03           ` [PATCH 7/7] ext4: sparse fixes Aneesh Kumar K.V
2007-09-25  9:11 ` [PATCH 1/7] ext4: Introduce le32_t and le16_t Aneesh Kumar K.V
2007-09-25 10:01   ` Andreas Dilger
2007-09-25 10:51     ` Aneesh Kumar K.V
2007-09-25 13:56 ` Dave Kleikamp
2007-09-25 15:45   ` Aneesh Kumar K.V
2007-09-25 16:02     ` Dave Kleikamp

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=11907110613446-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=adilger@clusterfs.com \
    --cc=cmm@us.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    /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.