aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/ext4/balloc.c25
-rw-r--r--fs/ext4/ext4.h10
-rw-r--r--fs/ext4/mballoc.c6
-rw-r--r--fs/ext4/resize.c10
4 files changed, 33 insertions, 18 deletions
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
@@ -30,6 +30,23 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
30 */ 30 */
31 31
32/* 32/*
33 * Calculate block group number for a given block number
34 */
35ext4_group_t ext4_get_group_number(struct super_block *sb,
36 ext4_fsblk_t block)
37{
38 ext4_group_t group;
39
40 if (test_opt2(sb, STD_GROUP_SIZE))
41 group = (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) +
42 block) >>
43 (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3);
44 else
45 ext4_get_group_no_and_offset(sb, block, &group, NULL);
46 return group;
47}
48
49/*
33 * Calculate the block group number and offset into the block/cluster 50 * Calculate the block group number and offset into the block/cluster
34 * allocation bitmap, given a block number 51 * allocation bitmap, given a block number
35 */ 52 */
@@ -59,13 +76,7 @@ static inline int ext4_block_in_group(struct super_block *sb,
59{ 76{
60 ext4_group_t actual_group; 77 ext4_group_t actual_group;
61 78
62 if (test_opt2(sb, STD_GROUP_SIZE)) 79 actual_group = ext4_get_group_number(sb, block);
63 actual_group =
64 (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) +
65 block) >>
66 (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3);
67 else
68 ext4_get_group_no_and_offset(sb, block, &actual_group, NULL);
69 return (actual_group == block_group) ? 1 : 0; 80 return (actual_group == block_group) ? 1 : 0;
70} 81}
71 82
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index cc58aa8e9869..a0637e5057ae 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1793,9 +1793,6 @@ ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
1793 */ 1793 */
1794#define ERR_BAD_DX_DIR -75000 1794#define ERR_BAD_DX_DIR -75000
1795 1795
1796void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
1797 ext4_group_t *blockgrpp, ext4_grpblk_t *offsetp);
1798
1799/* 1796/*
1800 * Timeout and state flag for lazy initialization inode thread. 1797 * Timeout and state flag for lazy initialization inode thread.
1801 */ 1798 */
@@ -1917,6 +1914,13 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
1917 struct buffer_head *bh); 1914 struct buffer_head *bh);
1918 1915
1919/* balloc.c */ 1916/* balloc.c */
1917extern void ext4_get_group_no_and_offset(struct super_block *sb,
1918 ext4_fsblk_t blocknr,
1919 ext4_group_t *blockgrpp,
1920 ext4_grpblk_t *offsetp);
1921extern ext4_group_t ext4_get_group_number(struct super_block *sb,
1922 ext4_fsblk_t block);
1923
1920extern void ext4_validate_block_bitmap(struct super_block *sb, 1924extern void ext4_validate_block_bitmap(struct super_block *sb,
1921 struct ext4_group_desc *desc, 1925 struct ext4_group_desc *desc,
1922 unsigned int block_group, 1926 unsigned int block_group,
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 580aada3d1bb..8c8d05218021 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3344,7 +3344,7 @@ static void ext4_mb_put_pa(struct ext4_allocation_context *ac,
3344 if (pa->pa_type == MB_GROUP_PA) 3344 if (pa->pa_type == MB_GROUP_PA)
3345 grp_blk--; 3345 grp_blk--;
3346 3346
3347 ext4_get_group_no_and_offset(sb, grp_blk, &grp, NULL); 3347 grp = ext4_get_group_number(sb, grp_blk);
3348 3348
3349 /* 3349 /*
3350 * possible race: 3350 * possible race:
@@ -3809,7 +3809,7 @@ repeat:
3809 3809
3810 list_for_each_entry_safe(pa, tmp, &list, u.pa_tmp_list) { 3810 list_for_each_entry_safe(pa, tmp, &list, u.pa_tmp_list) {
3811 BUG_ON(pa->pa_type != MB_INODE_PA); 3811 BUG_ON(pa->pa_type != MB_INODE_PA);
3812 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL); 3812 group = ext4_get_group_number(sb, pa->pa_pstart);
3813 3813
3814 err = ext4_mb_load_buddy(sb, group, &e4b); 3814 err = ext4_mb_load_buddy(sb, group, &e4b);
3815 if (err) { 3815 if (err) {
@@ -4071,7 +4071,7 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,
4071 4071
4072 list_for_each_entry_safe(pa, tmp, &discard_list, u.pa_tmp_list) { 4072 list_for_each_entry_safe(pa, tmp, &discard_list, u.pa_tmp_list) {
4073 4073
4074 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL); 4074 group = ext4_get_group_number(sb, pa->pa_pstart);
4075 if (ext4_mb_load_buddy(sb, group, &e4b)) { 4075 if (ext4_mb_load_buddy(sb, group, &e4b)) {
4076 ext4_error(sb, "Error loading buddy information for %u", 4076 ext4_error(sb, "Error loading buddy information for %u",
4077 group); 4077 group);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index c169477a62c9..e3498534a2c1 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -272,7 +272,7 @@ next_group:
272 if (start_blk >= last_blk) 272 if (start_blk >= last_blk)
273 goto next_group; 273 goto next_group;
274 group_data[bb_index].block_bitmap = start_blk++; 274 group_data[bb_index].block_bitmap = start_blk++;
275 ext4_get_group_no_and_offset(sb, start_blk - 1, &group, NULL); 275 group = ext4_get_group_number(sb, start_blk - 1);
276 group -= group_data[0].group; 276 group -= group_data[0].group;
277 group_data[group].free_blocks_count--; 277 group_data[group].free_blocks_count--;
278 if (flexbg_size > 1) 278 if (flexbg_size > 1)
@@ -284,7 +284,7 @@ next_group:
284 if (start_blk >= last_blk) 284 if (start_blk >= last_blk)
285 goto next_group; 285 goto next_group;
286 group_data[ib_index].inode_bitmap = start_blk++; 286 group_data[ib_index].inode_bitmap = start_blk++;
287 ext4_get_group_no_and_offset(sb, start_blk - 1, &group, NULL); 287 group = ext4_get_group_number(sb, start_blk - 1);
288 group -= group_data[0].group; 288 group -= group_data[0].group;
289 group_data[group].free_blocks_count--; 289 group_data[group].free_blocks_count--;
290 if (flexbg_size > 1) 290 if (flexbg_size > 1)
@@ -296,7 +296,7 @@ next_group:
296 if (start_blk + EXT4_SB(sb)->s_itb_per_group > last_blk) 296 if (start_blk + EXT4_SB(sb)->s_itb_per_group > last_blk)
297 goto next_group; 297 goto next_group;
298 group_data[it_index].inode_table = start_blk; 298 group_data[it_index].inode_table = start_blk;
299 ext4_get_group_no_and_offset(sb, start_blk, &group, NULL); 299 group = ext4_get_group_number(sb, start_blk - 1);
300 group -= group_data[0].group; 300 group -= group_data[0].group;
301 group_data[group].free_blocks_count -= 301 group_data[group].free_blocks_count -=
302 EXT4_SB(sb)->s_itb_per_group; 302 EXT4_SB(sb)->s_itb_per_group;
@@ -392,7 +392,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle,
392 ext4_group_t group; 392 ext4_group_t group;
393 int err; 393 int err;
394 394
395 ext4_get_group_no_and_offset(sb, block, &group, NULL); 395 group = ext4_get_group_number(sb, block);
396 start = ext4_group_first_block_no(sb, group); 396 start = ext4_group_first_block_no(sb, group);
397 group -= flex_gd->groups[0].group; 397 group -= flex_gd->groups[0].group;
398 398
@@ -1879,7 +1879,7 @@ retry:
1879 /* Nothing need to do */ 1879 /* Nothing need to do */
1880 return 0; 1880 return 0;
1881 1881
1882 ext4_get_group_no_and_offset(sb, n_blocks_count - 1, &n_group, &offset); 1882 n_group = ext4_get_group_number(sb, n_blocks_count - 1);
1883 ext4_get_group_no_and_offset(sb, o_blocks_count - 1, &o_group, &offset); 1883 ext4_get_group_no_and_offset(sb, o_blocks_count - 1, &o_group, &offset);
1884 1884
1885 n_desc_blocks = num_desc_blocks(sb, n_group + 1); 1885 n_desc_blocks = num_desc_blocks(sb, n_group + 1);