summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/bcachefs/bcachefs.h1
-rw-r--r--fs/bcachefs/btree_key_cache.c4
-rw-r--r--fs/bcachefs/recovery.c11
-rw-r--r--fs/bcachefs/super.c1
4 files changed, 12 insertions, 5 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h
index dc7b78b7e2a2..64a9094ec748 100644
--- a/fs/bcachefs/bcachefs.h
+++ b/fs/bcachefs/bcachefs.h
@@ -489,6 +489,7 @@ enum {
BCH_FS_FSCK_DONE,
BCH_FS_STARTED,
BCH_FS_RW,
+ BCH_FS_WAS_RW,
/* shutdown: */
BCH_FS_STOPPING,
diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c
index 019d4d164553..f8b9ca4dfb2b 100644
--- a/fs/bcachefs/btree_key_cache.c
+++ b/fs/bcachefs/btree_key_cache.c
@@ -683,7 +683,9 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
kmem_cache_free(bch2_key_cache, ck);
}
- BUG_ON(atomic_long_read(&bc->nr_dirty) && !bch2_journal_error(&c->journal));
+ BUG_ON(atomic_long_read(&bc->nr_dirty) &&
+ !bch2_journal_error(&c->journal) &&
+ test_bit(BCH_FS_WAS_RW, &c->flags));
BUG_ON(atomic_long_read(&bc->nr_keys));
mutex_unlock(&bc->lock);
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index 2dc3dee4efc8..fe6886e42216 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -973,7 +973,7 @@ int bch2_fs_recovery(struct bch_fs *c)
struct jset *last_journal_entry = NULL;
u64 blacklist_seq, journal_seq;
bool write_sb = false;
- int ret;
+ int ret = 0;
if (c->sb.clean)
clean = read_superblock_clean(c);
@@ -1253,10 +1253,9 @@ use_clean:
if (c->journal_seq_blacklist_table &&
c->journal_seq_blacklist_table->nr > 128)
queue_work(system_long_wq, &c->journal_seq_blacklist_gc_work);
-out:
+
ret = 0;
-err:
-fsck_err:
+out:
set_bit(BCH_FS_FSCK_DONE, &c->flags);
bch2_flush_fsck_errs(c);
@@ -1270,6 +1269,10 @@ fsck_err:
else
bch_verbose(c, "ret %i", ret);
return ret;
+err:
+fsck_err:
+ bch2_fs_emergency_read_only(c);
+ goto out;
}
int bch2_fs_initialize(struct bch_fs *c)
diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c
index 18ad2db9f4bf..64bc5ed33203 100644
--- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -441,6 +441,7 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
percpu_ref_reinit(&c->writes);
set_bit(BCH_FS_RW, &c->flags);
+ set_bit(BCH_FS_WAS_RW, &c->flags);
return 0;
err:
__bch2_fs_read_only(c);