Lines Matching refs:sb

46 int ext4_resize_begin(struct super_block *sb)  in ext4_resize_begin()  argument
48 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_resize_begin()
59 !ext4_has_feature_resize_inode(sb)) { in ext4_resize_begin()
60 ext4_error(sb, "resize_inode disabled but reserved GDT blocks non-zero"); in ext4_resize_begin()
71 ext4_warning(sb, "won't resize using backup superblock at %llu", in ext4_resize_begin()
81 ext4_warning(sb, "There are errors in the filesystem, " in ext4_resize_begin()
86 if (ext4_has_feature_sparse_super2(sb)) { in ext4_resize_begin()
87 ext4_msg(sb, KERN_ERR, "Online resizing not supported with sparse_super2"); in ext4_resize_begin()
98 int ext4_resize_end(struct super_block *sb, bool update_backups) in ext4_resize_end() argument
100 clear_bit_unlock(EXT4_FLAGS_RESIZING, &EXT4_SB(sb)->s_ext4_flags); in ext4_resize_end()
103 return ext4_update_overhead(sb, true); in ext4_resize_end()
107 static ext4_grpblk_t ext4_group_overhead_blocks(struct super_block *sb, in ext4_group_overhead_blocks() argument
110 overhead = ext4_bg_num_gdb(sb, group); in ext4_group_overhead_blocks()
111 if (ext4_bg_has_super(sb, group)) in ext4_group_overhead_blocks()
113 le16_to_cpu(EXT4_SB(sb)->s_es->s_reserved_gdt_blocks); in ext4_group_overhead_blocks()
120 static int verify_group_input(struct super_block *sb, in verify_group_input() argument
123 struct ext4_sb_info *sbi = EXT4_SB(sb); in verify_group_input()
136 ext4_warning(sb, "Cannot add at group %u (only %u groups)", in verify_group_input()
141 overhead = ext4_group_overhead_blocks(sb, group); in verify_group_input()
147 if (test_opt(sb, DEBUG)) in verify_group_input()
150 ext4_bg_has_super(sb, input->group) ? "normal" : in verify_group_input()
154 ext4_get_group_no_and_offset(sb, start, NULL, &offset); in verify_group_input()
156 ext4_warning(sb, "Last group not full"); in verify_group_input()
158 ext4_warning(sb, "Reserved blocks too high (%u)", in verify_group_input()
161 ext4_warning(sb, "Bad blocks count %u", in verify_group_input()
163 else if (IS_ERR(bh = ext4_sb_bread(sb, end - 1, 0))) { in verify_group_input()
166 ext4_warning(sb, "Cannot read last block (%llu)", in verify_group_input()
169 ext4_warning(sb, "Block bitmap not in group (block %llu)", in verify_group_input()
172 ext4_warning(sb, "Inode bitmap not in group (block %llu)", in verify_group_input()
176 ext4_warning(sb, "Inode table not in group (blocks %llu-%llu)", in verify_group_input()
179 ext4_warning(sb, "Block bitmap same as inode bitmap (%llu)", in verify_group_input()
182 ext4_warning(sb, "Block bitmap (%llu) in inode table " in verify_group_input()
187 ext4_warning(sb, "Inode bitmap (%llu) in inode table " in verify_group_input()
192 ext4_warning(sb, "Block bitmap (%llu) in GDT table (%llu-%llu)", in verify_group_input()
196 ext4_warning(sb, "Inode bitmap (%llu) in GDT table (%llu-%llu)", in verify_group_input()
201 ext4_warning(sb, "Inode table (%llu-%llu) overlaps GDT table " in verify_group_input()
304 static int ext4_alloc_group_tables(struct super_block *sb, in ext4_alloc_group_tables() argument
332 start_blk = ext4_group_first_block_no(sb, src_group); in ext4_alloc_group_tables()
335 overhead = ext4_group_overhead_blocks(sb, src_group); in ext4_alloc_group_tables()
342 overhead = ext4_group_overhead_blocks(sb, src_group); in ext4_alloc_group_tables()
354 group = ext4_get_group_number(sb, start_blk - 1); in ext4_alloc_group_tables()
365 group = ext4_get_group_number(sb, start_blk - 1); in ext4_alloc_group_tables()
373 unsigned int itb = EXT4_SB(sb)->s_itb_per_group; in ext4_alloc_group_tables()
379 group = ext4_get_group_number(sb, start_blk); in ext4_alloc_group_tables()
380 next_group_start = ext4_group_first_block_no(sb, group + 1); in ext4_alloc_group_tables()
392 start_blk += EXT4_SB(sb)->s_itb_per_group; in ext4_alloc_group_tables()
398 EXT4_NUM_B2C(EXT4_SB(sb), in ext4_alloc_group_tables()
402 if (test_opt(sb, DEBUG)) { in ext4_alloc_group_tables()
413 ext4_bg_has_super(sb, group + i) ? "normal" : in ext4_alloc_group_tables()
423 static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, in bclean() argument
429 bh = sb_getblk(sb, blk); in bclean()
433 err = ext4_journal_get_write_access(handle, sb, bh, EXT4_JTR_NONE); in bclean()
438 memset(bh->b_data, 0, sb->s_blocksize); in bclean()
460 static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle, in set_flexbg_block_bitmap() argument
464 struct ext4_sb_info *sbi = EXT4_SB(sb); in set_flexbg_block_bitmap()
476 group = ext4_get_group_number(sb, EXT4_C2B(sbi, first_cluster)); in set_flexbg_block_bitmap()
477 start = EXT4_B2C(sbi, ext4_group_first_block_no(sb, group)); in set_flexbg_block_bitmap()
480 count2 = EXT4_CLUSTERS_PER_GROUP(sb) - (first_cluster - start); in set_flexbg_block_bitmap()
493 bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap); in set_flexbg_block_bitmap()
498 err = ext4_journal_get_write_access(handle, sb, bh, in set_flexbg_block_bitmap()
531 static int setup_new_flex_group_blocks(struct super_block *sb, in setup_new_flex_group_blocks() argument
534 int group_table_count[] = {1, 1, EXT4_SB(sb)->s_itb_per_group}; in setup_new_flex_group_blocks()
537 struct ext4_sb_info *sbi = EXT4_SB(sb); in setup_new_flex_group_blocks()
551 meta_bg = ext4_has_feature_meta_bg(sb); in setup_new_flex_group_blocks()
554 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, EXT4_MAX_TRANS_DATA); in setup_new_flex_group_blocks()
563 gdblocks = ext4_bg_num_gdb(sb, group); in setup_new_flex_group_blocks()
564 start = ext4_group_first_block_no(sb, group); in setup_new_flex_group_blocks()
566 if (meta_bg == 0 && !ext4_bg_has_super(sb, group)) in setup_new_flex_group_blocks()
572 block = start + ext4_bg_has_super(sb, group); in setup_new_flex_group_blocks()
582 gdb = sb_getblk(sb, block); in setup_new_flex_group_blocks()
589 err = ext4_journal_get_write_access(handle, sb, gdb, in setup_new_flex_group_blocks()
610 if (ext4_bg_has_super(sb, group)) { in setup_new_flex_group_blocks()
611 err = sb_issue_zeroout(sb, gdblocks + start + 1, in setup_new_flex_group_blocks()
626 err = sb_issue_zeroout(sb, block, sbi->s_itb_per_group, in setup_new_flex_group_blocks()
641 bh = bclean(handle, sb, block); in setup_new_flex_group_blocks()
646 overhead = ext4_group_overhead_blocks(sb, group); in setup_new_flex_group_blocks()
654 sb->s_blocksize * 8, bh->b_data); in setup_new_flex_group_blocks()
670 bh = bclean(handle, sb, block); in setup_new_flex_group_blocks()
676 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), in setup_new_flex_group_blocks()
677 sb->s_blocksize * 8, bh->b_data); in setup_new_flex_group_blocks()
695 err = set_flexbg_block_bitmap(sb, handle, in setup_new_flex_group_blocks()
708 err = set_flexbg_block_bitmap(sb, handle, in setup_new_flex_group_blocks()
733 unsigned int ext4_list_backups(struct super_block *sb, unsigned int *three, in ext4_list_backups() argument
736 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_list_backups()
741 if (ext4_has_feature_sparse_super2(sb)) { in ext4_list_backups()
751 if (!ext4_has_feature_sparse_super(sb)) { in ext4_list_backups()
777 static int verify_reserved_gdb(struct super_block *sb, in verify_reserved_gdb() argument
789 while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) { in verify_reserved_gdb()
791 grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){ in verify_reserved_gdb()
792 ext4_warning(sb, "reserved GDT %llu" in verify_reserved_gdb()
796 (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) + in verify_reserved_gdb()
800 if (++gdbackups > EXT4_ADDR_PER_BLOCK(sb)) in verify_reserved_gdb()
823 struct super_block *sb = inode->i_sb; in add_new_gdb() local
824 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in add_new_gdb()
825 unsigned long gdb_num = group / EXT4_DESC_PER_BLOCK(sb); in add_new_gdb()
826 ext4_fsblk_t gdblock = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num; in add_new_gdb()
835 if (test_opt(sb, DEBUG)) in add_new_gdb()
840 gdb_bh = ext4_sb_bread(sb, gdblock, 0); in add_new_gdb()
844 gdbackups = verify_reserved_gdb(sb, group, gdb_bh); in add_new_gdb()
851 dind = ext4_sb_bread(sb, le32_to_cpu(*data), 0); in add_new_gdb()
859 if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) { in add_new_gdb()
860 ext4_warning(sb, "new group %u GDT block %llu not reserved", in add_new_gdb()
866 BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access"); in add_new_gdb()
867 err = ext4_journal_get_write_access(handle, sb, EXT4_SB(sb)->s_sbh, in add_new_gdb()
873 err = ext4_journal_get_write_access(handle, sb, gdb_bh, EXT4_JTR_NONE); in add_new_gdb()
878 err = ext4_journal_get_write_access(handle, sb, dind, EXT4_JTR_NONE); in add_new_gdb()
880 ext4_std_error(sb, err); in add_new_gdb()
893 ext4_warning(sb, "not enough memory for %lu groups", in add_new_gdb()
907 data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)] = 0; in add_new_gdb()
910 ext4_std_error(sb, err); in add_new_gdb()
913 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> in add_new_gdb()
914 (9 - EXT4_SB(sb)->s_cluster_bits); in add_new_gdb()
916 memset(gdb_bh->b_data, 0, sb->s_blocksize); in add_new_gdb()
919 ext4_std_error(sb, err); in add_new_gdb()
926 o_group_desc = rcu_dereference(EXT4_SB(sb)->s_group_desc); in add_new_gdb()
928 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); in add_new_gdb()
931 rcu_assign_pointer(EXT4_SB(sb)->s_group_desc, n_group_desc); in add_new_gdb()
932 EXT4_SB(sb)->s_gdb_count++; in add_new_gdb()
935 lock_buffer(EXT4_SB(sb)->s_sbh); in add_new_gdb()
937 ext4_superblock_csum_set(sb); in add_new_gdb()
938 unlock_buffer(EXT4_SB(sb)->s_sbh); in add_new_gdb()
939 err = ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); in add_new_gdb()
941 ext4_std_error(sb, err); in add_new_gdb()
962 static int add_new_gdb_meta_bg(struct super_block *sb, in add_new_gdb_meta_bg() argument
967 unsigned long gdb_num = group / EXT4_DESC_PER_BLOCK(sb); in add_new_gdb_meta_bg()
970 gdblock = ext4_group_first_block_no(sb, group) + in add_new_gdb_meta_bg()
971 ext4_bg_has_super(sb, group); in add_new_gdb_meta_bg()
972 gdb_bh = ext4_sb_bread(sb, gdblock, 0); in add_new_gdb_meta_bg()
980 ext4_warning(sb, "not enough memory for %lu groups", in add_new_gdb_meta_bg()
986 o_group_desc = rcu_dereference(EXT4_SB(sb)->s_group_desc); in add_new_gdb_meta_bg()
988 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); in add_new_gdb_meta_bg()
993 err = ext4_journal_get_write_access(handle, sb, gdb_bh, EXT4_JTR_NONE); in add_new_gdb_meta_bg()
1000 rcu_assign_pointer(EXT4_SB(sb)->s_group_desc, n_group_desc); in add_new_gdb_meta_bg()
1001 EXT4_SB(sb)->s_gdb_count++; in add_new_gdb_meta_bg()
1022 struct super_block *sb = inode->i_sb; in reserve_backup_gdb() local
1023 int reserved_gdb =le16_to_cpu(EXT4_SB(sb)->s_es->s_reserved_gdt_blocks); in reserve_backup_gdb()
1024 int cluster_bits = EXT4_SB(sb)->s_cluster_bits; in reserve_backup_gdb()
1039 dind = ext4_sb_bread(sb, le32_to_cpu(*data), 0); in reserve_backup_gdb()
1046 blk = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + EXT4_SB(sb)->s_gdb_count; in reserve_backup_gdb()
1047 data = (__le32 *)dind->b_data + (EXT4_SB(sb)->s_gdb_count % in reserve_backup_gdb()
1048 EXT4_ADDR_PER_BLOCK(sb)); in reserve_backup_gdb()
1049 end = (__le32 *)dind->b_data + EXT4_ADDR_PER_BLOCK(sb); in reserve_backup_gdb()
1054 ext4_warning(sb, "reserved block %llu" in reserve_backup_gdb()
1061 primary[res] = ext4_sb_bread(sb, blk, 0); in reserve_backup_gdb()
1067 gdbackups = verify_reserved_gdb(sb, group, primary[res]); in reserve_backup_gdb()
1079 if ((err = ext4_journal_get_write_access(handle, sb, primary[i], in reserve_backup_gdb()
1091 blk = group * EXT4_BLOCKS_PER_GROUP(sb); in reserve_backup_gdb()
1101 inode->i_blocks += reserved_gdb * sb->s_blocksize >> (9 - cluster_bits); in reserve_backup_gdb()
1115 static inline void ext4_set_block_group_nr(struct super_block *sb, char *data, in ext4_set_block_group_nr() argument
1121 if (ext4_has_metadata_csum(sb)) in ext4_set_block_group_nr()
1122 es->s_checksum = ext4_superblock_csum(sb, es); in ext4_set_block_group_nr()
1141 static void update_backups(struct super_block *sb, sector_t blk_off, char *data, in update_backups() argument
1144 struct ext4_sb_info *sbi = EXT4_SB(sb); in update_backups()
1146 const int bpg = EXT4_BLOCKS_PER_GROUP(sb); in update_backups()
1151 int rest = sb->s_blocksize - size; in update_backups()
1155 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, EXT4_MAX_TRANS_DATA); in update_backups()
1163 group = ext4_list_backups(sb, &three, &five, &seven); in update_backups()
1166 group = ext4_get_group_number(sb, blk_off) + 1; in update_backups()
1167 last = (ext4_group_t)(group + EXT4_DESC_PER_BLOCK(sb) - 2); in update_backups()
1173 int has_super = ext4_bg_has_super(sb, group); in update_backups()
1174 ext4_fsblk_t first_block = ext4_group_first_block_no(sb, group); in update_backups()
1186 bh = sb_getblk(sb, backup_block); in update_backups()
1193 ext4_group_first_block_no(sb, group)); in update_backups()
1195 if ((err = ext4_journal_get_write_access(handle, sb, bh, in update_backups()
1205 ext4_set_block_group_nr(sb, bh->b_data, group); in update_backups()
1210 ext4_std_error(sb, err); in update_backups()
1214 group = ext4_list_backups(sb, &three, &five, &seven); in update_backups()
1235 ext4_warning(sb, "can't update backup for group %u (err %d), " in update_backups()
1253 static int ext4_add_new_descs(handle_t *handle, struct super_block *sb, in ext4_add_new_descs() argument
1257 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_add_new_descs()
1263 meta_bg = ext4_has_feature_meta_bg(sb); in ext4_add_new_descs()
1265 int reserved_gdb = ext4_bg_has_super(sb, group) ? in ext4_add_new_descs()
1268 gdb_off = group % EXT4_DESC_PER_BLOCK(sb); in ext4_add_new_descs()
1269 gdb_num = group / EXT4_DESC_PER_BLOCK(sb); in ext4_add_new_descs()
1281 err = ext4_journal_get_write_access(handle, sb, gdb_bh, in ext4_add_new_descs()
1284 if (!err && reserved_gdb && ext4_bg_num_gdb(sb, group)) in ext4_add_new_descs()
1287 err = add_new_gdb_meta_bg(sb, handle, group); in ext4_add_new_descs()
1297 static struct buffer_head *ext4_get_bitmap(struct super_block *sb, __u64 block) in ext4_get_bitmap() argument
1299 struct buffer_head *bh = sb_getblk(sb, block); in ext4_get_bitmap()
1312 static int ext4_set_bitmap_checksums(struct super_block *sb, in ext4_set_bitmap_checksums() argument
1318 if (!ext4_has_metadata_csum(sb)) in ext4_set_bitmap_checksums()
1321 bh = ext4_get_bitmap(sb, group_data->inode_bitmap); in ext4_set_bitmap_checksums()
1324 ext4_inode_bitmap_csum_set(sb, gdp, bh); in ext4_set_bitmap_checksums()
1327 bh = ext4_get_bitmap(sb, group_data->block_bitmap); in ext4_set_bitmap_checksums()
1330 ext4_block_bitmap_csum_set(sb, gdp, bh); in ext4_set_bitmap_checksums()
1339 static int ext4_setup_new_descs(handle_t *handle, struct super_block *sb, in ext4_setup_new_descs() argument
1344 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_setup_new_descs()
1354 gdb_off = group % EXT4_DESC_PER_BLOCK(sb); in ext4_setup_new_descs()
1355 gdb_num = group / EXT4_DESC_PER_BLOCK(sb); in ext4_setup_new_descs()
1363 gdb_off * EXT4_DESC_SIZE(sb)); in ext4_setup_new_descs()
1365 memset(gdp, 0, EXT4_DESC_SIZE(sb)); in ext4_setup_new_descs()
1366 ext4_block_bitmap_set(sb, gdp, group_data->block_bitmap); in ext4_setup_new_descs()
1367 ext4_inode_bitmap_set(sb, gdp, group_data->inode_bitmap); in ext4_setup_new_descs()
1368 err = ext4_set_bitmap_checksums(sb, gdp, group_data); in ext4_setup_new_descs()
1370 ext4_std_error(sb, err); in ext4_setup_new_descs()
1374 ext4_inode_table_set(sb, gdp, group_data->inode_table); in ext4_setup_new_descs()
1375 ext4_free_group_clusters_set(sb, gdp, in ext4_setup_new_descs()
1377 ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb)); in ext4_setup_new_descs()
1378 if (ext4_has_group_desc_csum(sb)) in ext4_setup_new_descs()
1379 ext4_itable_unused_set(sb, gdp, in ext4_setup_new_descs()
1380 EXT4_INODES_PER_GROUP(sb)); in ext4_setup_new_descs()
1382 ext4_group_desc_csum_set(sb, group, gdp); in ext4_setup_new_descs()
1386 ext4_std_error(sb, err); in ext4_setup_new_descs()
1394 err = ext4_mb_add_groupinfo(sb, group, gdp); in ext4_setup_new_descs()
1401 static void ext4_add_overhead(struct super_block *sb, in ext4_add_overhead() argument
1404 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_add_overhead()
1419 static void ext4_update_super(struct super_block *sb, in ext4_update_super() argument
1426 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_update_super()
1454 le32_add_cpu(&es->s_inodes_count, EXT4_INODES_PER_GROUP(sb) * in ext4_update_super()
1456 le32_add_cpu(&es->s_free_inodes_count, EXT4_INODES_PER_GROUP(sb) * in ext4_update_super()
1483 (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb))); in ext4_update_super()
1494 EXT4_INODES_PER_GROUP(sb) * flex_gd->count); in ext4_update_super()
1498 if (ext4_has_feature_flex_bg(sb) && sbi->s_log_groups_per_flex) { in ext4_update_super()
1506 atomic_add(EXT4_INODES_PER_GROUP(sb) * flex_gd->count, in ext4_update_super()
1517 if (ext4_has_feature_bigalloc(sb) && (sbi->s_overhead != 0)) in ext4_update_super()
1518 ext4_add_overhead(sb, in ext4_update_super()
1521 ext4_calculate_overhead(sb); in ext4_update_super()
1524 ext4_superblock_csum_set(sb); in ext4_update_super()
1526 if (test_opt(sb, DEBUG)) in ext4_update_super()
1536 static int ext4_flex_group_add(struct super_block *sb, in ext4_flex_group_add() argument
1540 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_flex_group_add()
1553 ext4_get_group_no_and_offset(sb, o_blocks_count, &group, &last); in ext4_flex_group_add()
1556 err = setup_new_flex_group_blocks(sb, flex_gd); in ext4_flex_group_add()
1568 credit += 1 + DIV_ROUND_UP(flex_gd->count, EXT4_DESC_PER_BLOCK(sb)); in ext4_flex_group_add()
1570 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, credit); in ext4_flex_group_add()
1577 err = ext4_journal_get_write_access(handle, sb, sbi->s_sbh, in ext4_flex_group_add()
1584 err = ext4_add_new_descs(handle, sb, group, in ext4_flex_group_add()
1589 err = ext4_setup_new_descs(handle, sb, flex_gd); in ext4_flex_group_add()
1593 ext4_update_super(sb, flex_gd); in ext4_flex_group_add()
1603 int gdb_num = group / EXT4_DESC_PER_BLOCK(sb); in ext4_flex_group_add()
1605 EXT4_DESC_PER_BLOCK(sb)); in ext4_flex_group_add()
1606 int meta_bg = ext4_has_feature_meta_bg(sb) && in ext4_flex_group_add()
1609 ext4_group_first_block_no(sb, 0); in ext4_flex_group_add()
1611 update_backups(sb, ext4_group_first_block_no(sb, 0), in ext4_flex_group_add()
1618 update_backups(sb, gdb_bh->b_blocknr - padding_blocks, in ext4_flex_group_add()
1626 static int ext4_setup_next_flex_gd(struct super_block *sb, in ext4_setup_next_flex_gd() argument
1630 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_setup_next_flex_gd()
1641 clusters_per_group = EXT4_CLUSTERS_PER_GROUP(sb); in ext4_setup_next_flex_gd()
1648 ext4_get_group_no_and_offset(sb, o_blocks_count, &group, &last); in ext4_setup_next_flex_gd()
1650 ext4_get_group_no_and_offset(sb, n_blocks_count - 1, &n_group, &last); in ext4_setup_next_flex_gd()
1662 group_data[i].blocks_count = EXT4_BLOCKS_PER_GROUP(sb); in ext4_setup_next_flex_gd()
1663 overhead = ext4_group_overhead_blocks(sb, group + i); in ext4_setup_next_flex_gd()
1665 group_data[i].free_clusters_count = EXT4_CLUSTERS_PER_GROUP(sb); in ext4_setup_next_flex_gd()
1666 if (ext4_has_group_desc_csum(sb)) { in ext4_setup_next_flex_gd()
1669 if (!test_opt(sb, INIT_INODE_TABLE)) in ext4_setup_next_flex_gd()
1675 if (last_group == n_group && ext4_has_group_desc_csum(sb)) in ext4_setup_next_flex_gd()
1701 int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) in ext4_group_add() argument
1704 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_group_add()
1706 int reserved_gdb = ext4_bg_has_super(sb, input->group) ? in ext4_group_add()
1713 gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb); in ext4_group_add()
1715 if (gdb_off == 0 && !ext4_has_feature_sparse_super(sb)) { in ext4_group_add()
1716 ext4_warning(sb, "Can't resize non-sparse filesystem further"); in ext4_group_add()
1722 ext4_warning(sb, "blocks_count overflow"); in ext4_group_add()
1726 if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) < in ext4_group_add()
1728 ext4_warning(sb, "inodes_count overflow"); in ext4_group_add()
1733 if (!ext4_has_feature_resize_inode(sb) || in ext4_group_add()
1735 ext4_warning(sb, in ext4_group_add()
1739 inode = ext4_iget(sb, EXT4_RESIZE_INO, EXT4_IGET_SPECIAL); in ext4_group_add()
1741 ext4_warning(sb, "Error opening resize inode"); in ext4_group_add()
1747 err = verify_group_input(sb, input); in ext4_group_add()
1751 err = ext4_alloc_flex_bg_array(sb, input->group + 1); in ext4_group_add()
1755 err = ext4_mb_alloc_groupinfo(sb, input->group + 1); in ext4_group_add()
1762 err = ext4_flex_group_add(sb, inode, &flex_gd); in ext4_group_add()
1771 static int ext4_group_extend_no_check(struct super_block *sb, in ext4_group_extend_no_check() argument
1774 struct ext4_super_block *es = EXT4_SB(sb)->s_es; in ext4_group_extend_no_check()
1781 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, 3); in ext4_group_extend_no_check()
1784 ext4_warning(sb, "error %d on journal start", err); in ext4_group_extend_no_check()
1788 BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access"); in ext4_group_extend_no_check()
1789 err = ext4_journal_get_write_access(handle, sb, EXT4_SB(sb)->s_sbh, in ext4_group_extend_no_check()
1792 ext4_warning(sb, "error %d on journal write access", err); in ext4_group_extend_no_check()
1796 lock_buffer(EXT4_SB(sb)->s_sbh); in ext4_group_extend_no_check()
1799 ext4_superblock_csum_set(sb); in ext4_group_extend_no_check()
1800 unlock_buffer(EXT4_SB(sb)->s_sbh); in ext4_group_extend_no_check()
1804 err = ext4_group_add_blocks(handle, sb, o_blocks_count, add); in ext4_group_extend_no_check()
1807 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); in ext4_group_extend_no_check()
1816 if (test_opt(sb, DEBUG)) in ext4_group_extend_no_check()
1819 update_backups(sb, ext4_group_first_block_no(sb, 0), in ext4_group_extend_no_check()
1835 int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, in ext4_group_extend() argument
1846 if (test_opt(sb, DEBUG)) in ext4_group_extend()
1847 ext4_msg(sb, KERN_DEBUG, in ext4_group_extend()
1854 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { in ext4_group_extend()
1855 ext4_msg(sb, KERN_ERR, in ext4_group_extend()
1862 ext4_warning(sb, "can't shrink FS - resize aborted"); in ext4_group_extend()
1867 ext4_get_group_no_and_offset(sb, o_blocks_count, &group, &last); in ext4_group_extend()
1870 ext4_warning(sb, "need to use ext2online to resize further"); in ext4_group_extend()
1874 add = EXT4_BLOCKS_PER_GROUP(sb) - last; in ext4_group_extend()
1877 ext4_warning(sb, "blocks_count overflow"); in ext4_group_extend()
1885 ext4_warning(sb, "will only finish group (%llu blocks, %u new)", in ext4_group_extend()
1889 bh = ext4_sb_bread(sb, o_blocks_count + add - 1, 0); in ext4_group_extend()
1891 ext4_warning(sb, "can't read last block, resize aborted"); in ext4_group_extend()
1896 return ext4_group_extend_no_check(sb, o_blocks_count, add); in ext4_group_extend()
1900 static int num_desc_blocks(struct super_block *sb, ext4_group_t groups) in num_desc_blocks() argument
1902 return (groups + EXT4_DESC_PER_BLOCK(sb) - 1) / EXT4_DESC_PER_BLOCK(sb); in num_desc_blocks()
1910 static int ext4_convert_meta_bg(struct super_block *sb, struct inode *inode) in ext4_convert_meta_bg() argument
1913 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_convert_meta_bg()
1920 ext4_msg(sb, KERN_INFO, "Converting file system to meta_bg"); in ext4_convert_meta_bg()
1923 ext4_error(sb, "Unexpected non-zero " in ext4_convert_meta_bg()
1945 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, credits); in ext4_convert_meta_bg()
1950 err = ext4_journal_get_write_access(handle, sb, sbi->s_sbh, in ext4_convert_meta_bg()
1956 ext4_clear_feature_resize_inode(sb); in ext4_convert_meta_bg()
1957 ext4_set_feature_meta_bg(sb); in ext4_convert_meta_bg()
1959 cpu_to_le32(num_desc_blocks(sb, sbi->s_groups_count)); in ext4_convert_meta_bg()
1960 ext4_superblock_csum_set(sb); in ext4_convert_meta_bg()
1965 ext4_std_error(sb, err); in ext4_convert_meta_bg()
1979 ext4_std_error(sb, err); in ext4_convert_meta_bg()
1987 ext4_error(sb, "corrupted/inconsistent resize inode"); in ext4_convert_meta_bg()
1997 int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count) in ext4_resize_fs() argument
2000 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_resize_fs()
2017 bh = ext4_sb_bread(sb, n_blocks_count - 1, 0); in ext4_resize_fs()
2019 ext4_warning(sb, "can't read last block, resize aborted"); in ext4_resize_fs()
2031 if (ext4_has_feature_bigalloc(sb)) in ext4_resize_fs()
2032 n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1); in ext4_resize_fs()
2037 ext4_msg(sb, KERN_INFO, "resizing filesystem from %llu " in ext4_resize_fs()
2042 ext4_warning(sb, "can't shrink FS - resize aborted"); in ext4_resize_fs()
2050 n_group = ext4_get_group_number(sb, n_blocks_count - 1); in ext4_resize_fs()
2051 if (n_group >= (0xFFFFFFFFUL / EXT4_INODES_PER_GROUP(sb))) { in ext4_resize_fs()
2052 ext4_warning(sb, "resize would cause inodes_count overflow"); in ext4_resize_fs()
2055 ext4_get_group_no_and_offset(sb, o_blocks_count - 1, &o_group, &offset); in ext4_resize_fs()
2057 n_desc_blocks = num_desc_blocks(sb, n_group + 1); in ext4_resize_fs()
2058 o_desc_blocks = num_desc_blocks(sb, sbi->s_groups_count); in ext4_resize_fs()
2060 meta_bg = ext4_has_feature_meta_bg(sb); in ext4_resize_fs()
2062 if (ext4_has_feature_resize_inode(sb)) { in ext4_resize_fs()
2064 ext4_error(sb, "resize_inode and meta_bg enabled " in ext4_resize_fs()
2073 n_group = n_desc_blocks * EXT4_DESC_PER_BLOCK(sb); in ext4_resize_fs()
2075 EXT4_BLOCKS_PER_GROUP(sb) + in ext4_resize_fs()
2081 resize_inode = ext4_iget(sb, EXT4_RESIZE_INO, in ext4_resize_fs()
2084 ext4_warning(sb, "Error opening resize inode"); in ext4_resize_fs()
2090 err = ext4_convert_meta_bg(sb, resize_inode); in ext4_resize_fs()
2111 if ((ext4_group_first_block_no(sb, n_group) + in ext4_resize_fs()
2112 ext4_group_overhead_blocks(sb, n_group) + 2 + in ext4_resize_fs()
2114 n_blocks_count = ext4_group_first_block_no(sb, n_group); in ext4_resize_fs()
2128 add = EXT4_C2B(sbi, EXT4_CLUSTERS_PER_GROUP(sb) - (offset + 1)); in ext4_resize_fs()
2130 err = ext4_group_extend_no_check(sb, o_blocks_count, add); in ext4_resize_fs()
2138 err = ext4_alloc_flex_bg_array(sb, n_group + 1); in ext4_resize_fs()
2142 err = ext4_mb_alloc_groupinfo(sb, n_group + 1); in ext4_resize_fs()
2155 while (ext4_setup_next_flex_gd(sb, flex_gd, n_blocks_count)) { in ext4_resize_fs()
2158 ext4_msg(sb, KERN_INFO, in ext4_resize_fs()
2163 if (ext4_alloc_group_tables(sb, flex_gd, flexbg_size) != 0) in ext4_resize_fs()
2165 err = ext4_flex_group_add(sb, resize_inode, flex_gd); in ext4_resize_fs()
2188 ext4_warning(sb, "error (%d) occurred during " in ext4_resize_fs()
2190 ext4_msg(sb, KERN_INFO, "resized filesystem to %llu", in ext4_resize_fs()