diff options
Diffstat (limited to 'libbcachefs/inode.c')
-rw-r--r-- | libbcachefs/inode.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/libbcachefs/inode.c b/libbcachefs/inode.c index e6cbc8fa..09b2444c 100644 --- a/libbcachefs/inode.c +++ b/libbcachefs/inode.c @@ -6,8 +6,7 @@ #include "error.h" #include "extents.h" #include "inode.h" -#include "io.h" -#include "keylist.h" +#include "str_hash.h" #include <linux/random.h> @@ -181,6 +180,53 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode, return 0; } +struct btree_iter *bch2_inode_peek(struct btree_trans *trans, + struct bch_inode_unpacked *inode, + u64 inum, unsigned flags) +{ + struct btree_iter *iter; + struct bkey_s_c k; + int ret; + + iter = bch2_trans_get_iter(trans, BTREE_ID_INODES, POS(inum, 0), + BTREE_ITER_SLOTS|flags); + if (IS_ERR(iter)) + return iter; + + k = bch2_btree_iter_peek_slot(iter); + ret = bkey_err(k); + if (ret) + goto err; + + ret = k.k->type == KEY_TYPE_inode ? 0 : -EIO; + if (ret) + goto err; + + ret = bch2_inode_unpack(bkey_s_c_to_inode(k), inode); + if (ret) + goto err; + + return iter; +err: + bch2_trans_iter_put(trans, iter); + return ERR_PTR(ret); +} + +int bch2_inode_write(struct btree_trans *trans, + struct btree_iter *iter, + struct bch_inode_unpacked *inode) +{ + struct bkey_inode_buf *inode_p; + + 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); + bch2_trans_update(trans, iter, &inode_p->inode.k_i); + return 0; +} + const char *bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k) { struct bkey_s_c_inode inode = bkey_s_c_to_inode(k); @@ -256,11 +302,13 @@ void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u, struct bch_inode_unpacked *parent) { s64 now = bch2_current_time(c); + enum bch_str_hash_type str_hash = + bch2_str_hash_opt_to_type(c, c->opts.str_hash); memset(inode_u, 0, sizeof(*inode_u)); /* ick */ - inode_u->bi_flags |= c->opts.str_hash << INODE_STR_HASH_OFFSET; + inode_u->bi_flags |= str_hash << INODE_STR_HASH_OFFSET; get_random_bytes(&inode_u->bi_hash_seed, sizeof(inode_u->bi_hash_seed)); |