Lines Matching refs:sb
26 static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
35 ext4_group_t ext4_get_group_number(struct super_block *sb, in ext4_get_group_number() argument
40 if (test_opt2(sb, STD_GROUP_SIZE)) in ext4_get_group_number()
42 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) >> in ext4_get_group_number()
43 (EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3); in ext4_get_group_number()
45 ext4_get_group_no_and_offset(sb, block, &group, NULL); in ext4_get_group_number()
53 void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr, in ext4_get_group_no_and_offset() argument
56 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_get_group_no_and_offset()
60 offset = do_div(blocknr, EXT4_BLOCKS_PER_GROUP(sb)) >> in ext4_get_group_no_and_offset()
61 EXT4_SB(sb)->s_cluster_bits; in ext4_get_group_no_and_offset()
73 static inline int ext4_block_in_group(struct super_block *sb, in ext4_block_in_group() argument
79 actual_group = ext4_get_group_number(sb, block); in ext4_block_in_group()
86 static unsigned ext4_num_overhead_clusters(struct super_block *sb, in ext4_num_overhead_clusters() argument
92 ext4_fsblk_t start = ext4_group_first_block_no(sb, block_group); in ext4_num_overhead_clusters()
94 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_num_overhead_clusters()
99 num_clusters = ext4_num_base_meta_clusters(sb, block_group); in ext4_num_overhead_clusters()
113 if (ext4_block_in_group(sb, ext4_block_bitmap(sb, gdp), block_group)) { in ext4_num_overhead_clusters()
115 ext4_block_bitmap(sb, gdp) - start); in ext4_num_overhead_clusters()
124 if (ext4_block_in_group(sb, ext4_inode_bitmap(sb, gdp), block_group)) { in ext4_num_overhead_clusters()
126 ext4_inode_bitmap(sb, gdp) - start); in ext4_num_overhead_clusters()
135 itbl_blk = ext4_inode_table(sb, gdp); in ext4_num_overhead_clusters()
137 if (ext4_block_in_group(sb, itbl_blk + i, block_group)) { in ext4_num_overhead_clusters()
159 static unsigned int num_clusters_in_group(struct super_block *sb, in num_clusters_in_group() argument
164 if (block_group == ext4_get_groups_count(sb) - 1) { in num_clusters_in_group()
171 blocks = ext4_blocks_count(EXT4_SB(sb)->s_es) - in num_clusters_in_group()
172 ext4_group_first_block_no(sb, block_group); in num_clusters_in_group()
174 blocks = EXT4_BLOCKS_PER_GROUP(sb); in num_clusters_in_group()
175 return EXT4_NUM_B2C(EXT4_SB(sb), blocks); in num_clusters_in_group()
179 static int ext4_init_block_bitmap(struct super_block *sb, in ext4_init_block_bitmap() argument
185 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_init_block_bitmap()
192 if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { in ext4_init_block_bitmap()
193 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_init_block_bitmap()
198 memset(bh->b_data, 0, sb->s_blocksize); in ext4_init_block_bitmap()
200 bit_max = ext4_num_base_meta_clusters(sb, block_group); in ext4_init_block_bitmap()
207 start = ext4_group_first_block_no(sb, block_group); in ext4_init_block_bitmap()
210 tmp = ext4_block_bitmap(sb, gdp); in ext4_init_block_bitmap()
211 if (ext4_block_in_group(sb, tmp, block_group)) in ext4_init_block_bitmap()
214 tmp = ext4_inode_bitmap(sb, gdp); in ext4_init_block_bitmap()
215 if (ext4_block_in_group(sb, tmp, block_group)) in ext4_init_block_bitmap()
218 tmp = ext4_inode_table(sb, gdp); in ext4_init_block_bitmap()
219 for (; tmp < ext4_inode_table(sb, gdp) + in ext4_init_block_bitmap()
221 if (ext4_block_in_group(sb, tmp, block_group)) in ext4_init_block_bitmap()
230 ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group), in ext4_init_block_bitmap()
231 sb->s_blocksize * 8, bh->b_data); in ext4_init_block_bitmap()
238 unsigned ext4_free_clusters_after_init(struct super_block *sb, in ext4_free_clusters_after_init() argument
242 return num_clusters_in_group(sb, block_group) - in ext4_free_clusters_after_init()
243 ext4_num_overhead_clusters(sb, block_group, gdp); in ext4_free_clusters_after_init()
264 struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb, in ext4_get_group_desc() argument
270 ext4_group_t ngroups = ext4_get_groups_count(sb); in ext4_get_group_desc()
272 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_get_group_desc()
275 ext4_error(sb, "block_group >= groups_count - block_group = %u," in ext4_get_group_desc()
281 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb); in ext4_get_group_desc()
282 offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1); in ext4_get_group_desc()
284 ext4_error(sb, "Group descriptor not loaded - " in ext4_get_group_desc()
292 offset * EXT4_DESC_SIZE(sb)); in ext4_get_group_desc()
302 static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb, in ext4_valid_block_bitmap() argument
307 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_valid_block_bitmap()
310 ext4_grpblk_t max_bit = EXT4_CLUSTERS_PER_GROUP(sb); in ext4_valid_block_bitmap()
314 if (ext4_has_feature_flex_bg(sb)) { in ext4_valid_block_bitmap()
323 group_first_block = ext4_group_first_block_no(sb, block_group); in ext4_valid_block_bitmap()
326 blk = ext4_block_bitmap(sb, desc); in ext4_valid_block_bitmap()
334 blk = ext4_inode_bitmap(sb, desc); in ext4_valid_block_bitmap()
342 blk = ext4_inode_table(sb, desc); in ext4_valid_block_bitmap()
357 static int ext4_validate_block_bitmap(struct super_block *sb, in ext4_validate_block_bitmap() argument
363 struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); in ext4_validate_block_bitmap()
370 ext4_lock_group(sb, block_group); in ext4_validate_block_bitmap()
373 if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group, in ext4_validate_block_bitmap()
375 ext4_unlock_group(sb, block_group); in ext4_validate_block_bitmap()
376 ext4_error(sb, "bg %u: bad block bitmap checksum", block_group); in ext4_validate_block_bitmap()
377 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_validate_block_bitmap()
381 blk = ext4_valid_block_bitmap(sb, desc, block_group, bh); in ext4_validate_block_bitmap()
383 ext4_unlock_group(sb, block_group); in ext4_validate_block_bitmap()
384 ext4_error(sb, "bg %u: block %llu: invalid block bitmap", in ext4_validate_block_bitmap()
386 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_validate_block_bitmap()
392 ext4_unlock_group(sb, block_group); in ext4_validate_block_bitmap()
407 ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group) in ext4_read_block_bitmap_nowait() argument
410 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_read_block_bitmap_nowait()
415 desc = ext4_get_group_desc(sb, block_group, NULL); in ext4_read_block_bitmap_nowait()
418 bitmap_blk = ext4_block_bitmap(sb, desc); in ext4_read_block_bitmap_nowait()
421 ext4_error(sb, "Invalid block bitmap block %llu in " in ext4_read_block_bitmap_nowait()
423 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_read_block_bitmap_nowait()
427 bh = sb_getblk(sb, bitmap_blk); in ext4_read_block_bitmap_nowait()
429 ext4_warning(sb, "Cannot get buffer for block bitmap - " in ext4_read_block_bitmap_nowait()
443 ext4_lock_group(sb, block_group); in ext4_read_block_bitmap_nowait()
444 if (ext4_has_group_desc_csum(sb) && in ext4_read_block_bitmap_nowait()
447 ext4_unlock_group(sb, block_group); in ext4_read_block_bitmap_nowait()
449 ext4_error(sb, "Block bitmap for bg 0 marked " in ext4_read_block_bitmap_nowait()
454 err = ext4_init_block_bitmap(sb, bh, block_group, desc); in ext4_read_block_bitmap_nowait()
458 ext4_unlock_group(sb, block_group); in ext4_read_block_bitmap_nowait()
461 ext4_error(sb, "Failed to init block bitmap for group " in ext4_read_block_bitmap_nowait()
467 ext4_unlock_group(sb, block_group); in ext4_read_block_bitmap_nowait()
481 trace_ext4_read_block_bitmap_load(sb, block_group); in ext4_read_block_bitmap_nowait()
487 err = ext4_validate_block_bitmap(sb, desc, block_group, bh); in ext4_read_block_bitmap_nowait()
497 int ext4_wait_block_bitmap(struct super_block *sb, ext4_group_t block_group, in ext4_wait_block_bitmap() argument
504 desc = ext4_get_group_desc(sb, block_group, NULL); in ext4_wait_block_bitmap()
509 ext4_error(sb, "Cannot read block bitmap - " in ext4_wait_block_bitmap()
512 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_wait_block_bitmap()
518 return ext4_validate_block_bitmap(sb, desc, block_group, bh); in ext4_wait_block_bitmap()
522 ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group) in ext4_read_block_bitmap() argument
527 bh = ext4_read_block_bitmap_nowait(sb, block_group); in ext4_read_block_bitmap()
530 err = ext4_wait_block_bitmap(sb, block_group, bh); in ext4_read_block_bitmap()
615 int ext4_should_retry_alloc(struct super_block *sb, int *retries) in ext4_should_retry_alloc() argument
617 if (!ext4_has_free_clusters(EXT4_SB(sb), 1, 0) || in ext4_should_retry_alloc()
619 !EXT4_SB(sb)->s_journal) in ext4_should_retry_alloc()
623 if (EXT4_SB(sb)->s_mb_free_pending == 0) in ext4_should_retry_alloc()
626 jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id); in ext4_should_retry_alloc()
627 jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal); in ext4_should_retry_alloc()
677 ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) in ext4_count_free_clusters() argument
682 ext4_group_t ngroups = ext4_get_groups_count(sb); in ext4_count_free_clusters()
690 es = EXT4_SB(sb)->s_es; in ext4_count_free_clusters()
696 gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_free_clusters()
700 if (EXT4_SB(sb)->s_group_info) in ext4_count_free_clusters()
701 grp = ext4_get_group_info(sb, i); in ext4_count_free_clusters()
703 desc_count += ext4_free_group_clusters(sb, gdp); in ext4_count_free_clusters()
705 bitmap_bh = ext4_read_block_bitmap(sb, i); in ext4_count_free_clusters()
712 EXT4_CLUSTERS_PER_GROUP(sb) / 8); in ext4_count_free_clusters()
714 i, ext4_free_group_clusters(sb, gdp), x); in ext4_count_free_clusters()
720 EXT4_NUM_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)), in ext4_count_free_clusters()
726 gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_free_clusters()
730 if (EXT4_SB(sb)->s_group_info) in ext4_count_free_clusters()
731 grp = ext4_get_group_info(sb, i); in ext4_count_free_clusters()
733 desc_count += ext4_free_group_clusters(sb, gdp); in ext4_count_free_clusters()
761 int ext4_bg_has_super(struct super_block *sb, ext4_group_t group) in ext4_bg_has_super() argument
763 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_bg_has_super()
767 if (ext4_has_feature_sparse_super2(sb)) { in ext4_bg_has_super()
773 if ((group <= 1) || !ext4_has_feature_sparse_super(sb)) in ext4_bg_has_super()
784 static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb, in ext4_bg_num_gdb_meta() argument
787 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); in ext4_bg_num_gdb_meta()
788 ext4_group_t first = metagroup * EXT4_DESC_PER_BLOCK(sb); in ext4_bg_num_gdb_meta()
789 ext4_group_t last = first + EXT4_DESC_PER_BLOCK(sb) - 1; in ext4_bg_num_gdb_meta()
796 static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, in ext4_bg_num_gdb_nometa() argument
799 if (!ext4_bg_has_super(sb, group)) in ext4_bg_num_gdb_nometa()
802 if (ext4_has_feature_meta_bg(sb)) in ext4_bg_num_gdb_nometa()
803 return le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg); in ext4_bg_num_gdb_nometa()
805 return EXT4_SB(sb)->s_gdb_count; in ext4_bg_num_gdb_nometa()
817 unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group) in ext4_bg_num_gdb() argument
820 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg); in ext4_bg_num_gdb()
821 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb); in ext4_bg_num_gdb()
823 if (!ext4_has_feature_meta_bg(sb) || metagroup < first_meta_bg) in ext4_bg_num_gdb()
824 return ext4_bg_num_gdb_nometa(sb, group); in ext4_bg_num_gdb()
826 return ext4_bg_num_gdb_meta(sb,group); in ext4_bg_num_gdb()
834 static unsigned ext4_num_base_meta_clusters(struct super_block *sb, in ext4_num_base_meta_clusters() argument
837 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_num_base_meta_clusters()
841 num = ext4_bg_has_super(sb, block_group); in ext4_num_base_meta_clusters()
843 if (!ext4_has_feature_meta_bg(sb) || in ext4_num_base_meta_clusters()
847 num += ext4_bg_num_gdb(sb, block_group); in ext4_num_base_meta_clusters()
851 num += ext4_bg_num_gdb(sb, block_group); in ext4_num_base_meta_clusters()