Loading fs/bcachefs/fsck.c +13 −40 Original line number Diff line number Diff line Loading @@ -142,34 +142,6 @@ static int lookup_dirent_in_snapshot(struct btree_trans *trans, return 0; } static int __write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { struct bkey_inode_buf *inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p)); if (IS_ERR(inode_p)) return PTR_ERR(inode_p); bch2_inode_pack(inode_p, inode); inode_p->inode.k.p.snapshot = snapshot; return bch2_btree_insert_nonextent(trans, BTREE_ID_inodes, &inode_p->inode.k_i, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); } static int fsck_write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { int ret = commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc, __write_inode(trans, inode, snapshot)); bch_err_fn(trans->c, ret); return ret; } static int __remove_dirent(struct btree_trans *trans, struct bpos pos) { struct bch_fs *c = trans->c; Loading Loading @@ -312,7 +284,7 @@ static int reattach_inode(struct btree_trans *trans, if (S_ISDIR(inode->bi_mode)) { lostfound.bi_nlink++; ret = __write_inode(trans, &lostfound, U32_MAX); ret = __bch2_fsck_write_inode(trans, &lostfound, U32_MAX); if (ret) return ret; } Loading @@ -334,7 +306,7 @@ static int reattach_inode(struct btree_trans *trans, inode->bi_dir = lostfound.bi_inum; inode->bi_dir_offset = dir_offset; return __write_inode(trans, inode, inode_snapshot); return __bch2_fsck_write_inode(trans, inode, inode_snapshot); } static int remove_backpointer(struct btree_trans *trans, Loading Loading @@ -858,7 +830,8 @@ static int check_inode(struct btree_trans *trans, u.bi_flags &= ~BCH_INODE_i_size_dirty|BCH_INODE_unlinked; ret = __write_inode(trans, &u, iter->pos.snapshot); ret = __bch2_fsck_write_inode(trans, &u, iter->pos.snapshot); bch_err_msg(c, ret, "in fsck updating inode"); if (ret) return ret; Loading Loading @@ -948,7 +921,7 @@ static int check_inode(struct btree_trans *trans, } if (do_update) { ret = __write_inode(trans, &u, iter->pos.snapshot); ret = __bch2_fsck_write_inode(trans, &u, iter->pos.snapshot); bch_err_msg(c, ret, "in fsck updating inode"); if (ret) return ret; Loading Loading @@ -1029,7 +1002,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) w->last_pos.inode, i->snapshot, i->inode.bi_sectors, i->count)) { i->inode.bi_sectors = i->count; ret = fsck_write_inode(trans, &i->inode, i->snapshot); ret = bch2_fsck_write_inode(trans, &i->inode, i->snapshot); if (ret) break; } Loading Loading @@ -1478,7 +1451,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) "directory %llu:%u with wrong i_nlink: got %u, should be %llu", w->last_pos.inode, i->snapshot, i->inode.bi_nlink, i->count)) { i->inode.bi_nlink = i->count; ret = fsck_write_inode(trans, &i->inode, i->snapshot); ret = bch2_fsck_write_inode(trans, &i->inode, i->snapshot); if (ret) break; } Loading @@ -1505,7 +1478,7 @@ static int check_dirent_target(struct btree_trans *trans, target->bi_dir = d.k->p.inode; target->bi_dir_offset = d.k->p.offset; ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot); if (ret) goto err; } Loading Loading @@ -1545,7 +1518,7 @@ static int check_dirent_target(struct btree_trans *trans, target->bi_nlink++; target->bi_flags &= ~BCH_INODE_unlinked; ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot); if (ret) goto err; } Loading @@ -1563,7 +1536,7 @@ static int check_dirent_target(struct btree_trans *trans, target->bi_dir = d.k->p.inode; target->bi_dir_offset = d.k->p.offset; ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot); if (ret) goto err; } Loading Loading @@ -1741,7 +1714,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter, target_inum, subvol_root.bi_subvol, target_subvol)) { subvol_root.bi_subvol = target_subvol; ret = __write_inode(trans, &subvol_root, target_snapshot); ret = __bch2_fsck_write_inode(trans, &subvol_root, target_snapshot); if (ret) goto err; } Loading Loading @@ -1915,7 +1888,7 @@ static int check_root_trans(struct btree_trans *trans) 0, NULL); root_inode.bi_inum = inum; ret = __write_inode(trans, &root_inode, snapshot); ret = __bch2_fsck_write_inode(trans, &root_inode, snapshot); bch_err_msg(c, ret, "writing root inode"); } err: Loading Loading @@ -2287,7 +2260,7 @@ static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_ite u.bi_inum, bch2_d_types[mode_to_type(u.bi_mode)], bch2_inode_nlink_get(&u), link->count)) { bch2_inode_nlink_set(&u, link->count); ret = __write_inode(trans, &u, k.k->p.snapshot); ret = __bch2_fsck_write_inode(trans, &u, k.k->p.snapshot); } fsck_err: return ret; Loading fs/bcachefs/inode.c +28 −0 Original line number Diff line number Diff line Loading @@ -384,6 +384,34 @@ int bch2_inode_write_flags(struct btree_trans *trans, return bch2_trans_update(trans, iter, &inode_p->inode.k_i, flags); } int __bch2_fsck_write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { struct bkey_inode_buf *inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p)); if (IS_ERR(inode_p)) return PTR_ERR(inode_p); bch2_inode_pack(inode_p, inode); inode_p->inode.k.p.snapshot = snapshot; return bch2_btree_insert_nonextent(trans, BTREE_ID_inodes, &inode_p->inode.k_i, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); } int bch2_fsck_write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { int ret = commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc, __bch2_fsck_write_inode(trans, inode, snapshot)); bch_err_fn(trans->c, ret); return ret; } struct bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k) { struct bch_inode_unpacked u; Loading fs/bcachefs/inode.h +3 −0 Original line number Diff line number Diff line Loading @@ -108,6 +108,9 @@ static inline int bch2_inode_write(struct btree_trans *trans, return bch2_inode_write_flags(trans, iter, inode, 0); } int __bch2_fsck_write_inode(struct btree_trans *, struct bch_inode_unpacked *, u32); int bch2_fsck_write_inode(struct btree_trans *, struct bch_inode_unpacked *, u32); void bch2_inode_init_early(struct bch_fs *, struct bch_inode_unpacked *); void bch2_inode_init_late(struct bch_inode_unpacked *, u64, Loading Loading
fs/bcachefs/fsck.c +13 −40 Original line number Diff line number Diff line Loading @@ -142,34 +142,6 @@ static int lookup_dirent_in_snapshot(struct btree_trans *trans, return 0; } static int __write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { struct bkey_inode_buf *inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p)); if (IS_ERR(inode_p)) return PTR_ERR(inode_p); bch2_inode_pack(inode_p, inode); inode_p->inode.k.p.snapshot = snapshot; return bch2_btree_insert_nonextent(trans, BTREE_ID_inodes, &inode_p->inode.k_i, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); } static int fsck_write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { int ret = commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc, __write_inode(trans, inode, snapshot)); bch_err_fn(trans->c, ret); return ret; } static int __remove_dirent(struct btree_trans *trans, struct bpos pos) { struct bch_fs *c = trans->c; Loading Loading @@ -312,7 +284,7 @@ static int reattach_inode(struct btree_trans *trans, if (S_ISDIR(inode->bi_mode)) { lostfound.bi_nlink++; ret = __write_inode(trans, &lostfound, U32_MAX); ret = __bch2_fsck_write_inode(trans, &lostfound, U32_MAX); if (ret) return ret; } Loading @@ -334,7 +306,7 @@ static int reattach_inode(struct btree_trans *trans, inode->bi_dir = lostfound.bi_inum; inode->bi_dir_offset = dir_offset; return __write_inode(trans, inode, inode_snapshot); return __bch2_fsck_write_inode(trans, inode, inode_snapshot); } static int remove_backpointer(struct btree_trans *trans, Loading Loading @@ -858,7 +830,8 @@ static int check_inode(struct btree_trans *trans, u.bi_flags &= ~BCH_INODE_i_size_dirty|BCH_INODE_unlinked; ret = __write_inode(trans, &u, iter->pos.snapshot); ret = __bch2_fsck_write_inode(trans, &u, iter->pos.snapshot); bch_err_msg(c, ret, "in fsck updating inode"); if (ret) return ret; Loading Loading @@ -948,7 +921,7 @@ static int check_inode(struct btree_trans *trans, } if (do_update) { ret = __write_inode(trans, &u, iter->pos.snapshot); ret = __bch2_fsck_write_inode(trans, &u, iter->pos.snapshot); bch_err_msg(c, ret, "in fsck updating inode"); if (ret) return ret; Loading Loading @@ -1029,7 +1002,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) w->last_pos.inode, i->snapshot, i->inode.bi_sectors, i->count)) { i->inode.bi_sectors = i->count; ret = fsck_write_inode(trans, &i->inode, i->snapshot); ret = bch2_fsck_write_inode(trans, &i->inode, i->snapshot); if (ret) break; } Loading Loading @@ -1478,7 +1451,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) "directory %llu:%u with wrong i_nlink: got %u, should be %llu", w->last_pos.inode, i->snapshot, i->inode.bi_nlink, i->count)) { i->inode.bi_nlink = i->count; ret = fsck_write_inode(trans, &i->inode, i->snapshot); ret = bch2_fsck_write_inode(trans, &i->inode, i->snapshot); if (ret) break; } Loading @@ -1505,7 +1478,7 @@ static int check_dirent_target(struct btree_trans *trans, target->bi_dir = d.k->p.inode; target->bi_dir_offset = d.k->p.offset; ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot); if (ret) goto err; } Loading Loading @@ -1545,7 +1518,7 @@ static int check_dirent_target(struct btree_trans *trans, target->bi_nlink++; target->bi_flags &= ~BCH_INODE_unlinked; ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot); if (ret) goto err; } Loading @@ -1563,7 +1536,7 @@ static int check_dirent_target(struct btree_trans *trans, target->bi_dir = d.k->p.inode; target->bi_dir_offset = d.k->p.offset; ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot); if (ret) goto err; } Loading Loading @@ -1741,7 +1714,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter, target_inum, subvol_root.bi_subvol, target_subvol)) { subvol_root.bi_subvol = target_subvol; ret = __write_inode(trans, &subvol_root, target_snapshot); ret = __bch2_fsck_write_inode(trans, &subvol_root, target_snapshot); if (ret) goto err; } Loading Loading @@ -1915,7 +1888,7 @@ static int check_root_trans(struct btree_trans *trans) 0, NULL); root_inode.bi_inum = inum; ret = __write_inode(trans, &root_inode, snapshot); ret = __bch2_fsck_write_inode(trans, &root_inode, snapshot); bch_err_msg(c, ret, "writing root inode"); } err: Loading Loading @@ -2287,7 +2260,7 @@ static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_ite u.bi_inum, bch2_d_types[mode_to_type(u.bi_mode)], bch2_inode_nlink_get(&u), link->count)) { bch2_inode_nlink_set(&u, link->count); ret = __write_inode(trans, &u, k.k->p.snapshot); ret = __bch2_fsck_write_inode(trans, &u, k.k->p.snapshot); } fsck_err: return ret; Loading
fs/bcachefs/inode.c +28 −0 Original line number Diff line number Diff line Loading @@ -384,6 +384,34 @@ int bch2_inode_write_flags(struct btree_trans *trans, return bch2_trans_update(trans, iter, &inode_p->inode.k_i, flags); } int __bch2_fsck_write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { struct bkey_inode_buf *inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p)); if (IS_ERR(inode_p)) return PTR_ERR(inode_p); bch2_inode_pack(inode_p, inode); inode_p->inode.k.p.snapshot = snapshot; return bch2_btree_insert_nonextent(trans, BTREE_ID_inodes, &inode_p->inode.k_i, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE); } int bch2_fsck_write_inode(struct btree_trans *trans, struct bch_inode_unpacked *inode, u32 snapshot) { int ret = commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc, __bch2_fsck_write_inode(trans, inode, snapshot)); bch_err_fn(trans->c, ret); return ret; } struct bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k) { struct bch_inode_unpacked u; Loading
fs/bcachefs/inode.h +3 −0 Original line number Diff line number Diff line Loading @@ -108,6 +108,9 @@ static inline int bch2_inode_write(struct btree_trans *trans, return bch2_inode_write_flags(trans, iter, inode, 0); } int __bch2_fsck_write_inode(struct btree_trans *, struct bch_inode_unpacked *, u32); int bch2_fsck_write_inode(struct btree_trans *, struct bch_inode_unpacked *, u32); void bch2_inode_init_early(struct bch_fs *, struct bch_inode_unpacked *); void bch2_inode_init_late(struct bch_inode_unpacked *, u64, Loading