Skip to content

Commit a592268

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_str_hash_check_key() may now be called without snapshots_seen
We don't track snapshot overwrites outside of fsck, so for this to be called at runtime outside of fsck we need to create it on demand, when we have repair to do. Signed-off-by: Kent Overstreet <[email protected]>
1 parent cb6f5d0 commit a592268

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

fs/bcachefs/fsck.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,6 @@ static int reconstruct_inode(struct btree_trans *trans, enum btree_id btree, u32
643643
return __bch2_fsck_write_inode(trans, &new_inode);
644644
}
645645

646-
struct snapshots_seen {
647-
struct bpos pos;
648-
snapshot_id_list ids;
649-
};
650-
651646
static inline void snapshots_seen_exit(struct snapshots_seen *s)
652647
{
653648
darray_exit(&s->ids);

fs/bcachefs/fsck.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
#include "str_hash.h"
66

7+
/* recoverds snapshot IDs of overwrites at @pos */
8+
struct snapshots_seen {
9+
struct bpos pos;
10+
snapshot_id_list ids;
11+
};
12+
713
int bch2_fsck_update_backpointers(struct btree_trans *,
814
struct snapshots_seen *,
915
const struct bch_hash_desc,

fs/bcachefs/str_hash.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ int __bch2_str_hash_check_key(struct btree_trans *trans,
231231
struct btree_iter iter = {};
232232
struct printbuf buf = PRINTBUF;
233233
struct bkey_s_c k;
234+
bool free_snapshots_seen = false;
234235
int ret = 0;
235236

236237
u64 hash = desc->hash_bkey(hash_info, hash_k);
@@ -256,6 +257,8 @@ int __bch2_str_hash_check_key(struct btree_trans *trans,
256257
out:
257258
bch2_trans_iter_exit(trans, &iter);
258259
printbuf_exit(&buf);
260+
if (free_snapshots_seen)
261+
darray_exit(&s->ids);
259262
return ret;
260263
bad_hash:
261264
/*
@@ -265,6 +268,22 @@ int __bch2_str_hash_check_key(struct btree_trans *trans,
265268
if (ret)
266269
goto out;
267270

271+
if (!s) {
272+
s = bch2_trans_kmalloc(trans, sizeof(*s));
273+
ret = PTR_ERR_OR_ZERO(s);
274+
if (ret)
275+
goto out;
276+
277+
s->pos = k_iter->pos;
278+
darray_init(&s->ids);
279+
280+
ret = bch2_get_snapshot_overwrites(trans, desc->btree_id, k_iter->pos, &s->ids);
281+
if (ret)
282+
goto out;
283+
284+
free_snapshots_seen = true;
285+
}
286+
268287
if (fsck_err(trans, hash_table_key_wrong_offset,
269288
"hash table key at wrong offset: btree %s inode %llu offset %llu, hashed to %llu\n%s",
270289
bch2_btree_id_str(desc->btree_id), hash_k.k->p.inode, hash_k.k->p.offset, hash,
@@ -286,7 +305,9 @@ int __bch2_str_hash_check_key(struct btree_trans *trans,
286305
if (k.k)
287306
goto duplicate_entries;
288307

289-
ret = bch2_hash_delete_at(trans, *desc, hash_info, k_iter,
308+
ret = bch2_insert_snapshot_whiteouts(trans, desc->btree_id,
309+
k_iter->pos, new->k.p) ?:
310+
bch2_hash_delete_at(trans, *desc, hash_info, k_iter,
290311
BTREE_ITER_with_updates|
291312
BTREE_UPDATE_internal_snapshot_node) ?:
292313
bch2_fsck_update_backpointers(trans, s, *desc, hash_info, new) ?:

0 commit comments

Comments
 (0)