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()
93 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, desc, bh) || in ext4_validate_inode_bitmap()
102 ext4_simulate_fail(sb, EXT4_SIM_IBITMAP_CRC)) { in ext4_validate_inode_bitmap()
103 ext4_unlock_group(sb, block_group); in ext4_validate_inode_bitmap()
104 ext4_error(sb, "Corrupt inode bitmap - block_group = %u, " in ext4_validate_inode_bitmap()
106 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_validate_inode_bitmap()
112 ext4_unlock_group(sb, block_group); in ext4_validate_inode_bitmap()
123 ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group) in ext4_read_inode_bitmap() argument
126 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_read_inode_bitmap()
131 desc = ext4_get_group_desc(sb, block_group, NULL); in ext4_read_inode_bitmap()
135 bitmap_blk = ext4_inode_bitmap(sb, desc); in ext4_read_inode_bitmap()
138 ext4_error(sb, "Invalid inode bitmap blk %llu in " in ext4_read_inode_bitmap()
140 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_read_inode_bitmap()
144 bh = sb_getblk(sb, bitmap_blk); in ext4_read_inode_bitmap()
146 ext4_warning(sb, "Cannot read inode bitmap - " in ext4_read_inode_bitmap()
160 ext4_lock_group(sb, block_group); in ext4_read_inode_bitmap()
161 if (ext4_has_group_desc_csum(sb) && in ext4_read_inode_bitmap()
164 ext4_unlock_group(sb, block_group); in ext4_read_inode_bitmap()
166 ext4_error(sb, "Inode bitmap for bg 0 marked " in ext4_read_inode_bitmap()
171 memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8); in ext4_read_inode_bitmap()
172 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), in ext4_read_inode_bitmap()
173 sb->s_blocksize * 8, bh->b_data); in ext4_read_inode_bitmap()
177 ext4_unlock_group(sb, block_group); in ext4_read_inode_bitmap()
181 ext4_unlock_group(sb, block_group); in ext4_read_inode_bitmap()
195 trace_ext4_load_inode_bitmap(sb, block_group); in ext4_read_inode_bitmap()
197 ext4_simulate_fail_bh(sb, bh, EXT4_SIM_IBITMAP_EIO); in ext4_read_inode_bitmap()
200 ext4_error_err(sb, EIO, "Cannot read inode bitmap - " in ext4_read_inode_bitmap()
203 ext4_mark_group_bitmap_corrupted(sb, block_group, in ext4_read_inode_bitmap()
209 err = ext4_validate_inode_bitmap(sb, desc, block_group, bh); in ext4_read_inode_bitmap()
236 struct super_block *sb = inode->i_sb; in ext4_free_inode() local
249 if (!sb) { in ext4_free_inode()
255 ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: count=%d", in ext4_free_inode()
261 ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: nlink=%d\n", in ext4_free_inode()
265 sbi = EXT4_SB(sb); in ext4_free_inode()
280 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { in ext4_free_inode()
281 ext4_error(sb, "reserved or nonexistent inode %lu", ino); in ext4_free_inode()
284 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); in ext4_free_inode()
285 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); in ext4_free_inode()
286 bitmap_bh = ext4_read_inode_bitmap(sb, block_group); in ext4_free_inode()
294 grp = ext4_get_group_info(sb, block_group); in ext4_free_inode()
302 fatal = ext4_journal_get_write_access(handle, sb, bitmap_bh, in ext4_free_inode()
308 gdp = ext4_get_group_desc(sb, block_group, &bh2); in ext4_free_inode()
311 fatal = ext4_journal_get_write_access(handle, sb, bh2, in ext4_free_inode()
314 ext4_lock_group(sb, block_group); in ext4_free_inode()
317 ext4_unlock_group(sb, block_group); in ext4_free_inode()
321 count = ext4_free_inodes_count(sb, gdp) + 1; in ext4_free_inode()
322 ext4_free_inodes_set(sb, gdp, count); in ext4_free_inode()
324 count = ext4_used_dirs_count(sb, gdp) - 1; in ext4_free_inode()
325 ext4_used_dirs_set(sb, gdp, count); in ext4_free_inode()
329 ext4_inode_bitmap_csum_set(sb, gdp, bitmap_bh); 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()
469 get_orlov_stats(sb, g, flex_size, &stats); in find_group_orlov()
501 desc = ext4_get_group_desc(sb, grp+i, NULL); in find_group_orlov()
502 if (desc && ext4_free_inodes_count(sb, desc)) { in find_group_orlov()
514 min_clusters = avefreec - EXT4_CLUSTERS_PER_GROUP(sb)*flex_size / 4; in find_group_orlov()
530 get_orlov_stats(sb, grp, flex_size, &stats); in find_group_orlov()
547 desc = ext4_get_group_desc(sb, grp, NULL); in find_group_orlov()
549 grp_free = ext4_free_inodes_count(sb, desc); in find_group_orlov()
569 static int find_group_other(struct super_block *sb, struct inode *parent, in find_group_other() argument
573 ext4_group_t i, last, ngroups = ext4_get_groups_count(sb); in find_group_other()
575 int flex_size = ext4_flex_bg_size(EXT4_SB(sb)); in find_group_other()
593 desc = ext4_get_group_desc(sb, i, NULL); in find_group_other()
594 if (desc && ext4_free_inodes_count(sb, desc)) { in find_group_other()
612 return find_group_orlov(sb, parent, group, mode, NULL); in find_group_other()
619 desc = ext4_get_group_desc(sb, *group, NULL); in find_group_other()
620 if (desc && ext4_free_inodes_count(sb, desc) && in find_group_other()
621 ext4_free_group_clusters(sb, desc)) in find_group_other()
643 desc = ext4_get_group_desc(sb, *group, NULL); in find_group_other()
644 if (desc && ext4_free_inodes_count(sb, desc) && in find_group_other()
645 ext4_free_group_clusters(sb, desc)) in find_group_other()
657 desc = ext4_get_group_desc(sb, *group, NULL); in find_group_other()
658 if (desc && ext4_free_inodes_count(sb, desc)) in find_group_other()
674 static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino) in recently_deleted() argument
679 int inodes_per_block = EXT4_SB(sb)->s_inodes_per_block; in recently_deleted()
684 gdp = ext4_get_group_desc(sb, group, NULL); in recently_deleted()
688 bh = sb_find_get_block(sb, ext4_inode_table(sb, gdp) + in recently_deleted()
697 offset = (ino % inodes_per_block) * EXT4_INODE_SIZE(sb); in recently_deleted()
717 static int find_inode_bit(struct super_block *sb, ext4_group_t group, in find_inode_bit() argument
720 bool check_recently_deleted = EXT4_SB(sb)->s_journal == NULL; in find_inode_bit()
721 unsigned long recently_deleted_ino = EXT4_INODES_PER_GROUP(sb); in find_inode_bit()
726 EXT4_INODES_PER_GROUP(sb), *ino); in find_inode_bit()
727 if (*ino >= EXT4_INODES_PER_GROUP(sb)) in find_inode_bit()
730 if (check_recently_deleted && recently_deleted(sb, group, *ino)) { in find_inode_bit()
733 if (*ino < EXT4_INODES_PER_GROUP(sb)) in find_inode_bit()
739 if (recently_deleted_ino >= EXT4_INODES_PER_GROUP(sb)) in find_inode_bit()
751 int ext4_mark_inode_used(struct super_block *sb, int ino) in ext4_mark_inode_used() argument
753 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); in ext4_mark_inode_used()
760 if (ino < EXT4_FIRST_INO(sb) || ino > max_ino) in ext4_mark_inode_used()
763 group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); in ext4_mark_inode_used()
764 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); in ext4_mark_inode_used()
765 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); in ext4_mark_inode_used()
774 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); in ext4_mark_inode_used()
785 ext4_std_error(sb, err); in ext4_mark_inode_used()
790 ext4_std_error(sb, err); in ext4_mark_inode_used()
795 if (ext4_has_group_desc_csum(sb) && in ext4_mark_inode_used()
799 block_bitmap_bh = ext4_read_block_bitmap(sb, group); in ext4_mark_inode_used()
810 ext4_lock_group(sb, group); in ext4_mark_inode_used()
811 if (ext4_has_group_desc_csum(sb) && in ext4_mark_inode_used()
814 ext4_free_group_clusters_set(sb, gdp, in ext4_mark_inode_used()
815 ext4_free_clusters_after_init(sb, group, gdp)); in ext4_mark_inode_used()
816 ext4_block_bitmap_csum_set(sb, gdp, block_bitmap_bh); 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, gdp, inode_bitmap_bh); in ext4_mark_inode_used()
855 ext4_group_desc_csum_set(sb, group, gdp); in ext4_mark_inode_used()
858 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()
930 struct super_block *sb; in __ext4_new_inode() local
950 sb = dir->i_sb; in __ext4_new_inode()
951 sbi = EXT4_SB(sb); in __ext4_new_inode()
953 if (unlikely(ext4_forced_shutdown(sb))) in __ext4_new_inode()
956 ngroups = ext4_get_groups_count(sb); in __ext4_new_inode()
958 inode = new_inode(sb); in __ext4_new_inode()
972 } else if (test_opt(sb, GRPID)) { in __ext4_new_inode()
979 if (ext4_has_feature_project(sb) && in __ext4_new_inode()
1008 group = (goal - 1) / EXT4_INODES_PER_GROUP(sb); in __ext4_new_inode()
1009 ino = (goal - 1) % EXT4_INODES_PER_GROUP(sb); in __ext4_new_inode()
1015 ret2 = find_group_orlov(sb, dir, &group, mode, qstr); in __ext4_new_inode()
1017 ret2 = find_group_other(sb, dir, &group, mode); in __ext4_new_inode()
1033 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); in __ext4_new_inode()
1040 if (ext4_free_inodes_count(sb, gdp) == 0) in __ext4_new_inode()
1044 grp = ext4_get_group_info(sb, group); in __ext4_new_inode()
1054 inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); in __ext4_new_inode()
1064 ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); in __ext4_new_inode()
1068 if (group == 0 && (ino + 1) < EXT4_FIRST_INO(sb)) { in __ext4_new_inode()
1069 ext4_error(sb, "reserved inode found cleared - " in __ext4_new_inode()
1071 ext4_mark_group_bitmap_corrupted(sb, group, in __ext4_new_inode()
1080 ext4_trans_default_revoke_credits(sb)); in __ext4_new_inode()
1083 ext4_std_error(sb, err); in __ext4_new_inode()
1088 err = ext4_journal_get_write_access(handle, sb, inode_bitmap_bh, in __ext4_new_inode()
1091 ext4_std_error(sb, err); in __ext4_new_inode()
1094 ext4_lock_group(sb, group); in __ext4_new_inode()
1100 ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); in __ext4_new_inode()
1108 ext4_unlock_group(sb, group); in __ext4_new_inode()
1124 ext4_std_error(sb, err); in __ext4_new_inode()
1129 err = ext4_journal_get_write_access(handle, sb, group_desc_bh, in __ext4_new_inode()
1132 ext4_std_error(sb, err); in __ext4_new_inode()
1137 if (ext4_has_group_desc_csum(sb) && in __ext4_new_inode()
1141 block_bitmap_bh = ext4_read_block_bitmap(sb, group); in __ext4_new_inode()
1147 err = ext4_journal_get_write_access(handle, sb, block_bitmap_bh, in __ext4_new_inode()
1151 ext4_std_error(sb, err); in __ext4_new_inode()
1159 ext4_lock_group(sb, group); in __ext4_new_inode()
1160 if (ext4_has_group_desc_csum(sb) && in __ext4_new_inode()
1163 ext4_free_group_clusters_set(sb, gdp, in __ext4_new_inode()
1164 ext4_free_clusters_after_init(sb, group, gdp)); in __ext4_new_inode()
1165 ext4_block_bitmap_csum_set(sb, gdp, block_bitmap_bh); in __ext4_new_inode()
1166 ext4_group_desc_csum_set(sb, group, gdp); in __ext4_new_inode()
1168 ext4_unlock_group(sb, group); in __ext4_new_inode()
1172 ext4_std_error(sb, err); in __ext4_new_inode()
1178 if (ext4_has_group_desc_csum(sb)) { in __ext4_new_inode()
1183 grp = ext4_get_group_info(sb, group); in __ext4_new_inode()
1193 ext4_lock_group(sb, group); /* while we modify the bg desc */ in __ext4_new_inode()
1194 free = EXT4_INODES_PER_GROUP(sb) - in __ext4_new_inode()
1195 ext4_itable_unused_count(sb, gdp); in __ext4_new_inode()
1206 ext4_itable_unused_set(sb, gdp, in __ext4_new_inode()
1207 (EXT4_INODES_PER_GROUP(sb) - ino)); in __ext4_new_inode()
1211 ext4_lock_group(sb, group); in __ext4_new_inode()
1214 ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1); in __ext4_new_inode()
1216 ext4_used_dirs_set(sb, gdp, ext4_used_dirs_count(sb, gdp) + 1); in __ext4_new_inode()
1224 if (ext4_has_group_desc_csum(sb)) { in __ext4_new_inode()
1225 ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh); 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()
1340 ext4_std_error(sb, err); in __ext4_new_inode()
1363 struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) in ext4_orphan_get() argument
1365 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count); in ext4_orphan_get()
1372 if (ino < EXT4_FIRST_INO(sb) || ino > max_ino) in ext4_orphan_get()
1375 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); in ext4_orphan_get()
1376 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); in ext4_orphan_get()
1377 bitmap_bh = ext4_read_inode_bitmap(sb, block_group); in ext4_orphan_get()
1388 inode = ext4_iget(sb, ino, EXT4_IGET_NORMAL); in ext4_orphan_get()
1391 ext4_error_err(sb, -err, in ext4_orphan_get()
1414 ext4_error(sb, "bad orphan inode %lu", ino); in ext4_orphan_get()
1435 unsigned long ext4_count_free_inodes(struct super_block *sb) in ext4_count_free_inodes() argument
1439 ext4_group_t i, ngroups = ext4_get_groups_count(sb); in ext4_count_free_inodes()
1445 es = EXT4_SB(sb)->s_es; in ext4_count_free_inodes()
1450 gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_free_inodes()
1453 desc_count += ext4_free_inodes_count(sb, gdp); in ext4_count_free_inodes()
1455 bitmap_bh = ext4_read_inode_bitmap(sb, i); in ext4_count_free_inodes()
1462 EXT4_INODES_PER_GROUP(sb) / 8); in ext4_count_free_inodes()
1464 (unsigned long) i, ext4_free_inodes_count(sb, gdp), x); in ext4_count_free_inodes()
1475 gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_free_inodes()
1478 desc_count += ext4_free_inodes_count(sb, gdp); in ext4_count_free_inodes()
1486 unsigned long ext4_count_dirs(struct super_block * sb) in ext4_count_dirs() argument
1489 ext4_group_t i, ngroups = ext4_get_groups_count(sb); in ext4_count_dirs()
1492 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); in ext4_count_dirs()
1495 count += ext4_used_dirs_count(sb, gdp); in ext4_count_dirs()
1508 int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, in ext4_init_inode_table() argument
1511 struct ext4_group_info *grp = ext4_get_group_info(sb, group); in ext4_init_inode_table()
1512 struct ext4_sb_info *sbi = EXT4_SB(sb); in ext4_init_inode_table()
1520 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); in ext4_init_inode_table()
1531 handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); in ext4_init_inode_table()
1544 used_inos = EXT4_INODES_PER_GROUP(sb) - in ext4_init_inode_table()
1545 ext4_itable_unused_count(sb, gdp); in ext4_init_inode_table()
1550 ext4_error(sb, "Something is wrong with group %u: " in ext4_init_inode_table()
1554 ext4_itable_unused_count(sb, gdp)); in ext4_init_inode_table()
1559 used_inos += group * EXT4_INODES_PER_GROUP(sb); in ext4_init_inode_table()
1565 (used_inos < EXT4_FIRST_INO(sb))) { in ext4_init_inode_table()
1566 ext4_error(sb, "Something is wrong with group %u: " in ext4_init_inode_table()
1569 group, ext4_itable_unused_count(sb, gdp), in ext4_init_inode_table()
1576 blk = ext4_inode_table(sb, gdp) + used_blks; in ext4_init_inode_table()
1580 ret = ext4_journal_get_write_access(handle, sb, group_desc_bh, in ext4_init_inode_table()
1595 ret = sb_issue_zeroout(sb, blk, num, GFP_NOFS); in ext4_init_inode_table()
1599 blkdev_issue_flush(sb->s_bdev); in ext4_init_inode_table()
1602 ext4_lock_group(sb, group); in ext4_init_inode_table()
1604 ext4_group_desc_csum_set(sb, group, gdp); in ext4_init_inode_table()
1605 ext4_unlock_group(sb, group); in ext4_init_inode_table()