All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] ext4: use ext4_group_first_block_no()
@ 2010-03-03 14:40 Akinobu Mita
  2010-03-03 14:40 ` [PATCH 2/3] ext4: use ext4_grp_offs_to_block Akinobu Mita
  2010-03-03 14:40 ` [PATCH 3/3] ext4: consolidate in_range() definisions Akinobu Mita
  0 siblings, 2 replies; 4+ messages in thread
From: Akinobu Mita @ 2010-03-03 14:40 UTC (permalink / raw)
  To: linux-ext4; +Cc: Akinobu Mita, Andreas Dilger, Theodore Ts'o

Use ext4_group_first_block_no() to calculate the first block number of
the group.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Andreas Dilger <adilger@sun.com>
Cc: linux-ext4@vger.kernel.org
Cc: "Theodore Ts'o" <tytso@mit.edu>
---
 fs/ext4/balloc.c  |    3 +--
 fs/ext4/extents.c |    3 +--
 fs/ext4/mballoc.c |   29 +++++++++++------------------
 fs/ext4/mballoc.h |    7 +------
 4 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 22bc743..89733a5 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -130,8 +130,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
 		 * to make sure we calculate the right free blocks
 		 */
 		group_blocks = ext4_blocks_count(sbi->s_es) -
-			le32_to_cpu(sbi->s_es->s_first_data_block) -
-			(EXT4_BLOCKS_PER_GROUP(sb) * (ngroups - 1));
+			ext4_group_first_block_no(sb, ngroups - 1);
 	} else {
 		group_blocks = EXT4_BLOCKS_PER_GROUP(sb);
 	}
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 765a482..11eaaa9 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -195,8 +195,7 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,
 		if (S_ISREG(inode->i_mode))
 			block_group++;
 	}
