Skip to content

Commit d2fda30

Browse files
author
Kent Overstreet
committed
bcachefs: __lookup_dirent() works in snapshot, not subvol
Add a new helper, bch2_hash_lookup_in_snapshot(), for when we're not operating in a subvolume and already have a snapshot ID, and then use it in lookup_lostfound() -> __lookup_dirent(). This is a bugfix - lookup_lostfound() doesn't take a subvolume ID, we were passing a nonsense subvolume ID before, and don't have one to pass since we may be operating in an interior snapshot node that doesn't have a subvolume ID. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 096386a commit d2fda30

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

fs/bcachefs/fsck.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,19 @@ static int lookup_inode(struct btree_trans *trans, u64 inode_nr,
119119
if (!ret)
120120
*snapshot = iter.pos.snapshot;
121121
err:
122-
bch_err_msg(trans->c, ret, "fetching inode %llu:%u", inode_nr, *snapshot);
123122
bch2_trans_iter_exit(trans, &iter);
124123
return ret;
125124
}
126125

127-
static int __lookup_dirent(struct btree_trans *trans,
126+
static int lookup_dirent_in_snapshot(struct btree_trans *trans,
128127
struct bch_hash_info hash_info,
129128
subvol_inum dir, struct qstr *name,
130-
u64 *target, unsigned *type)
129+
u64 *target, unsigned *type, u32 snapshot)
131130
{
132131
struct btree_iter iter;
133132
struct bkey_s_c_dirent d;
134-
int ret;
135-
136-
ret = bch2_hash_lookup(trans, &iter, bch2_dirent_hash_desc,
137-
&hash_info, dir, name, 0);
133+
int ret = bch2_hash_lookup_in_snapshot(trans, &iter, bch2_dirent_hash_desc,
134+
&hash_info, dir, name, 0, snapshot);
138135
if (ret)
139136
return ret;
140137

@@ -225,15 +222,16 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
225222

226223
struct bch_inode_unpacked root_inode;
227224
struct bch_hash_info root_hash_info;
228-
ret = lookup_inode(trans, root_inum.inum, &root_inode, &snapshot);
225+
u32 root_inode_snapshot = snapshot;
226+
ret = lookup_inode(trans, root_inum.inum, &root_inode, &root_inode_snapshot);
229227
bch_err_msg(c, ret, "looking up root inode");
230228
if (ret)
231229
return ret;
232230

233231
root_hash_info = bch2_hash_info_init(c, &root_inode);
234232

235-
ret = __lookup_dirent(trans, root_hash_info, root_inum,
236-
&lostfound_str, &inum, &d_type);
233+
ret = lookup_dirent_in_snapshot(trans, root_hash_info, root_inum,
234+
&lostfound_str, &inum, &d_type, snapshot);
237235
if (bch2_err_matches(ret, ENOENT))
238236
goto create_lostfound;
239237

@@ -250,7 +248,10 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
250248
* The bch2_check_dirents pass has already run, dangling dirents
251249
* shouldn't exist here:
252250
*/
253-
return lookup_inode(trans, inum, lostfound, &snapshot);
251+
ret = lookup_inode(trans, inum, lostfound, &snapshot);
252+
bch_err_msg(c, ret, "looking up lost+found %llu:%u in (root inode %llu, snapshot root %u)",
253+
inum, snapshot, root_inum.inum, bch2_snapshot_root(c, snapshot));
254+
return ret;
254255

255256
create_lostfound:
256257
/*

fs/bcachefs/str_hash.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,16 @@ static inline bool is_visible_key(struct bch_hash_desc desc, subvol_inum inum, s
160160
}
161161

162162
static __always_inline int
163-
bch2_hash_lookup(struct btree_trans *trans,
163+
bch2_hash_lookup_in_snapshot(struct btree_trans *trans,
164164
struct btree_iter *iter,
165165
const struct bch_hash_desc desc,
166166
const struct bch_hash_info *info,
167167
subvol_inum inum, const void *key,
168-
unsigned flags)
168+
unsigned flags, u32 snapshot)
169169
{
170170
struct bkey_s_c k;
171-
u32 snapshot;
172171
int ret;
173172

174-
ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
175-
if (ret)
176-
return ret;
177-
178173
for_each_btree_key_upto_norestart(trans, *iter, desc.btree_id,
179174
SPOS(inum.inum, desc.hash_key(info, key), snapshot),
180175
POS(inum.inum, U64_MAX),
@@ -194,6 +189,19 @@ bch2_hash_lookup(struct btree_trans *trans,
194189
return ret ?: -BCH_ERR_ENOENT_str_hash_lookup;
195190
}
196191

192+
static __always_inline int
193+
bch2_hash_lookup(struct btree_trans *trans,
194+
struct btree_iter *iter,
195+
const struct bch_hash_desc desc,
196+
const struct bch_hash_info *info,
197+
subvol_inum inum, const void *key,
198+
unsigned flags)
199+
{
200+
u32 snapshot;
201+
return bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot) ?:
202+
bch2_hash_lookup_in_snapshot(trans, iter, desc, info, inum, key, flags, snapshot);
203+
}
204+
197205
static __always_inline int
198206
bch2_hash_hole(struct btree_trans *trans,
199207
struct btree_iter *iter,

0 commit comments

Comments
 (0)