From bd86298e60b84b5e6d2da3e75c4ce2f6b70bdeed Mon Sep 17 00:00:00 2001 From: Lukas Czerner Date: Wed, 3 Apr 2013 23:32:34 -0400 Subject: ext4: introduce ext4_get_group_number() Currently on many places in ext4 we're using ext4_get_group_no_and_offset() even though we're only interested in knowing the block group of the particular block, not the offset within the block group so we can use more efficient way to compute block group. This patch introduces ext4_get_group_number() which computes block group for a given block much more efficiently. Use this function instead of ext4_get_group_no_and_offset() everywhere where we're only interested in knowing the block group. Signed-off-by: Lukas Czerner Signed-off-by: "Theodore Ts'o" --- fs/ext4/balloc.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'fs/ext4/balloc.c') diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index d6babf94907e..9e8d8ffb063f 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c @@ -29,6 +29,23 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb, * balloc.c contains the blocks allocation and deallocation routines */ +/* + * Calculate block group number for a given block number + */ +ext4_group_t ext4_get_group_number(struct super_block *sb, + ext4_fsblk_t block) +{ + ext4_group_t group; + + if (test_opt2(sb, STD_GROUP_SIZE)) + group = (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) + + block) >> + (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3); + else + ext4_get_group_no_and_offset(sb, block, &group, NULL); + return group; +} + /* * Calculate the block group number and offset into the block/cluster * allocation bitmap, given a block number @@ -59,13 +76,7 @@ static inline int ext4_block_in_group(struct super_block *sb, { ext4_group_t actual_group; - if (test_opt2(sb, STD_GROUP_SIZE)) - actual_group = - (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) + - block) >> - (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3); - else - ext4_get_group_no_and_offset(sb, block, &actual_group, NULL); + actual_group = ext4_get_group_number(sb, block); return (actual_group == block_group) ? 1 : 0; } -- cgit v1.2.3