Lines Matching full:trans

73 static s64 bch2_count_inode_sectors(struct btree_trans *trans, u64 inum,  in bch2_count_inode_sectors()  argument
78 int ret = for_each_btree_key_max(trans, iter, BTREE_ID_extents, in bch2_count_inode_sectors()
90 static s64 bch2_count_subdirs(struct btree_trans *trans, u64 inum, in bch2_count_subdirs() argument
95 int ret = for_each_btree_key_max(trans, iter, BTREE_ID_dirents, in bch2_count_subdirs()
108 static int subvol_lookup(struct btree_trans *trans, u32 subvol, in subvol_lookup() argument
112 int ret = bch2_subvolume_get(trans, subvol, false, &s); in subvol_lookup()
119 static int lookup_first_inode(struct btree_trans *trans, u64 inode_nr, in lookup_first_inode() argument
126 for_each_btree_key_norestart(trans, iter, BTREE_ID_inodes, POS(0, inode_nr), in lookup_first_inode()
137 bch_err_msg(trans->c, ret, "fetching inode %llu", inode_nr); in lookup_first_inode()
138 bch2_trans_iter_exit(trans, &iter); in lookup_first_inode()
142 static int lookup_inode(struct btree_trans *trans, u64 inode_nr, u32 snapshot, in lookup_inode() argument
149 k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_inodes, in lookup_inode()
159 bch2_trans_iter_exit(trans, &iter); in lookup_inode()
163 static int lookup_dirent_in_snapshot(struct btree_trans *trans, in lookup_dirent_in_snapshot() argument
169 struct bkey_s_c k = bch2_hash_lookup_in_snapshot(trans, &iter, bch2_dirent_hash_desc, in lookup_dirent_in_snapshot()
178 bch2_trans_iter_exit(trans, &iter); in lookup_dirent_in_snapshot()
182 static int __remove_dirent(struct btree_trans *trans, struct bpos pos) in __remove_dirent() argument
184 struct bch_fs *c = trans->c; in __remove_dirent()
190 ret = lookup_first_inode(trans, pos.inode, &dir_inode); in __remove_dirent()
196 bch2_trans_iter_init(trans, &iter, BTREE_ID_dirents, pos, BTREE_ITER_intent); in __remove_dirent()
199 bch2_hash_delete_at(trans, bch2_dirent_hash_desc, in __remove_dirent()
202 bch2_trans_iter_exit(trans, &iter); in __remove_dirent()
212 static int find_snapshot_tree_subvol(struct btree_trans *trans, in find_snapshot_tree_subvol() argument
219 for_each_btree_key_norestart(trans, iter, BTREE_ID_snapshots, POS_MIN, 0, k, ret) { in find_snapshot_tree_subvol()
234 bch2_trans_iter_exit(trans, &iter); in find_snapshot_tree_subvol()
239 static int lookup_lostfound(struct btree_trans *trans, u32 snapshot, in lookup_lostfound() argument
243 struct bch_fs *c = trans->c; in lookup_lostfound()
251 ret = bch2_snapshot_tree_lookup(trans, in lookup_lostfound()
257 ret = find_snapshot_tree_subvol(trans, in lookup_lostfound()
265 ret = bch2_subvolume_get(trans, subvolid, false, &subvol); in lookup_lostfound()
272 struct bkey_i_subvolume *subvol = bch2_bkey_get_mut_typed(trans, &iter, in lookup_lostfound()
280 bch2_trans_iter_exit(trans, &iter); in lookup_lostfound()
290 ret = lookup_inode(trans, root_inum.inum, snapshot, &root_inode); in lookup_lostfound()
298 ret = lookup_dirent_in_snapshot(trans, root_hash_info, root_inum, in lookup_lostfound()
316 ret = lookup_inode(trans, inum, snapshot, lostfound); in lookup_lostfound()
332 ret = bch2_inum_to_path(trans, root_inum, &path); in lookup_lostfound()
350 ret = bch2_inode_create(trans, &lostfound_iter, lostfound, snapshot, cpu); in lookup_lostfound()
359 ret = bch2_dirent_create_snapshot(trans, in lookup_lostfound()
366 bch2_inode_write_flags(trans, &lostfound_iter, lostfound, in lookup_lostfound()
370 bch2_trans_iter_exit(trans, &lostfound_iter); in lookup_lostfound()
383 static int maybe_delete_dirent(struct btree_trans *trans, struct bpos d_pos, u32 snapshot) in maybe_delete_dirent() argument
386 struct bkey_s_c k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_dirents, in maybe_delete_dirent()
399 struct bkey_i *k = bch2_trans_kmalloc(trans, sizeof(*k)); in maybe_delete_dirent()
407 ret = bch2_trans_update(trans, &iter, k, BTREE_UPDATE_internal_snapshot_node); in maybe_delete_dirent()
410 bch2_trans_iter_exit(trans, &iter); in maybe_delete_dirent()
414 static int reattach_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode) in reattach_inode() argument
416 struct bch_fs *c = trans->c; in reattach_inode()
426 ret = subvol_lookup(trans, inode->bi_parent_subvol, in reattach_inode()
436 ret = lookup_lostfound(trans, dirent_snapshot, &lostfound, inode->bi_inum); in reattach_inode()
448 ret = __bch2_fsck_write_inode(trans, &lostfound); in reattach_inode()
457 ret = bch2_dirent_create_snapshot(trans, in reattach_inode()
471 ret = __bch2_fsck_write_inode(trans, inode); in reattach_inode()
487 for_each_btree_key_reverse_norestart(trans, iter, in reattach_inode()
504 ret = maybe_delete_dirent(trans, in reattach_inode()
519 ret = bch2_inode_write_flags(trans, &iter, &child_inode, in reattach_inode()
526 bch2_trans_iter_exit(trans, &iter); in reattach_inode()
532 static struct bkey_s_c_dirent dirent_get_by_pos(struct btree_trans *trans, in dirent_get_by_pos() argument
536 return bch2_bkey_get_iter_typed(trans, iter, BTREE_ID_dirents, pos, 0, dirent); in dirent_get_by_pos()
539 static int remove_backpointer(struct btree_trans *trans, in remove_backpointer() argument
545 struct bch_fs *c = trans->c; in remove_backpointer()
547 struct bkey_s_c_dirent d = dirent_get_by_pos(trans, &iter, in remove_backpointer()
551 __remove_dirent(trans, d.k->p); in remove_backpointer()
552 bch2_trans_iter_exit(trans, &iter); in remove_backpointer()
556 static int reattach_subvol(struct btree_trans *trans, struct bkey_s_c_subvolume s) in reattach_subvol() argument
558 struct bch_fs *c = trans->c; in reattach_subvol()
561 int ret = bch2_inode_find_by_inum_trans(trans, in reattach_subvol()
567 ret = remove_backpointer(trans, &inode); in reattach_subvol()
573 ret = reattach_inode(trans, &inode); in reattach_subvol()
578 static int reconstruct_subvol(struct btree_trans *trans, u32 snapshotid, u32 subvolid, u64 inum) in reconstruct_subvol() argument
580 struct bch_fs *c = trans->c; in reconstruct_subvol()
602 int ret = bch2_inode_create(trans, &inode_iter, &new_inode, snapshotid, cpu) ?: in reconstruct_subvol()
604 bch2_inode_write(trans, &inode_iter, &new_inode); in reconstruct_subvol()
605 bch2_trans_iter_exit(trans, &inode_iter); in reconstruct_subvol()
614 struct bkey_i_subvolume *new_subvol = bch2_trans_kmalloc(trans, sizeof(*new_subvol)); in reconstruct_subvol()
623 ret = bch2_btree_insert_trans(trans, BTREE_ID_subvolumes, &new_subvol->k_i, 0); in reconstruct_subvol()
628 struct bkey_i_snapshot *s = bch2_bkey_get_mut_typed(trans, &iter, in reconstruct_subvol()
640 bch2_trans_iter_exit(trans, &iter); in reconstruct_subvol()
642 struct bkey_i_snapshot_tree *st = bch2_bkey_get_mut_typed(trans, &iter, in reconstruct_subvol()
653 bch2_trans_iter_exit(trans, &iter); in reconstruct_subvol()
657 static int reconstruct_inode(struct btree_trans *trans, enum btree_id btree, u32 snapshot, u64 inum) in reconstruct_inode() argument
659 struct bch_fs *c = trans->c; in reconstruct_inode()
667 bch2_trans_iter_init(trans, &iter, BTREE_ID_extents, SPOS(inum, U64_MAX, snapshot), 0); in reconstruct_inode()
669 bch2_trans_iter_exit(trans, &iter); in reconstruct_inode()
693 return __bch2_fsck_write_inode(trans, &new_inode); in reconstruct_inode()
862 static int get_inodes_all_snapshots(struct btree_trans *trans, in get_inodes_all_snapshots() argument
865 struct bch_fs *c = trans->c; in get_inodes_all_snapshots()
879 for_each_btree_key_norestart(trans, iter, BTREE_ID_inodes, POS(0, inum), in get_inodes_all_snapshots()
887 bch2_trans_iter_exit(trans, &iter); in get_inodes_all_snapshots()
941 static struct inode_walker_entry *walk_inode(struct btree_trans *trans, in walk_inode() argument
946 int ret = get_inodes_all_snapshots(trans, w, k.k->p.inode); in walk_inode()
953 return lookup_inode_for_snapshot(trans->c, w, k); in walk_inode()
956 static int get_visible_inodes(struct btree_trans *trans, in get_visible_inodes() argument
961 struct bch_fs *c = trans->c; in get_visible_inodes()
969 for_each_btree_key_reverse_norestart(trans, iter, BTREE_ID_inodes, SPOS(0, inum, s->pos.snapshot), in get_visible_inodes()
986 bch2_trans_iter_exit(trans, &iter); in get_visible_inodes()
996 int bch2_fsck_update_backpointers(struct btree_trans *trans, in bch2_fsck_update_backpointers() argument
1012 ret = get_visible_inodes(trans, &target, s, le64_to_cpu(d->v.d_inum)); in bch2_fsck_update_backpointers()
1018 ret = __bch2_fsck_write_inode(trans, &i->inode); in bch2_fsck_update_backpointers()
1028 static struct bkey_s_c_dirent inode_get_dirent(struct btree_trans *trans, in inode_get_dirent() argument
1035 int ret = subvol_lookup(trans, inode->bi_parent_subvol, snapshot, &inum); in inode_get_dirent()
1040 return dirent_get_by_pos(trans, iter, SPOS(inode->bi_dir, inode->bi_dir_offset, *snapshot)); in inode_get_dirent()
1043 static int check_inode_deleted_list(struct btree_trans *trans, struct bpos p) in check_inode_deleted_list() argument
1046 struct bkey_s_c k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_deleted_inodes, p, 0); in check_inode_deleted_list()
1048 bch2_trans_iter_exit(trans, &iter); in check_inode_deleted_list()
1052 static int check_inode_dirent_inode(struct btree_trans *trans, in check_inode_dirent_inode() argument
1056 struct bch_fs *c = trans->c; in check_inode_dirent_inode()
1061 struct bkey_s_c_dirent d = inode_get_dirent(trans, &dirent_iter, inode, &inode_snapshot); in check_inode_dirent_inode()
1067 trans, inode_points_to_missing_dirent, in check_inode_dirent_inode()
1071 trans, inode_points_to_wrong_dirent, in check_inode_dirent_inode()
1089 bch2_trans_iter_exit(trans, &dirent_iter); in check_inode_dirent_inode()
1095 static int get_snapshot_root_inode(struct btree_trans *trans, in get_snapshot_root_inode() argument
1103 for_each_btree_key_reverse_norestart(trans, iter, BTREE_ID_inodes, in get_snapshot_root_inode()
1117 bch2_trans_iter_exit(trans, &iter); in get_snapshot_root_inode()
1121 static int check_inode(struct btree_trans *trans, in check_inode() argument
1127 struct bch_fs *c = trans->c; in check_inode()
1133 ret = bch2_check_key_has_snapshot(trans, iter, k); in check_inode()
1151 ret = get_snapshot_root_inode(trans, snapshot_root, u.bi_inum); in check_inode()
1158 trans, inode_snapshot_mismatch, in check_inode()
1166 ret = check_inode_dirent_inode(trans, &u, &do_update); in check_inode()
1172 trans, inode_unlinked_but_has_dirent, in check_inode()
1184 ret = bch2_empty_dir_snapshot(trans, k.k->p.offset, 0, k.k->p.snapshot); in check_inode()
1188 fsck_err_on(ret, trans, inode_dir_unlinked_but_not_empty, in check_inode()
1198 ret = bch2_inode_has_child_snapshots(trans, k.k->p); in check_inode()
1203 trans, inode_has_child_snapshots_wrong, in check_inode()
1230 ret = check_inode_deleted_list(trans, k.k->p); in check_inode()
1235 trans, unlinked_inode_not_on_deleted_list, in check_inode()
1239 ret = bch2_btree_bit_mod_buffered(trans, BTREE_ID_deleted_inodes, k.k->p, 1); in check_inode()
1243 ret = bch2_inode_or_descendents_is_open(trans, k.k->p); in check_inode()
1248 trans, inode_unlinked_and_not_open, in check_inode()
1251 ret = bch2_inode_rm_snapshot(trans, u.bi_inum, iter->pos.snapshot); in check_inode()
1262 trans, inode_bi_parent_nonzero, in check_inode()
1272 ret = bch2_subvolume_get(trans, u.bi_subvol, false, &s); in check_inode()
1277 ret = reconstruct_subvol(trans, k.k->p.snapshot, u.bi_subvol, u.bi_inum); in check_inode()
1282 trans, inode_bi_subvol_missing, in check_inode()
1288 trans, inode_bi_subvol_wrong, in check_inode()
1300 trans, inode_journal_seq_in_future, in check_inode()
1311 ret = __bch2_fsck_write_inode(trans, &u); in check_inode()
1332 for_each_btree_key_commit(trans, iter, BTREE_ID_inodes, in bch2_check_inodes()
1336 check_inode(trans, &iter, k, &snapshot_root, &s))); in bch2_check_inodes()
1343 static int find_oldest_inode_needs_reattach(struct btree_trans *trans, in find_oldest_inode_needs_reattach() argument
1346 struct bch_fs *c = trans->c; in find_oldest_inode_needs_reattach()
1356 for_each_btree_key_norestart(trans, iter, in find_oldest_inode_needs_reattach()
1379 bch2_trans_iter_exit(trans, &iter); in find_oldest_inode_needs_reattach()
1384 static int check_unreachable_inode(struct btree_trans *trans, in check_unreachable_inode() argument
1402 ret = find_oldest_inode_needs_reattach(trans, &inode); in check_unreachable_inode()
1406 if (fsck_err(trans, inode_unreachable, in check_unreachable_inode()
1410 ret = reattach_inode(trans, &inode); in check_unreachable_inode()
1429 for_each_btree_key_commit(trans, iter, BTREE_ID_inodes, in bch2_check_unreachable_inodes()
1433 check_unreachable_inode(trans, &iter, k))); in bch2_check_unreachable_inodes()
1452 static int check_key_has_inode(struct btree_trans *trans, in check_key_has_inode() argument
1458 struct bch_fs *c = trans->c; in check_key_has_inode()
1468 ret = reconstruct_inode(trans, iter->btree_id, k.k->p.snapshot, k.k->p.inode) ?: in check_key_has_inode()
1469 bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc); in check_key_has_inode()
1479 trans, key_in_missing_inode, in check_key_has_inode()
1486 trans, key_in_wrong_inode_type, in check_key_has_inode()
1499 ret = bch2_btree_delete_at(trans, iter, BTREE_UPDATE_internal_snapshot_node); in check_key_has_inode()
1503 static int check_i_sectors_notnested(struct btree_trans *trans, struct inode_walker *w) in check_i_sectors_notnested() argument
1505 struct bch_fs *c = trans->c; in check_i_sectors_notnested()
1513 count2 = bch2_count_inode_sectors(trans, w->last_pos.inode, i->snapshot); in check_i_sectors_notnested()
1525 trans, inode_i_sectors_wrong, in check_i_sectors_notnested()
1530 ret = bch2_fsck_write_inode(trans, &i->inode); in check_i_sectors_notnested()
1540 static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) in check_i_sectors() argument
1542 u32 restart_count = trans->restart_count; in check_i_sectors()
1543 return check_i_sectors_notnested(trans, w) ?: in check_i_sectors()
1544 trans_was_restarted(trans, restart_count); in check_i_sectors()
1607 static int overlapping_extents_found(struct btree_trans *trans, in overlapping_extents_found() argument
1614 struct bch_fs *c = trans->c; in overlapping_extents_found()
1622 bch2_trans_iter_init(trans, &iter1, btree, pos1, in overlapping_extents_found()
1673 if (fsck_err(trans, extent_overlapping, in overlapping_extents_found()
1683 trans->extra_disk_res += bch2_bkey_sectors_compressed(k2); in overlapping_extents_found()
1685 ret = bch2_trans_update_extent_overwrite(trans, old_iter, in overlapping_extents_found()
1688 bch2_trans_commit(trans, &res, NULL, BCH_TRANS_COMMIT_no_enospc); in overlapping_extents_found()
1717 bch2_trans_iter_exit(trans, &iter2); in overlapping_extents_found()
1718 bch2_trans_iter_exit(trans, &iter1); in overlapping_extents_found()
1723 static int check_overlapping_extents(struct btree_trans *trans, in check_overlapping_extents() argument
1730 struct bch_fs *c = trans->c; in check_overlapping_extents()
1749 ret = overlapping_extents_found(trans, iter->btree_id, in check_overlapping_extents()
1764 static int check_extent_overbig(struct btree_trans *trans, struct btree_iter *iter, in check_extent_overbig() argument
1767 struct bch_fs *c = trans->c; in check_extent_overbig()
1786 static int check_extent(struct btree_trans *trans, struct btree_iter *iter, in check_extent() argument
1793 struct bch_fs *c = trans->c; in check_extent()
1797 ret = bch2_check_key_has_snapshot(trans, iter, k); in check_extent()
1804 ret = check_i_sectors(trans, inode); in check_extent()
1813 struct inode_walker_entry *extent_i = walk_inode(trans, inode, k); in check_extent()
1818 ret = check_key_has_inode(trans, iter, inode, extent_i, k); in check_extent()
1823 ret = check_overlapping_extents(trans, s, extent_ends, k, iter, in check_extent()
1842 trans, extent_past_end_of_inode, in check_extent()
1851 bch2_btree_delete_at(trans, &iter2, in check_extent()
1853 bch2_trans_iter_exit(trans, &iter2); in check_extent()
1863 ret = bch2_trans_commit(trans, res, NULL, BCH_TRANS_COMMIT_no_enospc); in check_extent()
1907 for_each_btree_key(trans, iter, BTREE_ID_extents, in bch2_check_extents()
1911 check_extent(trans, &iter, k, &w, &s, &extent_ends, &res) ?: in bch2_check_extents()
1912 check_extent_overbig(trans, &iter, k); in bch2_check_extents()
1914 check_i_sectors_notnested(trans, &w)); in bch2_check_extents()
1930 for_each_btree_key_commit(trans, iter, BTREE_ID_reflink, in bch2_check_indirect_extents()
1936 check_extent_overbig(trans, &iter, k); in bch2_check_indirect_extents()
1944 static int check_subdir_count_notnested(struct btree_trans *trans, struct inode_walker *w) in check_subdir_count_notnested() argument
1946 struct bch_fs *c = trans->c; in check_subdir_count_notnested()
1954 count2 = bch2_count_subdirs(trans, w->last_pos.inode, i->snapshot); in check_subdir_count_notnested()
1967 trans, inode_dir_wrong_nlink, in check_subdir_count_notnested()
1971 ret = bch2_fsck_write_inode(trans, &i->inode); in check_subdir_count_notnested()
1981 static int check_subdir_dirents_count(struct btree_trans *trans, struct inode_walker *w) in check_subdir_dirents_count() argument
1983 u32 restart_count = trans->restart_count; in check_subdir_dirents_count()
1984 return check_subdir_count_notnested(trans, w) ?: in check_subdir_dirents_count()
1985 trans_was_restarted(trans, restart_count); in check_subdir_dirents_count()
1989 static int check_dirent_inode_dirent(struct btree_trans *trans, in check_dirent_inode_dirent() argument
1994 struct bch_fs *c = trans->c; in check_dirent_inode_dirent()
2005 trans, inode_dir_missing_backpointer, in check_dirent_inode_dirent()
2014 trans, inode_unlinked_but_has_dirent, in check_dirent_inode_dirent()
2025 return __bch2_fsck_write_inode(trans, target); in check_dirent_inode_dirent()
2029 !fsck_err(trans, inode_wrong_backpointer, in check_dirent_inode_dirent()
2037 struct bkey_s_c_dirent bp_dirent = dirent_get_by_pos(trans, &bp_iter, in check_dirent_inode_dirent()
2047 trans, inode_wrong_backpointer, in check_dirent_inode_dirent()
2058 ret = __bch2_fsck_write_inode(trans, target); in check_dirent_inode_dirent()
2070 trans, inode_dir_multiple_links, in check_dirent_inode_dirent()
2074 ret = __remove_dirent(trans, d.k->p); in check_dirent_inode_dirent()
2084 trans, inode_multiple_links_but_nlink_0, in check_dirent_inode_dirent()
2089 ret = __bch2_fsck_write_inode(trans, target); in check_dirent_inode_dirent()
2096 bch2_trans_iter_exit(trans, &bp_iter); in check_dirent_inode_dirent()
2103 static int check_dirent_target(struct btree_trans *trans, in check_dirent_target() argument
2108 struct bch_fs *c = trans->c; in check_dirent_target()
2113 ret = check_dirent_inode_dirent(trans, iter, d, target); in check_dirent_target()
2118 trans, dirent_d_type_wrong, in check_dirent_target()
2124 n = bch2_trans_kmalloc(trans, bkey_bytes(d.k)); in check_dirent_target()
2138 ret = bch2_trans_update(trans, iter, &n->k_i, 0); in check_dirent_target()
2152 static int find_snapshot_subvol(struct btree_trans *trans, u32 snapshot, u32 *subvolid) in find_snapshot_subvol() argument
2158 for_each_btree_key_norestart(trans, iter, BTREE_ID_subvolumes, POS_MIN, 0, k, ret) { in find_snapshot_subvol()
2163 if (bch2_snapshot_is_ancestor(trans->c, le32_to_cpu(s.v->snapshot), snapshot)) { in find_snapshot_subvol()
2164 bch2_trans_iter_exit(trans, &iter); in find_snapshot_subvol()
2172 bch2_trans_iter_exit(trans, &iter); in find_snapshot_subvol()
2177 static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *iter, in check_dirent_to_subvol() argument
2180 struct bch_fs *c = trans->c; in check_dirent_to_subvol()
2191 ret = subvol_lookup(trans, parent_subvol, &parent_snapshot, &parent_inum); in check_dirent_to_subvol()
2197 int ret2 = find_snapshot_subvol(trans, d.k->p.snapshot, &new_parent_subvol); in check_dirent_to_subvol()
2209 ret = reconstruct_subvol(trans, d.k->p.snapshot, parent_subvol, 0); in check_dirent_to_subvol()
2217 trans, dirent_to_missing_parent_subvol, in check_dirent_to_subvol()
2221 trans, dirent_not_visible_in_parent_subvol, in check_dirent_to_subvol()
2230 struct bkey_i_dirent *new_dirent = bch2_bkey_make_mut_typed(trans, iter, &d.s_c, 0, dirent); in check_dirent_to_subvol()
2239 bch2_bkey_get_iter_typed(trans, &subvol_iter, in check_dirent_to_subvol()
2247 if (fsck_err(trans, dirent_to_missing_subvol, in check_dirent_to_subvol()
2250 return __remove_dirent(trans, d.k->p); in check_dirent_to_subvol()
2256 trans, subvol_fs_path_parent_wrong, in check_dirent_to_subvol()
2261 bch2_bkey_make_mut_typed(trans, &subvol_iter, &s.s_c, 0, subvolume); in check_dirent_to_subvol()
2272 ret = lookup_inode(trans, target_inum, target_snapshot, &subvol_root); in check_dirent_to_subvol()
2283 trans, inode_bi_parent_wrong, in check_dirent_to_subvol()
2289 ret = __bch2_fsck_write_inode(trans, &subvol_root); in check_dirent_to_subvol()
2294 ret = check_dirent_target(trans, iter, d, &subvol_root); in check_dirent_to_subvol()
2300 bch2_trans_iter_exit(trans, &subvol_iter); in check_dirent_to_subvol()
2305 static int check_dirent(struct btree_trans *trans, struct btree_iter *iter, in check_dirent() argument
2312 struct bch_fs *c = trans->c; in check_dirent()
2317 ret = bch2_check_key_has_snapshot(trans, iter, k); in check_dirent()
2331 ret = check_subdir_dirents_count(trans, dir); in check_dirent()
2336 i = walk_inode(trans, dir, k); in check_dirent()
2341 ret = check_key_has_inode(trans, iter, dir, i, k); in check_dirent()
2352 ret = bch2_str_hash_check_key(trans, s, &bch2_dirent_hash_desc, hash_info, iter, k); in check_dirent()
2367 ret = check_dirent_to_subvol(trans, iter, d); in check_dirent()
2371 ret = get_visible_inodes(trans, target, s, le64_to_cpu(d.v->d_inum)); in check_dirent()
2376 trans, dirent_to_missing_inode, in check_dirent()
2381 ret = __remove_dirent(trans, d.k->p); in check_dirent()
2387 ret = check_dirent_target(trans, iter, d, &i->inode); in check_dirent()
2394 trans, dirent_to_overwritten_inode, in check_dirent()
2401 bch2_trans_iter_init(trans, &delete_iter, in check_dirent()
2406 bch2_hash_delete_at(trans, bch2_dirent_hash_desc, in check_dirent()
2410 bch2_trans_iter_exit(trans, &delete_iter); in check_dirent()
2417 ret = bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc); in check_dirent()
2448 for_each_btree_key(trans, iter, BTREE_ID_dirents, in bch2_check_dirents()
2451 check_dirent(trans, &iter, k, &hash_info, &dir, &target, &s)) ?: in bch2_check_dirents()
2452 check_subdir_count_notnested(trans, &dir)); in bch2_check_dirents()
2461 static int check_xattr(struct btree_trans *trans, struct btree_iter *iter, in check_xattr() argument
2466 struct bch_fs *c = trans->c; in check_xattr()
2470 ret = bch2_check_key_has_snapshot(trans, iter, k); in check_xattr()
2476 i = walk_inode(trans, inode, k); in check_xattr()
2481 ret = check_key_has_inode(trans, iter, inode, i, k); in check_xattr()
2492 ret = bch2_str_hash_check_key(trans, NULL, &bch2_xattr_hash_desc, hash_info, iter, k); in check_xattr()
2507 for_each_btree_key_commit(trans, iter, BTREE_ID_xattrs, in bch2_check_xattrs()
2513 check_xattr(trans, &iter, k, &hash_info, &inode))); in bch2_check_xattrs()
2520 static int check_root_trans(struct btree_trans *trans) in check_root_trans() argument
2522 struct bch_fs *c = trans->c; in check_root_trans()
2528 ret = subvol_lookup(trans, BCACHEFS_ROOT_SUBVOL, &snapshot, &inum); in check_root_trans()
2532 if (mustfix_fsck_err_on(ret, trans, root_subvol_missing, in check_root_trans()
2535 bch2_trans_kmalloc(trans, sizeof(*root_subvol)); in check_root_trans()
2548 ret = bch2_btree_insert_trans(trans, BTREE_ID_subvolumes, &root_subvol->k_i, 0); in check_root_trans()
2554 ret = lookup_inode(trans, BCACHEFS_ROOT_INO, snapshot, &root_inode); in check_root_trans()
2559 trans, root_dir_missing, in check_root_trans()
2562 trans, root_inode_not_dir, in check_root_trans()
2569 ret = __bch2_fsck_write_inode(trans, &root_inode); in check_root_trans()
2581 check_root_trans(trans)); in bch2_check_root()
2596 static int check_subvol_path(struct btree_trans *trans, struct btree_iter *iter, struct bkey_s_c k) in check_subvol_path() argument
2598 struct bch_fs *c = trans->c; in check_subvol_path()
2615 ret = bch2_inode_find_by_inum_trans(trans, in check_subvol_path()
2625 ret = reattach_subvol(trans, s); in check_subvol_path()
2629 bch2_trans_iter_exit(trans, &parent_iter); in check_subvol_path()
2630 bch2_trans_iter_init(trans, &parent_iter, in check_subvol_path()
2638 trans, subvol_unreachable, in check_subvol_path()
2642 ret = reattach_subvol(trans, s); in check_subvol_path()
2650 bch2_trans_iter_exit(trans, &parent_iter); in check_subvol_path()
2657 for_each_btree_key_commit(trans, iter, in bch2_check_subvolume_structure()
2660 check_subvol_path(trans, &iter, k))); in bch2_check_subvolume_structure()
2672 static int bch2_bi_depth_renumber_one(struct btree_trans *trans, struct pathbuf_entry *p, in bch2_bi_depth_renumber_one() argument
2676 struct bkey_s_c k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_inodes, in bch2_bi_depth_renumber_one()
2688 ret = __bch2_fsck_write_inode(trans, &inode) ?: in bch2_bi_depth_renumber_one()
2689 bch2_trans_commit(trans, NULL, NULL, 0); in bch2_bi_depth_renumber_one()
2692 bch2_trans_iter_exit(trans, &iter); in bch2_bi_depth_renumber_one()
2696 static int bch2_bi_depth_renumber(struct btree_trans *trans, pathbuf *path, u32 new_bi_depth) in bch2_bi_depth_renumber() argument
2698 u32 restart_count = trans->restart_count; in bch2_bi_depth_renumber()
2702 ret = nested_lockrestart_do(trans, in bch2_bi_depth_renumber()
2703 bch2_bi_depth_renumber_one(trans, i, new_bi_depth)); in bch2_bi_depth_renumber()
2704 bch_err_fn(trans->c, ret); in bch2_bi_depth_renumber()
2711 return ret ?: trans_was_restarted(trans, restart_count); in bch2_bi_depth_renumber()
2723 static int check_path_loop(struct btree_trans *trans, struct bkey_s_c inode_k) in check_path_loop() argument
2725 struct bch_fs *c = trans->c; in check_path_loop()
2744 d = inode_get_dirent(trans, &dirent_iter, &inode, &parent_snapshot); in check_path_loop()
2750 bch2_trans_iter_exit(trans, &dirent_iter); in check_path_loop()
2760 bch2_trans_iter_exit(trans, &dirent_iter); in check_path_loop()
2771 bch2_trans_iter_exit(trans, &inode_iter); in check_path_loop()
2772 inode_k = bch2_bkey_get_iter(trans, &inode_iter, BTREE_ID_inodes, in check_path_loop()
2803 if (fsck_err(trans, dir_loop, "directory structure loop")) { in check_path_loop()
2804 ret = remove_backpointer(trans, &inode); in check_path_loop()
2809 ret = reattach_inode(trans, &inode); in check_path_loop()
2821 ret = bch2_bi_depth_renumber(trans, &path, min_bi_depth); in check_path_loop()
2824 bch2_trans_iter_exit(trans, &inode_iter); in check_path_loop()
2838 for_each_btree_key_commit(trans, iter, BTREE_ID_inodes, POS_MIN, in bch2_check_directory_structure()
2849 check_path_loop(trans, k); in bch2_check_directory_structure()
2938 for_each_btree_key(trans, iter, BTREE_ID_inodes, in check_nlinks_find_hardlinks()
2988 for_each_btree_key(trans, iter, BTREE_ID_dirents, POS_MIN, in check_nlinks_walk_dirents()
3013 static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_iter *iter, in check_nlinks_update_inode() argument
3045 trans, inode_wrong_nlink, in check_nlinks_update_inode()
3050 ret = __bch2_fsck_write_inode(trans, &u); in check_nlinks_update_inode()
3064 for_each_btree_key_commit(trans, iter, BTREE_ID_inodes, in check_nlinks_update_hardlinks()
3068 check_nlinks_update_inode(trans, &iter, k, links, &idx, range_end))); in check_nlinks_update_hardlinks()
3111 static int fix_reflink_p_key(struct btree_trans *trans, struct btree_iter *iter, in fix_reflink_p_key() argument
3125 u = bch2_trans_kmalloc(trans, sizeof(*u)); in fix_reflink_p_key()
3134 return bch2_trans_update(trans, iter, &u->k_i, BTREE_TRIGGER_norun); in fix_reflink_p_key()
3143 for_each_btree_key_commit(trans, iter, in bch2_fix_reflink_p()
3148 fix_reflink_p_key(trans, &iter, k))); in bch2_fix_reflink_p()