Update bcachefs sources to 2d95696fbe bcachefs: fix rw -> ro -> rw transition

This commit is contained in:
Kent Overstreet 2017-05-08 09:33:47 -08:00
parent 63065c0128
commit a588eb0d9e
3 changed files with 37 additions and 48 deletions

View File

@ -1 +1 @@
9ceb982d7790f552e2f5c96bebeab176516cf144 43e3159567958ea70c8a95d98fdb6e881153a656

View File

@ -853,7 +853,6 @@ static void discard_invalidated_bucket(struct bch_dev *ca, long bucket)
bucket_to_sector(ca, bucket), bucket_to_sector(ca, bucket),
ca->mi.bucket_size, GFP_NOIO, 0); ca->mi.bucket_size, GFP_NOIO, 0);
while (1) { while (1) {
bool pushed = false; bool pushed = false;
unsigned i; unsigned i;
@ -877,10 +876,9 @@ static void discard_invalidated_bucket(struct bch_dev *ca, long bucket)
if (pushed) if (pushed)
break; break;
if (kthread_should_stop()) { if (kthread_should_stop())
__set_current_state(TASK_RUNNING);
break; break;
}
schedule(); schedule();
try_to_freeze(); try_to_freeze();
} }
@ -900,16 +898,45 @@ static int bch2_allocator_thread(void *arg)
{ {
struct bch_dev *ca = arg; struct bch_dev *ca = arg;
struct bch_fs *c = ca->fs; struct bch_fs *c = ca->fs;
u64 journal_seq;
size_t bucket; size_t bucket;
int ret; int ret;
set_freezable(); set_freezable();
while (!kthread_should_stop()) { while (1) {
u64 journal_seq = 0; while (1) {
while (ca->nr_invalidated) {
BUG_ON(fifo_empty(&ca->free_inc));
bucket = fifo_peek(&ca->free_inc);
discard_invalidated_bucket(ca, bucket);
if (kthread_should_stop())
goto out;
--ca->nr_invalidated;
}
if (fifo_empty(&ca->free_inc))
break;
journal_seq = 0;
ret = bch2_invalidate_free_inc(c, ca, &journal_seq);
if (ret < 0)
goto out;
ca->nr_invalidated = ret;
if (ca->nr_invalidated == fifo_used(&ca->free_inc))
ca->alloc_thread_started = true;
if (ca->allocator_invalidating_data)
bch2_journal_flush_seq(&c->journal, journal_seq);
else if (ca->allocator_journal_seq_flush)
bch2_journal_flush_seq(&c->journal,
ca->allocator_journal_seq_flush);
}
/* Reset front/back so we can easily sort fifo entries later: */ /* Reset front/back so we can easily sort fifo entries later: */
BUG_ON(fifo_used(&ca->free_inc));
ca->free_inc.front = ca->free_inc.back = 0; ca->free_inc.front = ca->free_inc.back = 0;
ca->allocator_journal_seq_flush = 0; ca->allocator_journal_seq_flush = 0;
ca->allocator_invalidating_data = false; ca->allocator_invalidating_data = false;
@ -964,29 +991,6 @@ static int bch2_allocator_thread(void *arg)
* free_inc is now full of newly-invalidated buckets: next, * free_inc is now full of newly-invalidated buckets: next,
* write out the new bucket gens: * write out the new bucket gens:
*/ */
while (!fifo_empty(&ca->free_inc) && !kthread_should_stop()) {
ret = bch2_invalidate_free_inc(c, ca, &journal_seq);
if (bch2_fs_fatal_err_on(ret < 0, c,
"error invalidating buckets: %i", ret))
goto err;
if (ca->allocator_invalidating_data)
bch2_journal_flush_seq(&c->journal, journal_seq);
else if (ca->allocator_journal_seq_flush)
bch2_journal_flush_seq(&c->journal,
ca->allocator_journal_seq_flush);
while (ret && !kthread_should_stop()) {
BUG_ON(fifo_empty(&ca->free_inc));
bucket = fifo_peek(&ca->free_inc);
discard_invalidated_bucket(ca, bucket);
--ret;
}
}
ca->alloc_thread_started = true;
} }
out: out:
/* /*
@ -995,21 +999,6 @@ out:
*/ */
synchronize_rcu(); synchronize_rcu();
return 0; return 0;
err:
/*
* Emergency read only - allocator thread has to shutdown.
*
* N.B. we better be going into RO mode, else allocations would hang
* indefinitely - whatever generated the error will have sent us into RO
* mode.
*
* Clear out the free_inc freelist so things are consistent-ish:
*/
spin_lock(&ca->freelist_lock);
while (fifo_pop(&ca->free_inc, bucket))
bch2_mark_free_bucket(ca, ca->buckets + bucket);
spin_unlock(&ca->freelist_lock);
goto out;
} }
/* Allocation */ /* Allocation */

View File

@ -373,8 +373,6 @@ struct bch_dev {
struct task_struct *alloc_thread; struct task_struct *alloc_thread;
bool need_alloc_write;
/* /*
* free: Buckets that are ready to be used * free: Buckets that are ready to be used
* *
@ -387,7 +385,9 @@ struct bch_dev {
DECLARE_FIFO(long, free)[RESERVE_NR]; DECLARE_FIFO(long, free)[RESERVE_NR];
DECLARE_FIFO(long, free_inc); DECLARE_FIFO(long, free_inc);
spinlock_t freelist_lock; spinlock_t freelist_lock;
unsigned nr_invalidated;
bool alloc_thread_started; bool alloc_thread_started;
bool need_alloc_write;
size_t fifo_last_bucket; size_t fifo_last_bucket;