summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-03-13 16:56:48 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2019-03-17 14:30:13 -0400
commitc3abf273efddf02bbb95f5eafcf50c2066985fd0 (patch)
tree207690463c3e1093f945bedaf1bd44bb3d66a66e
parent907ba8930c9bf81cbd2ab734000efe09c301d487 (diff)
bcachefs: fix bch2_invalidate_one_bucket2() during journal replay
-rw-r--r--fs/bcachefs/alloc_background.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index 64bc8a416b70..62f639b8a72b 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -938,7 +938,7 @@ retry:
else
memset(&u, 0, sizeof(u));
- invalidating_cached_data = u.cached_sectors != 0;
+ invalidating_cached_data = m.cached_sectors != 0;
//BUG_ON(u.dirty_sectors);
u.data_type = 0;
@@ -946,7 +946,13 @@ retry:
u.cached_sectors = 0;
u.read_time = c->bucket_clock[READ].hand;
u.write_time = c->bucket_clock[WRITE].hand;
- u.gen++;
+
+ /*
+ * The allocator has to start before journal replay is finished - thus,
+ * we have to trust the in memory bucket @m, not the version in the
+ * btree:
+ */
+ u.gen = m.gen + 1;
a = bkey_alloc_init(&alloc_key.k);
a->k.p = iter->pos;
@@ -962,6 +968,7 @@ retry:
ret = bch2_btree_insert_at(c, NULL,
invalidating_cached_data ? journal_seq : NULL,
BTREE_INSERT_ATOMIC|
+ BTREE_INSERT_NOUNLOCK|
BTREE_INSERT_NOCHECK_RW|
BTREE_INSERT_NOFAIL|
BTREE_INSERT_USE_RESERVE|
@@ -981,6 +988,10 @@ retry:
if (!top->nr)
heap_pop(&ca->alloc_heap, e, bucket_alloc_cmp, NULL);
+ /* with btree still locked: */
+ if (ca->buckets_written)
+ set_bit(b, ca->buckets_written);
+
/*
* Make sure we flush the last journal entry that updated this
* bucket (i.e. deleting the last reference) before writing to