diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-03-02 18:35:30 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:58 -0400 |
commit | ab2a29ccffd0e9fe62afb8bbd45e1709f9726942 (patch) | |
tree | 506bd3b3614eaf0dd3ee9f94af28c4a81117cf00 /fs/bcachefs/inode.c | |
parent | e751c01a8ee1ca934cc0953e2e77ad4ea3e64d5e (diff) | |
download | lwn-ab2a29ccffd0e9fe62afb8bbd45e1709f9726942.tar.gz lwn-ab2a29ccffd0e9fe62afb8bbd45e1709f9726942.zip |
bcachefs: Inode backpointers
This patch adds two new inode fields, bi_dir and bi_dir_offset, that
point back to the inode's dirent.
Since we're only adding fields for a single backpointer, files that have
been hardlinked won't necessarily have valid backpointers: we also add a
new inode flag, BCH_INODE_BACKPTR_UNTRUSTED, that's set if an inode has
ever had multiple links to it. That's ok, because we only really need
this functionality for directories, which can never have multiple
hardlinks - when we add subvolumes, we'll need a way to enemurate and
print subvolumes, and this will let us reconstruct a path to a subvolume
root given a subvolume root inode.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/inode.c')
-rw-r--r-- | fs/bcachefs/inode.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c index 7044ab73831c..b72b3578bbe2 100644 --- a/fs/bcachefs/inode.c +++ b/fs/bcachefs/inode.c @@ -470,11 +470,10 @@ static inline u32 bkey_generation(struct bkey_s_c k) } } -int bch2_inode_create(struct btree_trans *trans, - struct bch_inode_unpacked *inode_u) +struct btree_iter *bch2_inode_create(struct btree_trans *trans, + struct bch_inode_unpacked *inode_u) { struct bch_fs *c = trans->c; - struct bkey_inode_buf *inode_p; struct btree_iter *iter = NULL; struct bkey_s_c k; u64 min, max, start, *hint; @@ -494,10 +493,6 @@ int bch2_inode_create(struct btree_trans *trans, if (start >= max || start < min) start = min; - - inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p)); - if (IS_ERR(inode_p)) - return PTR_ERR(inode_p); again: for_each_btree_key(trans, iter, BTREE_ID_inodes, POS(0, start), BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) { @@ -521,7 +516,7 @@ again: bch2_trans_iter_put(trans, iter); if (ret) - return ret; + return ERR_PTR(ret); if (start != min) { /* Retry from start */ @@ -529,15 +524,12 @@ again: goto again; } - return -ENOSPC; + return ERR_PTR(-ENOSPC); found_slot: *hint = k.k->p.offset; inode_u->bi_inum = k.k->p.offset; inode_u->bi_generation = bkey_generation(k); - - ret = bch2_inode_write(trans, iter, inode_u); - bch2_trans_iter_put(trans, iter); - return ret; + return iter; } int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached) |