Commit 69c8e6ce authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: move fsck_write_inode() to inode.c

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 29223b5a
...@@ -142,34 +142,6 @@ static int lookup_dirent_in_snapshot(struct btree_trans *trans, ...@@ -142,34 +142,6 @@ static int lookup_dirent_in_snapshot(struct btree_trans *trans,
return 0; 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) static int __remove_dirent(struct btree_trans *trans, struct bpos pos)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
...@@ -312,7 +284,7 @@ static int reattach_inode(struct btree_trans *trans, ...@@ -312,7 +284,7 @@ static int reattach_inode(struct btree_trans *trans,
if (S_ISDIR(inode->bi_mode)) { if (S_ISDIR(inode->bi_mode)) {
lostfound.bi_nlink++; lostfound.bi_nlink++;
ret = __write_inode(trans, &lostfound, U32_MAX); ret = __bch2_fsck_write_inode(trans, &lostfound, U32_MAX);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -334,7 +306,7 @@ static int reattach_inode(struct btree_trans *trans, ...@@ -334,7 +306,7 @@ static int reattach_inode(struct btree_trans *trans,
inode->bi_dir = lostfound.bi_inum; inode->bi_dir = lostfound.bi_inum;
inode->bi_dir_offset = dir_offset; 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, static int remove_backpointer(struct btree_trans *trans,
...@@ -858,7 +830,8 @@ static int check_inode(struct btree_trans *trans, ...@@ -858,7 +830,8 @@ static int check_inode(struct btree_trans *trans,
u.bi_flags &= ~BCH_INODE_i_size_dirty|BCH_INODE_unlinked; 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"); bch_err_msg(c, ret, "in fsck updating inode");
if (ret) if (ret)
return ret; return ret;
...@@ -948,7 +921,7 @@ static int check_inode(struct btree_trans *trans, ...@@ -948,7 +921,7 @@ static int check_inode(struct btree_trans *trans,
} }
if (do_update) { 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"); bch_err_msg(c, ret, "in fsck updating inode");
if (ret) if (ret)
return ret; return ret;
...@@ -1029,7 +1002,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) ...@@ -1029,7 +1002,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w)
w->last_pos.inode, i->snapshot, w->last_pos.inode, i->snapshot,
i->inode.bi_sectors, i->count)) { i->inode.bi_sectors, i->count)) {
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) if (ret)
break; break;
} }
...@@ -1478,7 +1451,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) ...@@ -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", "directory %llu:%u with wrong i_nlink: got %u, should be %llu",
w->last_pos.inode, i->snapshot, i->inode.bi_nlink, i->count)) { w->last_pos.inode, i->snapshot, i->inode.bi_nlink, i->count)) {
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) if (ret)
break; break;
} }
...@@ -1505,7 +1478,7 @@ static int check_dirent_target(struct btree_trans *trans, ...@@ -1505,7 +1478,7 @@ static int check_dirent_target(struct btree_trans *trans,
target->bi_dir = d.k->p.inode; target->bi_dir = d.k->p.inode;
target->bi_dir_offset = d.k->p.offset; 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) if (ret)
goto err; goto err;
} }
...@@ -1545,7 +1518,7 @@ static int check_dirent_target(struct btree_trans *trans, ...@@ -1545,7 +1518,7 @@ static int check_dirent_target(struct btree_trans *trans,
target->bi_nlink++; target->bi_nlink++;
target->bi_flags &= ~BCH_INODE_unlinked; target->bi_flags &= ~BCH_INODE_unlinked;
ret = __write_inode(trans, target, target_snapshot); ret = __bch2_fsck_write_inode(trans, target, target_snapshot);
if (ret) if (ret)
goto err; goto err;
} }
...@@ -1563,7 +1536,7 @@ static int check_dirent_target(struct btree_trans *trans, ...@@ -1563,7 +1536,7 @@ static int check_dirent_target(struct btree_trans *trans,
target->bi_dir = d.k->p.inode; target->bi_dir = d.k->p.inode;
target->bi_dir_offset = d.k->p.offset; 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) if (ret)
goto err; goto err;
} }
...@@ -1741,7 +1714,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1741,7 +1714,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
target_inum, target_inum,
subvol_root.bi_subvol, target_subvol)) { subvol_root.bi_subvol, target_subvol)) {
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) if (ret)
goto err; goto err;
} }
...@@ -1915,7 +1888,7 @@ static int check_root_trans(struct btree_trans *trans) ...@@ -1915,7 +1888,7 @@ static int check_root_trans(struct btree_trans *trans)
0, NULL); 0, NULL);
root_inode.bi_inum = inum; 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"); bch_err_msg(c, ret, "writing root inode");
} }
err: err:
...@@ -2287,7 +2260,7 @@ static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_ite ...@@ -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)], u.bi_inum, bch2_d_types[mode_to_type(u.bi_mode)],
bch2_inode_nlink_get(&u), link->count)) { bch2_inode_nlink_get(&u), link->count)) {
bch2_inode_nlink_set(&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: fsck_err:
return ret; return ret;
......
...@@ -384,6 +384,34 @@ int bch2_inode_write_flags(struct btree_trans *trans, ...@@ -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); 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 bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k)
{ {
struct bch_inode_unpacked u; struct bch_inode_unpacked u;
......
...@@ -108,6 +108,9 @@ static inline int bch2_inode_write(struct btree_trans *trans, ...@@ -108,6 +108,9 @@ static inline int bch2_inode_write(struct btree_trans *trans,
return bch2_inode_write_flags(trans, iter, inode, 0); 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 *, void bch2_inode_init_early(struct bch_fs *,
struct bch_inode_unpacked *); struct bch_inode_unpacked *);
void bch2_inode_init_late(struct bch_inode_unpacked *, u64, void bch2_inode_init_late(struct bch_inode_unpacked *, u64,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment