Commit bdbf953b authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_shoot_down_journal_keys()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 27fcec6c
...@@ -567,3 +567,22 @@ int bch2_journal_keys_sort(struct bch_fs *c) ...@@ -567,3 +567,22 @@ int bch2_journal_keys_sort(struct bch_fs *c)
bch_verbose(c, "Journal keys: %zu read, %zu after sorting and compacting", nr_read, keys->nr); bch_verbose(c, "Journal keys: %zu read, %zu after sorting and compacting", nr_read, keys->nr);
return 0; return 0;
} }
void bch2_shoot_down_journal_keys(struct bch_fs *c, enum btree_id btree,
unsigned level_min, unsigned level_max,
struct bpos start, struct bpos end)
{
struct journal_keys *keys = &c->journal_keys;
size_t dst = 0;
move_gap(keys, keys->nr);
darray_for_each(*keys, i)
if (!(i->btree_id == btree &&
i->level >= level_min &&
i->level <= level_max &&
bpos_ge(i->k->k.p, start) &&
bpos_le(i->k->k.p, end)))
keys->data[dst++] = *i;
keys->nr = keys->gap = dst;
}
...@@ -66,4 +66,8 @@ void bch2_journal_entries_free(struct bch_fs *); ...@@ -66,4 +66,8 @@ void bch2_journal_entries_free(struct bch_fs *);
int bch2_journal_keys_sort(struct bch_fs *); int bch2_journal_keys_sort(struct bch_fs *);
void bch2_shoot_down_journal_keys(struct bch_fs *, enum btree_id,
unsigned, unsigned,
struct bpos, struct bpos);
#endif /* _BCACHEFS_BTREE_JOURNAL_ITER_H */ #endif /* _BCACHEFS_BTREE_JOURNAL_ITER_H */
...@@ -47,7 +47,7 @@ static bool btree_id_is_alloc(enum btree_id id) ...@@ -47,7 +47,7 @@ static bool btree_id_is_alloc(enum btree_id id)
} }
/* for -o reconstruct_alloc: */ /* for -o reconstruct_alloc: */
static void do_reconstruct_alloc(struct bch_fs *c) static void bch2_reconstruct_alloc(struct bch_fs *c)
{ {
bch2_journal_log_msg(c, "dropping alloc info"); bch2_journal_log_msg(c, "dropping alloc info");
bch_info(c, "dropping and reconstructing all alloc info"); bch_info(c, "dropping and reconstructing all alloc info");
...@@ -82,15 +82,17 @@ static void do_reconstruct_alloc(struct bch_fs *c) ...@@ -82,15 +82,17 @@ static void do_reconstruct_alloc(struct bch_fs *c)
c->recovery_passes_explicit |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0])); c->recovery_passes_explicit |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0]));
struct journal_keys *keys = &c->journal_keys;
size_t src, dst;
move_gap(keys, keys->nr);
for (src = 0, dst = 0; src < keys->nr; src++) bch2_shoot_down_journal_keys(c, BTREE_ID_alloc,
if (!btree_id_is_alloc(keys->data[src].btree_id)) 0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
keys->data[dst++] = keys->data[src]; bch2_shoot_down_journal_keys(c, BTREE_ID_backpointers,
keys->nr = keys->gap = dst; 0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
bch2_shoot_down_journal_keys(c, BTREE_ID_need_discard,
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
bch2_shoot_down_journal_keys(c, BTREE_ID_freespace,
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
bch2_shoot_down_journal_keys(c, BTREE_ID_bucket_gens,
0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
} }
/* /*
...@@ -731,7 +733,7 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -731,7 +733,7 @@ int bch2_fs_recovery(struct bch_fs *c)
c->journal_replay_seq_end = blacklist_seq - 1; c->journal_replay_seq_end = blacklist_seq - 1;
if (c->opts.reconstruct_alloc) if (c->opts.reconstruct_alloc)
do_reconstruct_alloc(c); bch2_reconstruct_alloc(c);
zero_out_btree_mem_ptr(&c->journal_keys); zero_out_btree_mem_ptr(&c->journal_keys);
......
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