diff options
Diffstat (limited to 'fs/ext4/balloc.c')
-rw-r--r-- | fs/ext4/balloc.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index 5c56785007e0..0762d143e252 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -83,9 +83,9 @@ static inline int ext4_block_in_group(struct super_block *sb, | |||
83 | /* Return the number of clusters used for file system metadata; this | 83 | /* Return the number of clusters used for file system metadata; this |
84 | * represents the overhead needed by the file system. | 84 | * represents the overhead needed by the file system. |
85 | */ | 85 | */ |
86 | unsigned ext4_num_overhead_clusters(struct super_block *sb, | 86 | static unsigned ext4_num_overhead_clusters(struct super_block *sb, |
87 | ext4_group_t block_group, | 87 | ext4_group_t block_group, |
88 | struct ext4_group_desc *gdp) | 88 | struct ext4_group_desc *gdp) |
89 | { | 89 | { |
90 | unsigned num_clusters; | 90 | unsigned num_clusters; |
91 | int block_cluster = -1, inode_cluster = -1, itbl_cluster = -1, i, c; | 91 | int block_cluster = -1, inode_cluster = -1, itbl_cluster = -1, i, c; |
@@ -176,9 +176,10 @@ static unsigned int num_clusters_in_group(struct super_block *sb, | |||
176 | } | 176 | } |
177 | 177 | ||
178 | /* Initializes an uninitialized block bitmap */ | 178 | /* Initializes an uninitialized block bitmap */ |
179 | void ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, | 179 | static void ext4_init_block_bitmap(struct super_block *sb, |
180 | ext4_group_t block_group, | 180 | struct buffer_head *bh, |
181 | struct ext4_group_desc *gdp) | 181 | ext4_group_t block_group, |
182 | struct ext4_group_desc *gdp) | ||
182 | { | 183 | { |
183 | unsigned int bit, bit_max; | 184 | unsigned int bit, bit_max; |
184 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 185 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
@@ -307,6 +308,7 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb, | |||
307 | ext4_group_t block_group, | 308 | ext4_group_t block_group, |
308 | struct buffer_head *bh) | 309 | struct buffer_head *bh) |
309 | { | 310 | { |
311 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
310 | ext4_grpblk_t offset; | 312 | ext4_grpblk_t offset; |
311 | ext4_grpblk_t next_zero_bit; | 313 | ext4_grpblk_t next_zero_bit; |
312 | ext4_fsblk_t blk; | 314 | ext4_fsblk_t blk; |
@@ -326,14 +328,14 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb, | |||
326 | /* check whether block bitmap block number is set */ | 328 | /* check whether block bitmap block number is set */ |
327 | blk = ext4_block_bitmap(sb, desc); | 329 | blk = ext4_block_bitmap(sb, desc); |
328 | offset = blk - group_first_block; | 330 | offset = blk - group_first_block; |
329 | if (!ext4_test_bit(offset, bh->b_data)) | 331 | if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data)) |
330 | /* bad block bitmap */ | 332 | /* bad block bitmap */ |
331 | return blk; | 333 | return blk; |
332 | 334 | ||
333 | /* check whether the inode bitmap block number is set */ | 335 | /* check whether the inode bitmap block number is set */ |
334 | blk = ext4_inode_bitmap(sb, desc); | 336 | blk = ext4_inode_bitmap(sb, desc); |
335 | offset = blk - group_first_block; | 337 | offset = blk - group_first_block; |
336 | if (!ext4_test_bit(offset, bh->b_data)) | 338 | if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data)) |
337 | /* bad block bitmap */ | 339 | /* bad block bitmap */ |
338 | return blk; | 340 | return blk; |
339 | 341 | ||
@@ -341,18 +343,19 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb, | |||
341 | blk = ext4_inode_table(sb, desc); | 343 | blk = ext4_inode_table(sb, desc); |
342 | offset = blk - group_first_block; | 344 | offset = blk - group_first_block; |
343 | next_zero_bit = ext4_find_next_zero_bit(bh->b_data, | 345 | next_zero_bit = ext4_find_next_zero_bit(bh->b_data, |
344 | offset + EXT4_SB(sb)->s_itb_per_group, | 346 | EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group), |
345 | offset); | 347 | EXT4_B2C(sbi, offset)); |
346 | if (next_zero_bit < offset + EXT4_SB(sb)->s_itb_per_group) | 348 | if (next_zero_bit < |
349 | EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group)) | ||
347 | /* bad bitmap for inode tables */ | 350 | /* bad bitmap for inode tables */ |
348 | return blk; | 351 | return blk; |
349 | return 0; | 352 | return 0; |
350 | } | 353 | } |
351 | 354 | ||
352 | void ext4_validate_block_bitmap(struct super_block *sb, | 355 | static void ext4_validate_block_bitmap(struct super_block *sb, |
353 | struct ext4_group_desc *desc, | 356 | struct ext4_group_desc *desc, |
354 | ext4_group_t block_group, | 357 | ext4_group_t block_group, |
355 | struct buffer_head *bh) | 358 | struct buffer_head *bh) |
356 | { | 359 | { |
357 | ext4_fsblk_t blk; | 360 | ext4_fsblk_t blk; |
358 | struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); | 361 | struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); |
@@ -708,16 +711,6 @@ static inline int test_root(ext4_group_t a, int b) | |||
708 | } | 711 | } |
709 | } | 712 | } |
710 | 713 | ||
711 | static int ext4_group_sparse(ext4_group_t group) | ||
712 | { | ||
713 | if (group <= 1) | ||
714 | return 1; | ||
715 | if (!(group & 1)) | ||
716 | return 0; | ||
717 | return (test_root(group, 7) || test_root(group, 5) || | ||
718 | test_root(group, 3)); | ||
719 | } | ||
720 | |||
721 | /** | 714 | /** |
722 | * ext4_bg_has_super - number of blocks used by the superblock in group | 715 | * ext4_bg_has_super - number of blocks used by the superblock in group |
723 | * @sb: superblock for filesystem | 716 | * @sb: superblock for filesystem |
@@ -728,11 +721,26 @@ static int ext4_group_sparse(ext4_group_t group) | |||
728 | */ | 721 | */ |
729 | int ext4_bg_has_super(struct super_block *sb, ext4_group_t group) | 722 | int ext4_bg_has_super(struct super_block *sb, ext4_group_t group) |
730 | { | 723 | { |
731 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, | 724 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; |
732 | EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) && | 725 | |
733 | !ext4_group_sparse(group)) | 726 | if (group == 0) |
727 | return 1; | ||
728 | if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_SPARSE_SUPER2)) { | ||
729 | if (group == le32_to_cpu(es->s_backup_bgs[0]) || | ||
730 | group == le32_to_cpu(es->s_backup_bgs[1])) | ||
731 | return 1; | ||
734 | return 0; | 732 | return 0; |
735 | return 1; | 733 | } |
734 | if ((group <= 1) || !EXT4_HAS_RO_COMPAT_FEATURE(sb, | ||
735 | EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) | ||
736 | return 1; | ||
737 | if (!(group & 1)) | ||
738 | return 0; | ||
739 | if (test_root(group, 3) || (test_root(group, 5)) || | ||
740 | test_root(group, 7)) | ||
741 | return 1; | ||
742 | |||
743 | return 0; | ||
736 | } | 744 | } |
737 | 745 | ||
738 | static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb, | 746 | static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb, |