Skip to content

Commit 2cce375

Browse files
author
Kent Overstreet
committed
bcachefs: split out ignore_blacklisted, ignore_not_dirty
prep work for replaying the journal backwards Signed-off-by: Kent Overstreet <[email protected]>
1 parent 6942661 commit 2cce375

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

fs/bcachefs/btree_journal_iter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ int bch2_journal_keys_sort(struct bch_fs *c)
512512
genradix_for_each(&c->journal_entries, iter, _i) {
513513
i = *_i;
514514

515-
if (!i || i->ignore)
515+
if (journal_replay_ignore(i))
516516
continue;
517517

518518
cond_resched();

fs/bcachefs/journal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
12041204
genradix_for_each_reverse(&c->journal_entries, iter, _i) {
12051205
i = *_i;
12061206

1207-
if (!i || i->ignore)
1207+
if (journal_replay_ignore(i))
12081208
continue;
12091209

12101210
last_seq = le64_to_cpu(i->j.last_seq);
@@ -1237,7 +1237,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
12371237
genradix_for_each(&c->journal_entries, iter, _i) {
12381238
i = *_i;
12391239

1240-
if (!i || i->ignore)
1240+
if (journal_replay_ignore(i))
12411241
continue;
12421242

12431243
seq = le64_to_cpu(i->j.seq);

fs/bcachefs/journal_io.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ static void __journal_replay_free(struct bch_fs *c,
8686
kvfree(i);
8787
}
8888

89-
static void journal_replay_free(struct bch_fs *c, struct journal_replay *i)
89+
static void journal_replay_free(struct bch_fs *c, struct journal_replay *i, bool blacklisted)
9090
{
91-
i->ignore = true;
91+
if (blacklisted)
92+
i->ignore_blacklisted = true;
93+
else
94+
i->ignore_not_dirty = true;
9295

9396
if (!c->opts.read_entire_journal)
9497
__journal_replay_free(c, i);
@@ -138,12 +141,13 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
138141
journal_entry_radix_idx(c, jlist->last_seq)) {
139142
i = *_i;
140143

141-
if (!i || i->ignore)
144+
if (journal_replay_ignore(i))
142145
continue;
143146

144147
if (le64_to_cpu(i->j.seq) >= last_seq)
145148
break;
146-
journal_replay_free(c, i);
149+
150+
journal_replay_free(c, i, false);
147151
}
148152
}
149153

@@ -199,8 +203,9 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
199203
return -BCH_ERR_ENOMEM_journal_entry_add;
200204

201205
darray_init(&i->ptrs);
202-
i->csum_good = entry_ptr.csum_good;
203-
i->ignore = false;
206+
i->csum_good = entry_ptr.csum_good;
207+
i->ignore_blacklisted = false;
208+
i->ignore_not_dirty = false;
204209
unsafe_memcpy(&i->j, j, bytes, "embedded variable length struct");
205210

206211
if (dup) {
@@ -1255,20 +1260,20 @@ int bch2_journal_read(struct bch_fs *c,
12551260

12561261
i = *_i;
12571262

1258-
if (!i || i->ignore)
1263+
if (journal_replay_ignore(i))
12591264
continue;
12601265

12611266
if (!*start_seq)
12621267
*blacklist_seq = *start_seq = le64_to_cpu(i->j.seq) + 1;
12631268

12641269
if (JSET_NO_FLUSH(&i->j)) {
1265-
i->ignore = true;
1270+
i->ignore_blacklisted = true;
12661271
continue;
12671272
}
12681273

12691274
if (!last_write_torn && !i->csum_good) {
12701275
last_write_torn = true;
1271-
i->ignore = true;
1276+
i->ignore_blacklisted = true;
12721277
continue;
12731278
}
12741279

@@ -1307,20 +1312,20 @@ int bch2_journal_read(struct bch_fs *c,
13071312
genradix_for_each(&c->journal_entries, radix_iter, _i) {
13081313
i = *_i;
13091314

1310-
if (!i || i->ignore)
1315+
if (journal_replay_ignore(i))
13111316
continue;
13121317

13131318
seq = le64_to_cpu(i->j.seq);
13141319
if (seq < *last_seq) {
1315-
journal_replay_free(c, i);
1320+
journal_replay_free(c, i, false);
13161321
continue;
13171322
}
13181323

13191324
if (bch2_journal_seq_is_blacklisted(c, seq, true)) {
13201325
fsck_err_on(!JSET_NO_FLUSH(&i->j), c,
13211326
jset_seq_blacklisted,
13221327
"found blacklisted journal entry %llu", seq);
1323-
i->ignore = true;
1328+
i->ignore_blacklisted = true;
13241329
}
13251330
}
13261331

@@ -1329,7 +1334,7 @@ int bch2_journal_read(struct bch_fs *c,
13291334
genradix_for_each(&c->journal_entries, radix_iter, _i) {
13301335
i = *_i;
13311336

1332-
if (!i || i->ignore)
1337+
if (journal_replay_ignore(i))
13331338
continue;
13341339

13351340
BUG_ON(seq > le64_to_cpu(i->j.seq));
@@ -1382,7 +1387,7 @@ int bch2_journal_read(struct bch_fs *c,
13821387
};
13831388

13841389
i = *_i;
1385-
if (!i || i->ignore)
1390+
if (journal_replay_ignore(i))
13861391
continue;
13871392

13881393
darray_for_each(i->ptrs, ptr) {

fs/bcachefs/journal_io.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ struct journal_replay {
2020
DARRAY_PREALLOCATED(struct journal_ptr, 8) ptrs;
2121

2222
bool csum_good;
23-
bool ignore;
23+
bool ignore_blacklisted;
24+
bool ignore_not_dirty;
2425
/* must be last: */
2526
struct jset j;
2627
};
2728

29+
static inline bool journal_replay_ignore(struct journal_replay *i)
30+
{
31+
return !i || i->ignore_blacklisted || i->ignore_not_dirty;
32+
}
33+
2834
static inline struct jset_entry *__jset_entry_type_next(struct jset *jset,
2935
struct jset_entry *entry, unsigned type)
3036
{

fs/bcachefs/recovery.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static int journal_replay_early(struct bch_fs *c,
366366
genradix_for_each(&c->journal_entries, iter, _i) {
367367
i = *_i;
368368

369-
if (!i || i->ignore)
369+
if (journal_replay_ignore(i))
370370
continue;
371371

372372
vstruct_for_each(&i->j, entry) {
@@ -868,7 +868,7 @@ int bch2_fs_recovery(struct bch_fs *c)
868868
goto out;
869869

870870
genradix_for_each_reverse(&c->journal_entries, iter, i)
871-
if (*i && !(*i)->ignore) {
871+
if (!journal_replay_ignore(*i)) {
872872
last_journal_entry = &(*i)->j;
873873
break;
874874
}
@@ -893,7 +893,8 @@ int bch2_fs_recovery(struct bch_fs *c)
893893
genradix_for_each_reverse(&c->journal_entries, iter, i)
894894
if (*i) {
895895
last_journal_entry = &(*i)->j;
896-
(*i)->ignore = false;
896+
(*i)->ignore_blacklisted = false;
897+
(*i)->ignore_not_dirty= false;
897898
/*
898899
* This was probably a NO_FLUSH entry,
899900
* so last_seq was garbage - but we know

0 commit comments

Comments
 (0)