-	bg_start = (block_group * EXT4_BLOCKS_PER_GROUP(inode->i_sb)) +
-		le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_first_data_block);
+	bg_start = ext4_group_first_block_no(inode->i_sb, block_group);
 	last_block = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es) - 1;
 
 	/*
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index d34afad..0babffd 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -441,10 +441,9 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
 	for (i = 0; i < count; i++) {
 		if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) {
 			ext4_fsblk_t blocknr;
-			blocknr = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb);
+
+			blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
 			blocknr += first + i;
-			blocknr +=
-			    le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
 			ext4_grp_locked_error(sb, e4b->bd_group,
 				   __func__, "double-free of inode"
 				   " %lu's block %llu(bit %u in group %u)",
@@ -1255,10 +1254,9 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
 
 		if (!mb_test_bit(block, EXT4_MB_BITMAP(e4b))) {
 			ext4_fsblk_t blocknr;
-			blocknr = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb);
+
+			blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
 			blocknr += block;
-			blocknr +=
-			    le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
 			ext4_grp_locked_error(sb, e4b->bd_group,
 				   __func__, "double-free of inode"
 				   " %lu's block %llu(bit %u in group %u)",
@@ -1631,7 +1629,6 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,
 	int max;
 	int err;
 	struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
-	struct ext4_super_block *es = sbi->s_es;
 	struct ext4_free_extent ex;
 
 	if (!(ac->ac_flags & EXT4_MB_HINT_TRY_GOAL))
@@ -1648,8 +1645,8 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,
 	if (max >= ac->ac_g_ex.fe_len && ac->ac_g_ex.fe_len == sbi->s_stripe) {
 		ext4_fsblk_t start;
 
-		start = (e4b->bd_group * EXT4_BLOCKS_PER_GROUP(ac->ac_sb)) +
-			ex.fe_start + le32_to_cpu(es->s_first_data_block);
+		start = ext4_group_first_block_no(ac->ac_sb, e4b->bd_group) +
+			ex.fe_start;
 		/* use do_div to get remainder (would be 64-bit modulo) */
 		if (do_div(start, sbi->s_stripe) == 0) {
 			ac->ac_found++;
@@ -1803,8 +1800,8 @@ void ext4_mb_scan_aligned(struct ext4_allocation_context *ac,
 	BUG_ON(sbi->s_stripe == 0);
 
 	/* find first stripe-aligned block in group */
-	first_group_block = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb)
-		+ le32_to_cpu(sbi->s_es->s_first_data_block);
+	first_group_block = ext4_group_first_block_no(sb, e4b->bd_group);
+
 	a = first_group_block + sbi->s_stripe - 1;
 	do_div(a, sbi->s_stripe);
 	i = (a * sbi->s_stripe) - first_group_block;
@@ -2560,12 +2557,9 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
 		ext4_unlock_group(sb, entry->group);
 		if (test_opt(sb, DISCARD)) {
 			ext4_fsblk_t discard_block;
-			struct ext4_super_block *es = EXT4_SB(sb)->s_es;
 
-			discard_block = (ext4_fsblk_t)entry->group *
-						EXT4_BLOCKS_PER_GROUP(sb)
-					+ entry->start_blk
-					+ le32_to_cpu(es->s_first_data_block);
+			discard_block = entry->start_blk +
+				ext4_group_first_block_no(sb, entry->group);
 			trace_ext4_discard_blocks(sb,
 					(unsigned long long)discard_block,
 					entry->count);
@@ -3526,8 +3520,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
 		if (bit >= end)
 			break;
 		next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
-		start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +
-				le32_to_cpu(sbi->s_es->s_first_data_block);
+		start = ext4_group_first_block_no(sb, group) + bit;
 		mb_debug(1, "    free preallocated %u/%u in group %u\n",
 				(unsigned) start, (unsigned) next - bit,
 				(unsigned) group);
diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
index 436521c..9b2deed 100644
--- a/fs/ext4/mballoc.h
+++ b/fs/ext4/mballoc.h
@@ -225,11 +225,6 @@ struct ext4_buddy {
 static inline ext4_fsblk_t ext4_grp_offs_to_block(struct super_block *sb,
 					struct ext4_free_extent *fex)
 {
-	ext4_fsblk_t block;

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

* [PATCH 2/3] ext4: use ext4_grp_offs_to_block
  2010-03-03 14:40 [PATCH 1/3] ext4: use ext4_group_first_block_no() Akinobu Mita
@ 2010-03-03 14:40 ` Akinobu Mita
  2010-03-03 14:40 ` [PATCH 3/3] ext4: consolidate in_range() definisions Akinobu Mita
  1 sibling, 0 replies; 4+ messages in thread
From: Akinobu Mita @ 2010-03-03 14:40 UTC (permalink / raw)
  To: linux-ext4; +Cc: Akinobu Mita, Andreas Dilger, Theodore Ts'o

Use ext4_grp_offs_to_block() to calculate the first block number of the
free extent.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Andreas Dilger <adilger@sun.com>
Cc: linux-ext4@vger.kernel.org
Cc: "Theodore Ts'o" <tytso@mit.edu>
---
 fs/ext4/mballoc.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 0babffd..5196a8c 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2697,9 +2697,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
 	if (err)
 		goto out_err;
 
-	block = ac->ac_b_ex.fe_group * EXT4_BLOCKS_PER_GROUP(sb)
-		+ ac->ac_b_ex.fe_start
-		+ le32_to_cpu(es->s_first_data_block);
+	block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex);
 
 	len = ac->ac_b_ex.fe_len;
 	if (!ext4_data_block_valid(sbi, block, len)) {
@@ -3155,9 +3153,7 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
 		/* The max size of hash table is PREALLOC_TB_SIZE */
 		order = PREALLOC_TB_SIZE - 1;
 
-	goal_block = ac->ac_g_ex.fe_group * EXT4_BLOCKS_PER_GROUP(ac->ac_sb) +
-		     ac->ac_g_ex.fe_start +
-		     le32_to_cpu(EXT4_SB(ac->ac_sb)->s_es->s_first_data_block);
+	goal_block = ext4_grp_offs_to_block(ac->ac_sb, &ac->ac_g_ex);
 	/*
 	 * search for the prealloc space that is having
 	 * minimal distance from the goal block.
-- 
1.6.0.6


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

* [PATCH 3/3] ext4: consolidate in_range() definisions
  2010-03-03 14:40 [PATCH 1/3] ext4: use ext4_group_first_block_no() Akinobu Mita
  2010-03-03 14:40 ` [PATCH 2/3] ext4: use ext4_grp_offs_to_block Akinobu Mita
@ 2010-03-03 14:40 ` Akinobu Mita
  2010-03-04  5:19   ` tytso
  1 sibling, 1 reply; 4+ messages in thread
From: Akinobu Mita @ 2010-03-03 14:40 UTC (permalink / raw)
  To: linux-ext4; +Cc: Akinobu Mita, Andreas Dilger, Theodore Ts'o

There are same in_range() macro definisions in mballoc.h and
balloc.c. This consolidates these in_range() definisions and
use it in extents.c, too

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Andreas Dilger <adilger@sun.com>
Cc: linux-ext4@vger.kernel.org
Cc: "Theodore Ts'o" <tytso@mit.edu>
---
 fs/ext4/balloc.c  |    3 ---
 fs/ext4/ext4.h    |    2 ++
 fs/ext4/extents.c |    4 ++--
 fs/ext4/mballoc.h |    2 --
 4 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 89733a5..c35c937 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -188,9 +188,6 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
  * when a file system is mounted (see ext4_fill_super).
  */
 
-
-#define in_range(b, first, len)	((b) >= (first) && (b) <= (first) + (len) - 1)
-
 /**
  * ext4_get_group_desc() -- load group descriptor from disk
  * @sb:			super block
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 874d169..3424afb 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1773,6 +1773,8 @@ static inline void set_bitmap_uptodate(struct buffer_head *bh)
 	set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state);
 }
 
+#define in_range(b, first, len)	((b) >= (first) && (b) <= (first) + (len) - 1)
+
 #endif	/* __KERNEL__ */
 
 #endif	/* _EXT4_H */
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 11eaaa9..69b96cd 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -1951,7 +1951,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,
 
 	BUG_ON(cex->ec_type != EXT4_EXT_CACHE_GAP &&
 			cex->ec_type != EXT4_EXT_CACHE_EXTENT);
-	if (block >= cex->ec_block && block < cex->ec_block + cex->ec_len) {
+	if (in_range(block, cex->ec_block, cex->ec_len)) {
 		ex->ee_block = cpu_to_le32(cex->ec_block);
 		ext4_ext_store_pblock(ex, cex->ec_start);
 		ex->ee_len = cpu_to_le16(cex->ec_len);
@@ -3257,7 +3257,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
 		 */
 		ee_len = ext4_ext_get_actual_len(ex);
 		/* if found extent covers block, simply return it */
-		if (iblock >= ee_block && iblock < ee_block + ee_len) {
+		if (in_range(iblock, ee_block, ee_len)) {
 			newblock = iblock - ee_block + ee_start;
 			/* number of remaining blocks in the extent */
 			allocated = ee_len - (iblock - ee_block);
diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
index 9b2deed..b619322 100644
--- a/fs/ext4/mballoc.h
+++ b/fs/ext4/mballoc.h
@@ -220,8 +220,6 @@ struct ext4_buddy {
 #define EXT4_MB_BITMAP(e4b)	((e4b)->bd_bitmap)
 #define EXT4_MB_BUDDY(e4b)	((e4b)->bd_buddy)
 
-#define in_range(b, first, len)	((b) >= (first) && (b) <= (first) + (len) - 1)

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

* Re: [PATCH 3/3] ext4: consolidate in_range() definisions
  2010-03-03 14:40 ` [PATCH 3/3] ext4: consolidate in_range() definisions Akinobu Mita
@ 2010-03-04  5:19   ` tytso
  0 siblings, 0 replies; 4+ messages in thread
From: tytso @ 2010-03-04  5:19 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-ext4, Andreas Dilger

On Wed, Mar 03, 2010 at 11:40:46PM +0900, Akinobu Mita wrote:
> There are same in_range() macro definisions in mballoc.h and
> balloc.c. This consolidates these in_range() definisions and
> use it in extents.c, too
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Andreas Dilger <adilger@sun.com>
> Cc: linux-ext4@vger.kernel.org
> Cc: "Theodore Ts'o" <tytso@mit.edu>

I've added all three to the ext4 patch queue, thanks.

     	       	     	    	 - Ted

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

end of thread, other threads:[~2010-03-04  5:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-03 14:40 [PATCH 1/3] ext4: use ext4_group_first_block_no() Akinobu Mita
2010-03-03 14:40 ` [PATCH 2/3] ext4: use ext4_grp_offs_to_block Akinobu Mita
2010-03-03 14:40 ` [PATCH 3/3] ext4: consolidate in_range() definisions Akinobu Mita
2010-03-04  5:19   ` tytso

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.