Lines Matching full:sb
79 static int ext4_validate_inode_bitmap(struct super_block *sb, in ext4_validate_inode_bitmap() argument
87 if (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY) in ext4_validate_inode_bitmap()
90 grp = ext4_get_group_info(sb, block_group); in ext4_validate_inode_bitmap()
97 ext4_lock_group(sb, block_group); in ext4_validate_inode_bitmap()
100 blk = ext4_inode_bitmap(sb, desc); in ext4_validate_inode_bitmap()
101 if (!ext4_inode_bitmap_csum_verify(sb, block_group, desc, bh, in ext4_validate_inode_bitmap()
102 EXT4_INODES_PER_GROUP(sb) / 8) || in ext4_validate_inode_bitmap()
103 ext4_simulate_fail(sb, EXT4_SIM_IBITMAP_CRC)) { in ext4_validate_inode_bitmap()
104 ext4_unlock_group(sb, block_group); in ext4_validate_inode_bitmap()
105 ext4_error(sb, "Corrupt inode bitmap - block_group = %u, " in ext4_validate_inode_bitmap()
107 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_validate_inode_bitmap()
113 ext4_unlock_group(sb, block_group); in ext4_validate_inode_bitmap()
124 ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group) in ext4_read_inode_bitmap() argument
127 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_read_inode_bitmap()
132 desc = ext4_get_group_desc(sb, block_group, NULL); in ext4_read_inode_bitmap()
136 bitmap_blk = ext4_inode_bitmap(sb, desc); in ext4_read_inode_bitmap()
139 ext4_error(sb, "Invalid inode bitmap blk %llu in " in ext4_read_inode_bitmap()
141 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_read_inode_bitmap()
145 bh = sb_getblk(sb, bitmap_blk); in ext4_read_inode_bitmap()
147 ext4_warning(sb, "Cannot read inode bitmap - " in ext4_read_inode_bitmap()
161 ext4_lock_group(sb, block_group); in ext4_read_inode_bitmap()
162 if (ext4_has_group_desc_csum(sb) && in ext4_read_inode_bitmap()
165 ext4_unlock_group(sb, block_group); in ext4_read_inode_bitmap()
167 ext4_error(sb, "Inode bitmap for bg 0 marked " in ext4_read_inode_bitmap()
172 memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8); in ext4_read_inode_bitmap()
173 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), in ext4_read_inode_bitmap()
174 sb->s_blocksize * 8, bh->b_data); in ext4_read_inode_bitmap()
178 ext4_unlock_group(sb, block_group); in ext4_read_inode_bitmap()
182 ext4_unlock_group(sb, block_group); in ext4_read_inode_bitmap()
196 trace_ext4_load_inode_bitmap(sb, block_group); in ext4_read_inode_bitmap()
198 ext4_simulate_fail_bh(sb, bh, EXT4_SIM_IBITMAP_EIO); in ext4_read_inode_bitmap()
201 ext4_error_err(sb, EIO, "Cannot read inode bitmap - " in ext4_read_inode_bitmap()
204 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_read_inode_bitmap()
210 err = ext4_validate_inode_bitmap(sb, desc, block_group, bh); in ext4_read_inode_bitmap()
237 struct super_block *sb = inode->i_sb; in ext4_free_inode() local
250 if (!sb) { in ext4_free_inode()
256 ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: count=%d", in ext4_free_inode()
262 ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: nlink=%d\n", in ext4_free_inode()
266 sbi = EXT4_SB(sb); in ext4_free_inode()
281 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { in ext4_free_inode()
282 ext4_error(sb, "reserved or nonexistent inode %lu", ino); in ext4_free_inode()
285 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); in ext4_free_inode()
286 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); in ext4_free_inode()
287 bitmap_bh = ext4_read_inode_bitmap(sb, block_group); in ext4_free_inode()
295 grp = ext4_get_group_info(sb, block_group); in ext4_free_inode()
308 gdp = ext4_get_group_desc(sb, block_group, &bh2); in ext4_free_inode()
313 ext4_lock_group(sb, block_group); in ext4_free_inode()
316 ext4_unlock_group(sb, block_group); in ext4_free_inode()
320 count = ext4_free_inodes_count(sb, gdp) + 1; in ext4_free_inode()
321 ext4_free_inodes_set(sb, gdp, count); in ext4_free_inode()
323 count = ext4_used_dirs_count(sb, gdp) - 1; in ext4_free_inode()
324 ext4_used_dirs_set(sb, gdp, count); in ext4_free_inode()
328 ext4_inode_bitmap_csum_set(sb, block_group, gdp, bitmap_bh, in ext4_free_inode()
329 EXT4_INODES_PER_GROUP(sb) / 8); in ext4_free_inode()
330 ext4_group_desc_csum_set(sb, block_group, gdp); in ext4_free_inode()
331 ext4_unlock_group(sb, block_group); in ext4_free_inode()
353 ext4_error(sb, "bit already cleared for inode %lu", ino); in ext4_free_inode()
354 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_free_inode()
360 ext4_std_error(sb, fatal); in ext4_free_inode()
374 static void get_orlov_stats(struct super_block *sb, ext4_group_t g, in get_orlov_stats() argument
380 struct flex_groups *fg = sbi_array_rcu_deref(EXT4_SB(sb), in get_orlov_stats()
388 desc = ext4_get_group_desc(sb, g, NULL); in get_orlov_stats()
390 stats->free_inodes = ext4_free_inodes_count(sb, desc); in get_orlov_stats()
391 stats->free_clusters = ext4_free_group_clusters(sb, desc); in get_orlov_stats()
392 stats->used_dirs = ext4_used_dirs_count(sb, desc); in get_orlov_stats()
421 static int find_group_orlov(struct super_block *sb, struct inode *parent, in find_group_orlov() argument
426 struct ext4_sb_info *sbi = EXT4_SB(sb); in find_group_orlov()
427 ext4_group_t real_ngroups = ext4_get_groups_count(sb); in find_group_orlov()
428 int inodes_per_group = EXT4_INODES_PER_GROUP(sb); in find_group_orlov()
455 ((parent == d_inode(sb->s_root)) || in find_group_orlov()
470 get_orlov_stats(sb, g, flex_size, &stats); in find_group_orlov()
502 desc = ext4_get_group_desc(sb, grp+i, NULL); in find_group_orlov()
503 if (desc && ext4_free_inodes_count(sb, desc)) { in find_group_orlov()
515 min_clusters = avefreec - EXT4_CLUSTERS_PER_GROUP(sb)*flex_size / 4; in find_group_orlov()
529 get_orlov_stats(sb, grp, flex_size, &stats); in find_group_orlov()
546 desc = ext4_get_group_desc(sb, grp, NULL); in find_group_orlov()
548 grp_free = ext4_free_inodes_count(sb, desc); in find_group_orlov()
568 static int find_group_other(struct super_block *sb, struct inode *parent, in find_group_other() argument
572 ext4_group_t i, last, ngroups = ext4_get_groups_count(sb); in find_group_other()
574 int flex_size = ext4_flex_bg_size(EXT4_SB(sb)); in find_group_other()
592 desc = ext4_get_group_desc(sb, i, NULL); in find_group_other()
593 if (desc && ext4_free_inodes_count(sb, desc)) { in find_group_other()
611 return find_group_orlov(sb, parent, group, mode, NULL); in find_group_other()
618 desc = ext4_get_group_desc(sb, *group, NULL); in find_group_other()
619 if (desc && ext4_free_inodes_count(sb, desc) && in find_group_other()
620 ext4_free_group_clusters(sb, desc)) in find_group_other()
642 desc = ext4_get_group_desc(sb, *group, NULL); in find_group_other()
643 if (desc && ext4_free_inodes_count(sb, desc) && in find_group_other()
644 ext4_free_group_clusters(sb, desc)) in find_group_other()
656 desc = ext4_get_group_desc(sb, *group, NULL); in find_group_other()
657 if (desc && ext4_free_inodes_count(sb, desc)) in find_group_other()
673 static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino) in recently_deleted() argument
678 int inodes_per_block = EXT4_SB(sb)->s_inodes_per_block; in recently_deleted()
683 gdp = ext4_get_group_desc(sb, group, NULL); in recently_deleted()
687 bh = sb_find_get_block(sb, ext4_inode_table(sb, gdp) + in recently_deleted()
696 offset = (ino % inodes_per_block) * EXT4_INODE_SIZE(sb); in recently_deleted()
716 static int find_inode_bit(struct super_block *sb, ext4_group_t group, in find_inode_bit() argument
719 bool check_recently_deleted = EXT4_SB(sb)->s_journal == NULL; in find_inode_bit()
720 unsigned long recently_deleted_ino = EXT4_INODES_PER_GROUP(sb); in find_inode_bit()
725 EXT4_INODES_PER_GROUP(sb), *ino); in find_inode_bit()
726 if (*ino >= EXT4_INODES_PER_GROUP(sb)) in find_inode_bit()
729 if (check_recently_deleted && recently_deleted(sb, group, *ino)) { in find_inode_bit()
732 if (*ino < EXT4_INODES_PER_GROUP(sb)) in find_inode_bit()
738 if (recently_deleted_ino >= EXT4_INODES_PER_GROUP(sb)) in find_inode_bit()
750 int ext4_mark_inode_used(struct super_block *sb, int ino) in ext4_mark_inode_used() argument
752 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); in ext4_mark_inode_used()
759 if (ino < EXT4_FIRST_INO(sb) || ino > max_ino) in ext4_mark_inode_used()
762 group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); in ext4_mark_inode_used()
763 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); in ext4_mark_inode_used()
764 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); in ext4_mark_inode_used()
773 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); in ext4_mark_inode_used()
784 ext4_std_error(sb, err); in ext4_mark_inode_used()
789 ext4_std_error(sb, err); in ext4_mark_inode_used()
794 if (ext4_has_group_desc_csum(sb) && in ext4_mark_inode_used()
798 block_bitmap_bh = ext4_read_block_bitmap(sb, group); in ext4_mark_inode_used()
809 ext4_lock_group(sb, group); in ext4_mark_inode_used()
810 if (ext4_has_group_desc_csum(sb) && in ext4_mark_inode_used()
813 ext4_free_group_clusters_set(sb, gdp, in ext4_mark_inode_used()
814 ext4_free_clusters_after_init(sb, group, gdp)); in ext4_mark_inode_used()
815 ext4_block_bitmap_csum_set(sb, group, gdp, in ext4_mark_inode_used()
817 ext4_group_desc_csum_set(sb, group, gdp); in ext4_mark_inode_used()
819 ext4_unlock_group(sb, group); in ext4_mark_inode_used()
823 ext4_std_error(sb, err); in ext4_mark_inode_used()
829 if (ext4_has_group_desc_csum(sb)) { in ext4_mark_inode_used()
832 ext4_lock_group(sb, group); /* while we modify the bg desc */ in ext4_mark_inode_used()
833 free = EXT4_INODES_PER_GROUP(sb) - in ext4_mark_inode_used()
834 ext4_itable_unused_count(sb, gdp); in ext4_mark_inode_used()
846 ext4_itable_unused_set(sb, gdp, in ext4_mark_inode_used()
847 (EXT4_INODES_PER_GROUP(sb) - bit - 1)); in ext4_mark_inode_used()
849 ext4_lock_group(sb, group); in ext4_mark_inode_used()
852 ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1); in ext4_mark_inode_used()
853 if (ext4_has_group_desc_csum(sb)) { in ext4_mark_inode_used()
854 ext4_inode_bitmap_csum_set(sb, group, gdp, inode_bitmap_bh, in ext4_mark_inode_used()
855 EXT4_INODES_PER_GROUP(sb) / 8); in ext4_mark_inode_used()
856 ext4_group_desc_csum_set(sb, group, gdp); in ext4_mark_inode_used()
859 ext4_unlock_group(sb, group); in ext4_mark_inode_used()
869 struct super_block *sb = dir->i_sb; in ext4_xattr_credits_for_new_inode() local
880 __ext4_xattr_set_credits(sb, NULL /* inode */, in ext4_xattr_credits_for_new_inode()
899 __ext4_xattr_set_credits(sb, NULL /* inode */, in ext4_xattr_credits_for_new_inode()
905 nblocks += __ext4_xattr_set_credits(sb, in ext4_xattr_credits_for_new_inode()
929 struct super_block *sb; in __ext4_new_inode() local
949 sb = dir->i_sb; in __ext4_new_inode()
950 sbi = EXT4_SB(sb); in __ext4_new_inode()
955 ngroups = ext4_get_groups_count(sb); in __ext4_new_inode()
957 inode = new_inode(sb); in __ext4_new_inode()
971 } else if (test_opt(sb, GRPID)) { in __ext4_new_inode()
978 if (ext4_has_feature_project(sb) && in __ext4_new_inode()
1007 group = (goal - 1) / EXT4_INODES_PER_GROUP(sb); in __ext4_new_inode()
1008 ino = (goal - 1) % EXT4_INODES_PER_GROUP(sb); in __ext4_new_inode()
1014 ret2 = find_group_orlov(sb, dir, &group, mode, qstr); in __ext4_new_inode()
1016 ret2 = find_group_other(sb, dir, &group, mode); in __ext4_new_inode()
1032 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); in __ext4_new_inode()
1039 if (ext4_free_inodes_count(sb, gdp) == 0) in __ext4_new_inode()
1043 grp = ext4_get_group_info(sb, group); in __ext4_new_inode()
1053 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); in __ext4_new_inode()
1063 ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); in __ext4_new_inode()
1067 if (group == 0 && (ino + 1) < EXT4_FIRST_INO(sb)) { in __ext4_new_inode()
1068 ext4_error(sb, "reserved inode found cleared - " in __ext4_new_inode()
1070 ext4_mark_group_bitmap_corrupted(sb, group, in __ext4_new_inode()
1079 ext4_trans_default_revoke_credits(sb)); in __ext4_new_inode()
1082 ext4_std_error(sb, err); in __ext4_new_inode()
1089 ext4_std_error(sb, err); in __ext4_new_inode()
1092 ext4_lock_group(sb, group); in __ext4_new_inode()
1098 ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); in __ext4_new_inode()
1106 ext4_unlock_group(sb, group); in __ext4_new_inode()
1111 if (ino < EXT4_INODES_PER_GROUP(sb)) in __ext4_new_inode()
1124 ext4_std_error(sb, err); in __ext4_new_inode()
1131 ext4_std_error(sb, err); in __ext4_new_inode()
1136 if (ext4_has_group_desc_csum(sb) && in __ext4_new_inode()
1140 block_bitmap_bh = ext4_read_block_bitmap(sb, group); in __ext4_new_inode()
1149 ext4_std_error(sb, err); in __ext4_new_inode()
1157 ext4_lock_group(sb, group); in __ext4_new_inode()
1158 if (ext4_has_group_desc_csum(sb) && in __ext4_new_inode()
1161 ext4_free_group_clusters_set(sb, gdp, in __ext4_new_inode()
1162 ext4_free_clusters_after_init(sb, group, gdp)); in __ext4_new_inode()
1163 ext4_block_bitmap_csum_set(sb, group, gdp, in __ext4_new_inode()
1165 ext4_group_desc_csum_set(sb, group, gdp); in __ext4_new_inode()
1167 ext4_unlock_group(sb, group); in __ext4_new_inode()
1171 ext4_std_error(sb, err); in __ext4_new_inode()
1177 if (ext4_has_group_desc_csum(sb)) { in __ext4_new_inode()
1182 grp = ext4_get_group_info(sb, group); in __ext4_new_inode()
1192 ext4_lock_group(sb, group); /* while we modify the bg desc */ in __ext4_new_inode()
1193 free = EXT4_INODES_PER_GROUP(sb) - in __ext4_new_inode()
1194 ext4_itable_unused_count(sb, gdp); in __ext4_new_inode()
1205 ext4_itable_unused_set(sb, gdp, in __ext4_new_inode()
1206 (EXT4_INODES_PER_GROUP(sb) - ino)); in __ext4_new_inode()
1210 ext4_lock_group(sb, group); in __ext4_new_inode()
1213 ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1); in __ext4_new_inode()
1215 ext4_used_dirs_set(sb, gdp, ext4_used_dirs_count(sb, gdp) + 1); in __ext4_new_inode()
1223 if (ext4_has_group_desc_csum(sb)) { in __ext4_new_inode()
1224 ext4_inode_bitmap_csum_set(sb, group, gdp, inode_bitmap_bh, in __ext4_new_inode()
1225 EXT4_INODES_PER_GROUP(sb) / 8); in __ext4_new_inode()
1226 ext4_group_desc_csum_set(sb, group, gdp); in __ext4_new_inode()
1228 ext4_unlock_group(sb, group); in __ext4_new_inode()
1233 ext4_std_error(sb, err); in __ext4_new_inode()
1247 inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb); in __ext4_new_inode()
1275 ext4_error(sb, "failed to insert inode %lu: doubly allocated?", in __ext4_new_inode()
1277 ext4_mark_group_bitmap_corrupted(sb, group, in __ext4_new_inode()
1284 if (ext4_has_metadata_csum(sb)) { in __ext4_new_inode()
1299 if (ext4_has_feature_inline_data(sb) && in __ext4_new_inode()
1328 if (ext4_has_feature_extents(sb)) { in __ext4_new_inode()
1343 ext4_std_error(sb, err); in __ext4_new_inode()
1366 struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) in ext4_orphan_get() argument
1368 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); in ext4_orphan_get()
1375 if (ino < EXT4_FIRST_INO(sb) || ino > max_ino) in ext4_orphan_get()
1378 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); in ext4_orphan_get()
1379 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); in ext4_orphan_get()
1380 bitmap_bh = ext4_read_inode_bitmap(sb, block_group); in ext4_orphan_get()
1391 inode = ext4_iget(sb, ino, EXT4_IGET_NORMAL); in ext4_orphan_get()
1394 ext4_error_err(sb, -err, in ext4_orphan_get()
1417 ext4_error(sb, "bad orphan inode %lu", ino); in ext4_orphan_get()
1438 unsigned long ext4_count_free_inodes(struct super_block *sb) in ext4_count_free_inodes() argument
1442 ext4_group_t i, ngroups = ext4_get_groups_count(sb); in ext4_count_free_inodes()
1448 es = EXT4_SB(sb)->s_es; in ext4_count_free_inodes()
1453 gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_free_inodes()
1456 desc_count += ext4_free_inodes_count(sb, gdp); in ext4_count_free_inodes()
1458 bitmap_bh = ext4_read_inode_bitmap(sb, i); in ext4_count_free_inodes()
1465 EXT4_INODES_PER_GROUP(sb) / 8); in ext4_count_free_inodes()
1467 (unsigned long) i, ext4_free_inodes_count(sb, gdp), x); in ext4_count_free_inodes()
1478 gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_free_inodes()
1481 desc_count += ext4_free_inodes_count(sb, gdp); in ext4_count_free_inodes()
1489 unsigned long ext4_count_dirs(struct super_block * sb) in ext4_count_dirs() argument
1492 ext4_group_t i, ngroups = ext4_get_groups_count(sb); in ext4_count_dirs()
1495 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_dirs()
1498 count += ext4_used_dirs_count(sb, gdp); in ext4_count_dirs()
1511 int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, in ext4_init_inode_table() argument
1514 struct ext4_group_info *grp = ext4_get_group_info(sb, group); in ext4_init_inode_table()
1515 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_init_inode_table()
1524 if (sb_rdonly(sb)) { in ext4_init_inode_table()
1529 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); in ext4_init_inode_table()
1540 handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); in ext4_init_inode_table()
1553 used_inos = EXT4_INODES_PER_GROUP(sb) - in ext4_init_inode_table()
1554 ext4_itable_unused_count(sb, gdp); in ext4_init_inode_table()
1559 ext4_error(sb, "Something is wrong with group %u: " in ext4_init_inode_table()
1563 ext4_itable_unused_count(sb, gdp)); in ext4_init_inode_table()
1568 used_inos += group * EXT4_INODES_PER_GROUP(sb); in ext4_init_inode_table()
1574 (used_inos < EXT4_FIRST_INO(sb))) { in ext4_init_inode_table()
1575 ext4_error(sb, "Something is wrong with group %u: " in ext4_init_inode_table()
1578 group, ext4_itable_unused_count(sb, gdp), in ext4_init_inode_table()
1585 blk = ext4_inode_table(sb, gdp) + used_blks; in ext4_init_inode_table()
1604 ret = sb_issue_zeroout(sb, blk, num, GFP_NOFS); in ext4_init_inode_table()
1608 blkdev_issue_flush(sb->s_bdev, GFP_NOFS); in ext4_init_inode_table()
1611 ext4_lock_group(sb, group); in ext4_init_inode_table()
1613 ext4_group_desc_csum_set(sb, group, gdp); in ext4_init_inode_table()
1614 ext4_unlock_group(sb, group); in ext4_init_inode_table()