bcachefs: bch2_shoot_down_journal_keys()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 19 Mar 2024 22:56:26 +0000 (18:56 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 3 Apr 2024 18:44:18 +0000 (14:44 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_journal_iter.c
fs/bcachefs/btree_journal_iter.h
fs/bcachefs/recovery.c

index 1f588264575db2d854df283c6bd1ef1e9bc14056..5cbcbfe85235b8de3777ae82b120d4627f99c8d7 100644 (file)
@@ -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);
        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;
+}
index 09cd53091a05b48036e96e8cd2ac4c58b35f69b2..af25046ebcaa763bd7e7b8c37e34818ea06c5cc2 100644 (file)
@@ -66,4 +66,8 @@ void bch2_journal_entries_free(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 */
index 88b794d5dbd0656e5c99f36b961dd5c5a4697d61..7cbf30e3ef73bc0da8abef2cb4ae8598011b3efb 100644 (file)
@@ -47,7 +47,7 @@ static bool btree_id_is_alloc(enum btree_id id)
 }
 
 /* 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");
        bch_info(c, "dropping and reconstructing all alloc info");
@@ -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]));
 
-       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++)
-               if (!btree_id_is_alloc(keys->data[src].btree_id))
-                       keys->data[dst++] = keys->data[src];
-       keys->nr = keys->gap = dst;
+       bch2_shoot_down_journal_keys(c, BTREE_ID_alloc,
+                                    0, BTREE_MAX_DEPTH, POS_MIN, SPOS_MAX);
+       bch2_shoot_down_journal_keys(c, BTREE_ID_backpointers,
+                                    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 @@ use_clean:
        c->journal_replay_seq_end       = blacklist_seq - 1;
 
        if (c->opts.reconstruct_alloc)
-               do_reconstruct_alloc(c);
+               bch2_reconstruct_alloc(c);
 
        zero_out_btree_mem_ptr(&c->journal_keys);