Commit 2cce3752 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: split out ignore_blacklisted, ignore_not_dirty

prep work for replaying the journal backwards
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 69426613
...@@ -512,7 +512,7 @@ int bch2_journal_keys_sort(struct bch_fs *c) ...@@ -512,7 +512,7 @@ int bch2_journal_keys_sort(struct bch_fs *c)
genradix_for_each(&c->journal_entries, iter, _i) { genradix_for_each(&c->journal_entries, iter, _i) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
cond_resched(); cond_resched();
......
...@@ -1204,7 +1204,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) ...@@ -1204,7 +1204,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
genradix_for_each_reverse(&c->journal_entries, iter, _i) { genradix_for_each_reverse(&c->journal_entries, iter, _i) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
last_seq = le64_to_cpu(i->j.last_seq); last_seq = le64_to_cpu(i->j.last_seq);
...@@ -1237,7 +1237,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq) ...@@ -1237,7 +1237,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
genradix_for_each(&c->journal_entries, iter, _i) { genradix_for_each(&c->journal_entries, iter, _i) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
seq = le64_to_cpu(i->j.seq); seq = le64_to_cpu(i->j.seq);
......
...@@ -86,9 +86,12 @@ static void __journal_replay_free(struct bch_fs *c, ...@@ -86,9 +86,12 @@ static void __journal_replay_free(struct bch_fs *c,
kvfree(i); kvfree(i);
} }
static void journal_replay_free(struct bch_fs *c, struct journal_replay *i) static void journal_replay_free(struct bch_fs *c, struct journal_replay *i, bool blacklisted)
{ {
i->ignore = true; if (blacklisted)
i->ignore_blacklisted = true;
else
i->ignore_not_dirty = true;
if (!c->opts.read_entire_journal) if (!c->opts.read_entire_journal)
__journal_replay_free(c, i); __journal_replay_free(c, i);
...@@ -138,12 +141,13 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca, ...@@ -138,12 +141,13 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
journal_entry_radix_idx(c, jlist->last_seq)) { journal_entry_radix_idx(c, jlist->last_seq)) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
if (le64_to_cpu(i->j.seq) >= last_seq) if (le64_to_cpu(i->j.seq) >= last_seq)
break; break;
journal_replay_free(c, i);
journal_replay_free(c, i, false);
} }
} }
...@@ -199,8 +203,9 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca, ...@@ -199,8 +203,9 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
return -BCH_ERR_ENOMEM_journal_entry_add; return -BCH_ERR_ENOMEM_journal_entry_add;
darray_init(&i->ptrs); darray_init(&i->ptrs);
i->csum_good = entry_ptr.csum_good; i->csum_good = entry_ptr.csum_good;
i->ignore = false; i->ignore_blacklisted = false;
i->ignore_not_dirty = false;
unsafe_memcpy(&i->j, j, bytes, "embedded variable length struct"); unsafe_memcpy(&i->j, j, bytes, "embedded variable length struct");
if (dup) { if (dup) {
...@@ -1255,20 +1260,20 @@ int bch2_journal_read(struct bch_fs *c, ...@@ -1255,20 +1260,20 @@ int bch2_journal_read(struct bch_fs *c,
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
if (!*start_seq) if (!*start_seq)
*blacklist_seq = *start_seq = le64_to_cpu(i->j.seq) + 1; *blacklist_seq = *start_seq = le64_to_cpu(i->j.seq) + 1;
if (JSET_NO_FLUSH(&i->j)) { if (JSET_NO_FLUSH(&i->j)) {
i->ignore = true; i->ignore_blacklisted = true;
continue; continue;
} }
if (!last_write_torn && !i->csum_good) { if (!last_write_torn && !i->csum_good) {
last_write_torn = true; last_write_torn = true;
i->ignore = true; i->ignore_blacklisted = true;
continue; continue;
} }
...@@ -1307,12 +1312,12 @@ int bch2_journal_read(struct bch_fs *c, ...@@ -1307,12 +1312,12 @@ int bch2_journal_read(struct bch_fs *c,
genradix_for_each(&c->journal_entries, radix_iter, _i) { genradix_for_each(&c->journal_entries, radix_iter, _i) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
seq = le64_to_cpu(i->j.seq); seq = le64_to_cpu(i->j.seq);
if (seq < *last_seq) { if (seq < *last_seq) {
journal_replay_free(c, i); journal_replay_free(c, i, false);
continue; continue;
} }
...@@ -1320,7 +1325,7 @@ int bch2_journal_read(struct bch_fs *c, ...@@ -1320,7 +1325,7 @@ int bch2_journal_read(struct bch_fs *c,
fsck_err_on(!JSET_NO_FLUSH(&i->j), c, fsck_err_on(!JSET_NO_FLUSH(&i->j), c,
jset_seq_blacklisted, jset_seq_blacklisted,
"found blacklisted journal entry %llu", seq); "found blacklisted journal entry %llu", seq);
i->ignore = true; i->ignore_blacklisted = true;
} }
} }
...@@ -1329,7 +1334,7 @@ int bch2_journal_read(struct bch_fs *c, ...@@ -1329,7 +1334,7 @@ int bch2_journal_read(struct bch_fs *c,
genradix_for_each(&c->journal_entries, radix_iter, _i) { genradix_for_each(&c->journal_entries, radix_iter, _i) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
BUG_ON(seq > le64_to_cpu(i->j.seq)); BUG_ON(seq > le64_to_cpu(i->j.seq));
...@@ -1382,7 +1387,7 @@ int bch2_journal_read(struct bch_fs *c, ...@@ -1382,7 +1387,7 @@ int bch2_journal_read(struct bch_fs *c,
}; };
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
darray_for_each(i->ptrs, ptr) { darray_for_each(i->ptrs, ptr) {
......
...@@ -20,11 +20,17 @@ struct journal_replay { ...@@ -20,11 +20,17 @@ struct journal_replay {
DARRAY_PREALLOCATED(struct journal_ptr, 8) ptrs; DARRAY_PREALLOCATED(struct journal_ptr, 8) ptrs;
bool csum_good; bool csum_good;
bool ignore; bool ignore_blacklisted;
bool ignore_not_dirty;
/* must be last: */ /* must be last: */
struct jset j; struct jset j;
}; };
static inline bool journal_replay_ignore(struct journal_replay *i)
{
return !i || i->ignore_blacklisted || i->ignore_not_dirty;
}
static inline struct jset_entry *__jset_entry_type_next(struct jset *jset, static inline struct jset_entry *__jset_entry_type_next(struct jset *jset,
struct jset_entry *entry, unsigned type) struct jset_entry *entry, unsigned type)
{ {
......
...@@ -366,7 +366,7 @@ static int journal_replay_early(struct bch_fs *c, ...@@ -366,7 +366,7 @@ static int journal_replay_early(struct bch_fs *c,
genradix_for_each(&c->journal_entries, iter, _i) { genradix_for_each(&c->journal_entries, iter, _i) {
i = *_i; i = *_i;
if (!i || i->ignore) if (journal_replay_ignore(i))
continue; continue;
vstruct_for_each(&i->j, entry) { vstruct_for_each(&i->j, entry) {
...@@ -868,7 +868,7 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -868,7 +868,7 @@ int bch2_fs_recovery(struct bch_fs *c)
goto out; goto out;
genradix_for_each_reverse(&c->journal_entries, iter, i) genradix_for_each_reverse(&c->journal_entries, iter, i)
if (*i && !(*i)->ignore) { if (!journal_replay_ignore(*i)) {
last_journal_entry = &(*i)->j; last_journal_entry = &(*i)->j;
break; break;
} }
...@@ -893,7 +893,8 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -893,7 +893,8 @@ int bch2_fs_recovery(struct bch_fs *c)
genradix_for_each_reverse(&c->journal_entries, iter, i) genradix_for_each_reverse(&c->journal_entries, iter, i)
if (*i) { if (*i) {
last_journal_entry = &(*i)->j; last_journal_entry = &(*i)->j;
(*i)->ignore = false; (*i)->ignore_blacklisted = false;
(*i)->ignore_not_dirty= false;
/* /*
* This was probably a NO_FLUSH entry, * This was probably a NO_FLUSH entry,
* so last_seq was garbage - but we know * so last_seq was garbage - but we know
......
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