diff options
Diffstat (limited to 'libbcachefs/fsck.c')
-rw-r--r-- | libbcachefs/fsck.c | 76 |
1 files changed, 3 insertions, 73 deletions
diff --git a/libbcachefs/fsck.c b/libbcachefs/fsck.c index c07ddfa0..8c186acc 100644 --- a/libbcachefs/fsck.c +++ b/libbcachefs/fsck.c @@ -219,69 +219,6 @@ static int write_inode(struct btree_trans *trans, return ret; } -static int fsck_inode_rm(struct btree_trans *trans, u64 inum, u32 snapshot) -{ - struct bch_fs *c = trans->c; - struct btree_iter iter = { NULL }; - struct bkey_i_inode_generation delete; - struct bch_inode_unpacked inode_u; - struct bkey_s_c k; - int ret; - - do { - ret = bch2_btree_delete_range_trans(trans, BTREE_ID_extents, - SPOS(inum, 0, snapshot), - SPOS(inum, U64_MAX, snapshot), - 0, NULL) ?: - bch2_btree_delete_range_trans(trans, BTREE_ID_dirents, - SPOS(inum, 0, snapshot), - SPOS(inum, U64_MAX, snapshot), - 0, NULL) ?: - bch2_btree_delete_range_trans(trans, BTREE_ID_xattrs, - SPOS(inum, 0, snapshot), - SPOS(inum, U64_MAX, snapshot), - 0, NULL); - } while (ret == -BCH_ERR_transaction_restart_nested); - if (ret) - goto err; -retry: - bch2_trans_begin(trans); - - k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_inodes, - SPOS(0, inum, snapshot), BTREE_ITER_INTENT); - ret = bkey_err(k); - if (ret) - goto err; - - if (!bkey_is_inode(k.k)) { - bch2_fs_inconsistent(c, - "inode %llu:%u not found when deleting", - inum, snapshot); - ret = -EIO; - goto err; - } - - bch2_inode_unpack(k, &inode_u); - - /* Subvolume root? */ - if (inode_u.bi_subvol) - bch_warn(c, "deleting inode %llu marked as unlinked, but also a subvolume root!?", inode_u.bi_inum); - - bkey_inode_generation_init(&delete.k_i); - delete.k.p = iter.pos; - delete.v.bi_generation = cpu_to_le32(inode_u.bi_generation + 1); - - ret = bch2_trans_update(trans, &iter, &delete.k_i, 0) ?: - bch2_trans_commit(trans, NULL, NULL, - BTREE_INSERT_NOFAIL); -err: - bch2_trans_iter_exit(trans, &iter); - if (bch2_err_matches(ret, BCH_ERR_transaction_restart)) - goto retry; - - return ret ?: -BCH_ERR_transaction_restart_nested; -} - static int __remove_dirent(struct btree_trans *trans, struct bpos pos) { struct bch_fs *c = trans->c; @@ -521,7 +458,6 @@ static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *see u32 id, u32 ancestor) { ssize_t i; - u32 top = seen->ids.nr ? seen->ids.data[seen->ids.nr - 1].equiv : 0; EBUG_ON(id > ancestor); EBUG_ON(!bch2_snapshot_is_equiv(c, id)); @@ -529,7 +465,7 @@ static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *see /* @ancestor should be the snapshot most recently added to @seen */ EBUG_ON(ancestor != seen->pos.snapshot); - EBUG_ON(ancestor != top); + EBUG_ON(ancestor != seen->ids.data[seen->ids.nr - 1].equiv); if (id == ancestor) return true; @@ -930,7 +866,7 @@ static int check_inode(struct btree_trans *trans, bch2_trans_unlock(trans); bch2_fs_lazy_rw(c); - ret = fsck_inode_rm(trans, u.bi_inum, iter->pos.snapshot); + ret = bch2_inode_rm_snapshot(trans, u.bi_inum, iter->pos.snapshot); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) bch_err(c, "error in fsck: error while deleting inode: %s", bch2_err_str(ret)); @@ -1198,19 +1134,13 @@ static int overlapping_extents_found(struct btree_trans *trans, BUG_ON(bkey_le(pos1, bkey_start_pos(&pos2))); - prt_str(&buf, "\n "); - bch2_bpos_to_text(&buf, pos1); - prt_str(&buf, "\n "); - - bch2_bkey_to_text(&buf, &pos2); - prt_str(&buf, "\n "); - bch2_trans_iter_init(trans, &iter, btree, SPOS(pos1.inode, pos1.offset - 1, snapshot), 0); k = bch2_btree_iter_peek_upto(&iter, POS(pos1.inode, U64_MAX)); ret = bkey_err(k); if (ret) goto err; + prt_str(&buf, "\n "); bch2_bkey_val_to_text(&buf, c, k); if (!bpos_eq(pos1, k.k->p)) { |